From a486bc63cd04736ac2df72566510189f4630ad88 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sun, 22 Feb 2026 12:43:11 +0200 Subject: [PATCH 1/2] lua{5_{1,2,3,4},jit}Packages.wrapLua: remove sed that does nothing patchShebangs already takes care of this automatically and does it well, before this hook runs. --- pkgs/development/interpreters/lua-5/wrap-lua.nix | 1 - pkgs/development/interpreters/lua-5/wrap.sh | 6 ------ 2 files changed, 7 deletions(-) diff --git a/pkgs/development/interpreters/lua-5/wrap-lua.nix b/pkgs/development/interpreters/lua-5/wrap-lua.nix index 1f074b04425dc..e1c22c8a785f3 100644 --- a/pkgs/development/interpreters/lua-5/wrap-lua.nix +++ b/pkgs/development/interpreters/lua-5/wrap-lua.nix @@ -9,6 +9,5 @@ makeSetupHook { name = "wrap-lua-hook"; propagatedBuildInputs = [ makeWrapper ]; - substitutions.executable = lua.interpreter; substitutions.lua = lua; } ./wrap.sh diff --git a/pkgs/development/interpreters/lua-5/wrap.sh b/pkgs/development/interpreters/lua-5/wrap.sh index f6868e6faac56..c939d62e4ec8b 100644 --- a/pkgs/development/interpreters/lua-5/wrap.sh +++ b/pkgs/development/interpreters/lua-5/wrap.sh @@ -28,12 +28,6 @@ wrapLuaProgramsIn() { # Find all regular files in the output directory that are executable. find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do - # Rewrite "#! .../env lua" to "#! /nix/store/.../lua". - # Lua to use besides one with this hook anyway. - if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then - sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^" - fi - # wrapProgram creates the executable shell script described # above. The script will set LUA_(C)PATH and PATH variables! # (see pkgs/build-support/setup-hooks/make-wrapper.sh) From 7b9e4c7595832c9e2fa05212888fc2369c50eef1 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sun, 22 Feb 2026 12:45:49 +0200 Subject: [PATCH 2/2] buildLuarocksPackage: fix cross compilation wrapping - Make `lua` gain `luaOnBuildFor{Build,Host,Target}` and alike attributes. - wrapLua: correctly substitute build & host lua & luarocks_bootstrap - Disallow build platform references when using `buildLuarocksPackage` in cross building. --- .../lua-5/build-luarocks-package.nix | 8 ++++++++ .../development/interpreters/lua-5/default.nix | 7 +++++++ .../interpreters/lua-5/wrap-lua.nix | 5 ++++- pkgs/development/interpreters/lua-5/wrap.sh | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix index bc79b674b4720..8209abaeced05 100644 --- a/pkgs/development/interpreters/lua-5/build-luarocks-package.nix +++ b/pkgs/development/interpreters/lua-5/build-luarocks-package.nix @@ -1,10 +1,12 @@ # Generic builder for lua packages { lib, + stdenv, lua, wrapLua, luarocks_bootstrap, writeTextFile, + buildPackages, # Whether the derivation provides a lua module or not. luarocksCheckHook, @@ -236,6 +238,12 @@ let runHook postShell ''; + disallowedReferences = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + buildPackages.bash + lua.luaOnBuild + lua.luaOnBuild.pkgs.luarocks_bootstrap + ]; + passthru = { inherit lua; } diff --git a/pkgs/development/interpreters/lua-5/default.nix b/pkgs/development/interpreters/lua-5/default.nix index 1147893e5e432..50843b9a65835 100644 --- a/pkgs/development/interpreters/lua-5/default.nix +++ b/pkgs/development/interpreters/lua-5/default.nix @@ -90,6 +90,13 @@ let inherit packageOverrides; self = luaOnBuild; }; + inherit + luaOnBuildForBuild + luaOnBuildForHost + luaOnBuildForTarget + luaOnHostForHost + luaOnTargetForTarget + ; tests = callPackage ./tests { lua = self; diff --git a/pkgs/development/interpreters/lua-5/wrap-lua.nix b/pkgs/development/interpreters/lua-5/wrap-lua.nix index e1c22c8a785f3..94e546bf31250 100644 --- a/pkgs/development/interpreters/lua-5/wrap-lua.nix +++ b/pkgs/development/interpreters/lua-5/wrap-lua.nix @@ -9,5 +9,8 @@ makeSetupHook { name = "wrap-lua-hook"; propagatedBuildInputs = [ makeWrapper ]; - substitutions.lua = lua; + substitutions.luaBuild = lua.luaOnBuildForHost; + substitutions.luaHost = lua.luaOnHostForHost; + substitutions.luarocksBuild = lua.luaOnBuildForHost.pkgs.luarocks_bootstrap; + substitutions.luarocksHost = lua.luaOnHostForHost.pkgs.luarocks_bootstrap; } ./wrap.sh diff --git a/pkgs/development/interpreters/lua-5/wrap.sh b/pkgs/development/interpreters/lua-5/wrap.sh index c939d62e4ec8b..47b82279c17c1 100644 --- a/pkgs/development/interpreters/lua-5/wrap.sh +++ b/pkgs/development/interpreters/lua-5/wrap.sh @@ -3,7 +3,7 @@ # variable is passed in from the buildLuarocksPackage function. set -e -source @lua@/nix-support/utils.sh +source @luaBuild@/nix-support/utils.sh wrapLuaPrograms() { wrapLuaProgramsIn "$out/bin" "$out $luaPath" @@ -28,6 +28,18 @@ wrapLuaProgramsIn() { # Find all regular files in the output directory that are executable. find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do + if head -n1 "$f" | grep -q '#!.*'; then + # Cross-compilation hack: exec '/nix/store/...-lua-.../bin/lua' execute + # the host lua + substituteInPlace "$f" \ + --replace-fail "@luaBuild@" "@luaHost@" + # Build platform's Luarocks writes scripts that reference luarocks + # itself in them, so we fix these references to reference the host + # platform's luarocks. + substituteInPlace "$f" \ + --replace-fail "@luarocksBuild@" "@luarocksHost@" + fi + # wrapProgram creates the executable shell script described # above. The script will set LUA_(C)PATH and PATH variables! # (see pkgs/build-support/setup-hooks/make-wrapper.sh) @@ -46,5 +58,9 @@ wrapLuaProgramsIn() { # see setup-hooks/make-wrapper.sh wrapProgram "${wrapProgramArgs[@]}" + # Same as above, but now for the wrapper script + substituteInPlace "$f" \ + --replace-fail "@luarocksBuild@" "@luarocksHost@" + done }