Skip to content

Commit

Permalink
luaPackages: update
Browse files Browse the repository at this point in the history
- luarocks-nix: bumped to pass args too, `package_X = callPackage ...`.
  It allows to remove the annoying `with self`.
  This new version disables tests (because broken) and now emits derivation
  with a callPackage in front.
- replaced X.override with lib.overrideLuarocks, it should be used
whenever buildInputs/extraVariables is changed since it impacts the
generated luarocks config.
Once structured attributes are in, it will be easier to have the
luarocks config generated by a hook and we probably will be able to
replace all overrideLuarocks by overrideAttrs.
  • Loading branch information
teto committed Oct 17, 2021
1 parent 9aeeb75 commit 6823c43
Show file tree
Hide file tree
Showing 7 changed files with 626 additions and 369 deletions.
9 changes: 4 additions & 5 deletions maintainers/scripts/update-luarocks-packages
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ TMP_FILE="$(mktemp)"
GENERATED_NIXFILE="pkgs/development/lua-modules/generated-packages.nix"
LUAROCKS_CONFIG="$NIXPKGS_PATH/maintainers/scripts/luarocks-config.lua"

HEADER = """
/* {GENERATED_NIXFILE} is an auto-generated file -- DO NOT EDIT!
HEADER = """/* {GENERATED_NIXFILE} is an auto-generated file -- DO NOT EDIT!
Regenerate it with:
nixpkgs$ ./maintainers/scripts/update-luarocks-packages
Expand Down Expand Up @@ -99,9 +98,8 @@ class LuaEditor(Editor):
header2 = textwrap.dedent(
# header2 = inspect.cleandoc(
"""
{ self, stdenv, lib, fetchurl, fetchgit, ... } @ args:
self: super:
with self;
{ self, stdenv, lib, fetchurl, fetchgit, callPackage, ... } @ args:
final: prev:
{
""")
f.write(header2)
Expand Down Expand Up @@ -199,6 +197,7 @@ def generate_pkg_nix(plug: LuaPlugin):

log.debug("running %s", ' '.join(cmd))
output = subprocess.check_output(cmd, text=True)
output = "callPackage(" + output.strip() + ") {};\n\n"
return (plug, output)

def main():
Expand Down
21 changes: 11 additions & 10 deletions pkgs/development/interpreters/lua-5/build-lua-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pname
# propagate build dependencies so in case we have A -> B -> C,
# C can import package A propagated by B
, propagatedBuildInputs ? []
, propagatedNativeBuildInputs ? []

# used to disable derivation, useful for specific lua versions
# TODO move from this setting meta.broken to a 'disabled' attribute on the
Expand All @@ -50,7 +49,7 @@ pname
# The latter is used to work-around luarocks having a problem with
# multiple-output derivations as external deps:
# https://github.com/luarocks/luarocks/issues/766<Paste>
, externalDeps ? lib.unique (lib.filter (drv: !drv ? luaModule) (propagatedBuildInputs ++ buildInputs))
, externalDeps ? []

# Appended to the generated luarocks config
, extraConfig ? ""
Expand All @@ -74,7 +73,6 @@ pname
let
generatedRockspecFilename = "${rockspecDir}/${pname}-${version}.rockspec";


# TODO fix warnings "Couldn't load rockspec for ..." during manifest
# construction -- from initial investigation, appears it will require
# upstream luarocks changes to fix cleanly (during manifest construction,
Expand All @@ -83,7 +81,7 @@ let
luarocks_config = "luarocks-config.lua";
luarocks_content = let
generatedConfig = lua.pkgs.lib.generateLuarocksConfig {
inherit externalDeps;
externalDeps = externalDeps ++ externalDepsGenerated;
inherit extraVariables;
inherit rocksSubdir;
inherit requiredLuaRocks;
Expand All @@ -99,12 +97,13 @@ let
# Filter out the lua derivation itself from the Lua module dependency
# closure, as it doesn't have a rock tree :)
requiredLuaRocks = lib.filter (d: d ? luaModule)
(lua.pkgs.requiredLuaModules propagatedBuildInputs);
(lua.pkgs.requiredLuaModules luarocksDrv.propagatedBuildInputs);

# example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
externalDepsGenerated = lib.unique (lib.filter (drv: !drv ? luaModule) (luarocksDrv.propagatedBuildInputs ++ luarocksDrv.buildInputs));
externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
in
toLuaModule ( lua.stdenv.mkDerivation (

luarocksDrv = toLuaModule ( lua.stdenv.mkDerivation (
builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariables"] // {

name = namePrefix + pname + "-" + version;
Expand Down Expand Up @@ -146,13 +145,12 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab
runHook postConfigure
'';

# TODO could be moved to configurePhase
buildPhase = ''
runHook preBuild
nix_debug "Using LUAROCKS_CONFIG=$LUAROCKS_CONFIG"
LUAROCKS=luarocks
LUAROCKS=${lua.pkgs.luarocks}/bin/luarocks
if (( ''${NIX_DEBUG:-0} >= 1 )); then
LUAROCKS="$LUAROCKS --verbose"
fi
Expand Down Expand Up @@ -195,6 +193,7 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab
passthru = {
inherit lua; # The lua interpreter
inherit externalDeps;
inherit luarocks_content;
} // passthru;

meta = {
Expand All @@ -203,4 +202,6 @@ builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps" "extraVariab
maintainers = (meta.maintainers or []) ++ [ ];
broken = disabled;
} // meta;
}))
}));
in
luarocksDrv
2 changes: 1 addition & 1 deletion pkgs/development/lua-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
overridenPackages = import ./overrides.nix { inherit pkgs; };

generatedPackages = if (builtins.pathExists ./generated-packages.nix) then
pkgs.callPackage ./generated-packages.nix { } else (final: prev: {});
(final: prev: pkgs.callPackage ./generated-packages.nix { inherit (final) callPackage; } final prev) else (final: prev: {});

extensible-self = lib.makeExtensible
(extends overrides
Expand Down
Loading

0 comments on commit 6823c43

Please sign in to comment.