diff options
author | Matthieu Coudron <mcoudron@hotmail.com> | 2023-03-30 15:43:19 +0200 |
---|---|---|
committer | Matthieu Coudron <mcoudron@hotmail.com> | 2023-04-22 22:09:35 +0200 |
commit | 30a70671f49dbb61abb66a5755398919f81d2d25 (patch) | |
tree | d1c23b7d06a8a37e3d672df92e0a508235b8b9b2 /pkgs/development/interpreters/lua-5 | |
parent | fc952043685f3de8ca1f5c19348de404c31e38df (diff) |
buildLuaPackage: enable __structuredAttrs rocks
it makes overriding easier, instead of having to know internals to decide which of `sqlite = prev.luaLib.overrideLuarocks prev.sqlite (drv: {` or `sqlite = prev.sqlite.overrideAttrs (drv: {` just use the latter
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r-- | pkgs/development/interpreters/lua-5/build-lua-package.nix | 118 |
1 files changed, 56 insertions, 62 deletions
diff --git a/pkgs/development/interpreters/lua-5/build-lua-package.nix b/pkgs/development/interpreters/lua-5/build-lua-package.nix index d29468df3b4dc..adba03873aa63 100644 --- a/pkgs/development/interpreters/lua-5/build-lua-package.nix +++ b/pkgs/development/interpreters/lua-5/build-lua-package.nix @@ -2,7 +2,7 @@ { lib , lua , wrapLua -, luarocks + # Whether the derivation provides a lua module or not. , luarocksCheckHook , luaLib @@ -38,13 +38,7 @@ # Skip wrapping of lua programs altogether , dontWrapLuaPrograms ? false - -, meta ? {} - -, passthru ? {} , doCheck ? false -, doInstallCheck ? false - # Non-Lua / system (e.g. C library) dependencies. Is a list of deps, where # each dep is either a derivation, or an attribute set like # { name = "rockspec external_dependencies key"; dep = derivation; } @@ -73,7 +67,6 @@ # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. let - generatedRockspecFilename = "${rockspecDir}/${pname}-${rockspecVersion}.rockspec"; # TODO fix warnings "Couldn't load rockspec for ..." during manifest # construction -- from initial investigation, appears it will require @@ -82,43 +75,33 @@ let # configured trees) luarocks_config = "luarocks-config.lua"; - # 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 (luarocksDrv.nativeBuildInputs ++ luarocksDrv.propagatedBuildInputs)); - - # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ] - externalDepsGenerated = lib.unique (lib.filter (drv: !drv ? luaModule) ( - luarocksDrv.nativeBuildInputs ++ luarocksDrv.propagatedBuildInputs ++ luarocksDrv.buildInputs) - ); - externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps; - - luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation (finalAttrs: let - - rocksSubdir = "${finalAttrs.pname}-${finalAttrs.version}-rocks"; - luarocks_content = let - generatedConfig = luaLib.generateLuarocksConfig { - externalDeps = externalDeps ++ externalDepsGenerated; - inherit extraVariables rocksSubdir requiredLuaRocks; - }; - in - '' - ${generatedConfig} - ${extraConfig} - ''; - in builtins.removeAttrs attrs ["disabled" "externalDeps" "extraVariables"] // { - - name = namePrefix + pname + "-" + finalAttrs.version; + luarocksDrv = luaLib.toLuaModule ( lua.stdenv.mkDerivation (self: attrs // { + + name = namePrefix + pname + "-" + self.version; inherit rockspecVersion; + __structuredAttrs = true; + env = { + LUAROCKS_CONFIG="$PWD/${luarocks_config}"; + }; + + generatedRockspecFilename = "${rockspecDir}/${pname}-${rockspecVersion}.rockspec"; + + nativeBuildInputs = [ wrapLua - luarocks - ] ++ lib.optionals doCheck ([ luarocksCheckHook ] ++ finalAttrs.nativeCheckInputs); + lua.pkgs.luarocks + ]; - buildInputs = buildInputs - ++ (map (d: d.dep) externalDeps'); + inherit doCheck extraVariables rockspecFilename knownRockspec externalDeps nativeCheckInputs; + buildInputs = let + # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ] + externalDeps' = lib.filter (dep: !lib.isDerivation dep) self.externalDeps; + in [ lua.pkgs.luarocks ] + ++ lib.optionals self.doCheck ([ luarocksCheckHook ] ++ self.nativeCheckInputs) + ++ (map (d: d.dep) externalDeps') + ; # propagate lua to active setup-hook in nix-shell propagatedBuildInputs = propagatedBuildInputs ++ [ lua ]; @@ -126,25 +109,42 @@ let # @-patterns do not capture formal argument default values, so we need to # explicitly inherit this for it to be available as a shell variable in the # builder - inherit rocksSubdir; + rocksSubdir = "${self.pname}-${self.version}-rocks"; + luarocks_content = let + externalDepsGenerated = lib.filter (drv: !drv ? luaModule) + (self.nativeBuildInputs ++ self.propagatedBuildInputs ++ self.buildInputs); + generatedConfig = luaLib.generateLuarocksConfig { + externalDeps = lib.unique (self.externalDeps ++ externalDepsGenerated); + # Filter out the lua derivation itself from the Lua module dependency + # closure, as it doesn't have a rock tree :) + # luaLib.hasLuaModule + requiredLuaRocks = lib.filter luaLib.hasLuaModule + (lua.pkgs.requiredLuaModules (self.nativeBuildInputs ++ self.propagatedBuildInputs)); + inherit (self) extraVariables rocksSubdir; + }; + in + '' + ${generatedConfig} + ${extraConfig} + ''; configurePhase = '' runHook preConfigure cat > ${luarocks_config} <<EOF - ${luarocks_content} + ${self.luarocks_content} EOF export LUAROCKS_CONFIG="$PWD/${luarocks_config}"; + cat "$LUAROCKS_CONFIG" '' - + lib.optionalString (rockspecFilename == null) '' - rockspecFilename="${generatedRockspecFilename}" + + lib.optionalString (self.rockspecFilename == null) '' + rockspecFilename="${self.generatedRockspecFilename}" '' - + lib.optionalString (knownRockspec != null) '' - + + lib.optionalString (self.knownRockspec != null) '' # prevents the following type of error: # Inconsistency between rockspec filename (42fm1b3d7iv6fcbhgm9674as3jh6y2sh-luv-1.22.0-1.rockspec) and its contents (luv-1.22.0-1.rockspec) - rockspecFilename="$TMP/$(stripHash ''${knownRockspec})" - cp ''${knownRockspec} "$rockspecFilename" + rockspecFilename="$TMP/$(stripHash ${self.knownRockspec})" + cp ${self.knownRockspec} "$rockspecFilename" '' + '' runHook postConfigure @@ -155,9 +155,9 @@ let nix_debug "Using LUAROCKS_CONFIG=$LUAROCKS_CONFIG" - LUAROCKS=luarocks + LUAROCKS_EXTRA_ARGS="" if (( ''${NIX_DEBUG:-0} >= 1 )); then - LUAROCKS="$LUAROCKS --verbose" + LUAROCKS_EXTRA_ARGS=" --verbose" fi runHook postBuild @@ -167,7 +167,7 @@ let wrapLuaPrograms '' + attrs.postFixup or ""; - installPhase = attrs.installPhase or '' + installPhase = '' runHook preInstall # work around failing luarocks test for Write access @@ -182,21 +182,17 @@ let # maybe we could reestablish dependency checking via passing --rock-trees nix_debug "ROCKSPEC $rockspecFilename" - nix_debug "cwd: $PWD" - $LUAROCKS make --deps-mode=all --tree=$out ''${rockspecFilename} + luarocks $LUAROCKS_EXTRA_ARGS make --deps-mode=all --tree=$out ''${rockspecFilename} runHook postInstall ''; - - checkPhase = attrs.checkPhase or '' + checkPhase = '' runHook preCheck - $LUAROCKS test + luarocks test runHook postCheck ''; - LUAROCKS_CONFIG="$PWD/${luarocks_config}"; - shellHook = '' runHook preShell export LUAROCKS_CONFIG="$PWD/${luarocks_config}"; @@ -205,16 +201,14 @@ let passthru = { inherit lua; # The lua interpreter - inherit externalDeps; - inherit luarocks_content; - } // passthru; + }; meta = { platforms = lua.meta.platforms; # add extra maintainer(s) to every package - maintainers = (meta.maintainers or []) ++ [ ]; + maintainers = (attrs.meta.maintainers or []) ++ [ ]; broken = disabled; - } // meta; + } // attrs.meta; })); in luarocksDrv |