liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 69bf6cb5fbe68a2a7ed4e3eeab0596a64d25ea5e
parent 9f58e7b926652dcdbea58694831f7dea58b882c6
Author: Daniel Barlow <dan@telent.net>
Date:   Sat,  7 Sep 2024 22:31:44 +0100

write-fennel quote PATH properly

escapeShellArg only quotes if the string contains special
characters, but for a Lua string we must quote unconditionally

Diffstat:
Mpkgs/write-fennel/default.nix | 13+++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/pkgs/write-fennel/default.nix b/pkgs/write-fennel/default.nix @@ -13,7 +13,7 @@ name: }: source: let - inherit (builtins) concatStringsSep map; + inherit (builtins) concatStringsSep replaceStrings map; luapath = map ( f: "${f}/share/lua/${lua.luaversion}/?.lua;" + "${f}/share/lua/${lua.luaversion}/?/init.lua;" ) packages; @@ -21,6 +21,7 @@ let macropath = concatStringsSep ";" (map (f: "${f}/share/lua/${lua.luaversion}/?.fnl") macros); luaFlags = lib.optionalString (mainFunction != null) "-e dofile(arg[0]).${mainFunction}()"; + quoteString = string : "'${replaceStrings ["'"] ["'\\''"] string}'"; in stdenv.mkDerivation { inherit name; @@ -29,11 +30,11 @@ stdenv.mkDerivation { buildPhase = '' ( echo "#!${lua}/bin/lua ${luaFlags}" - echo "package.path = ${lib.strings.escapeShellArg (concatStringsSep "" luapath)} .. package.path" - echo "package.cpath = ${lib.strings.escapeShellArg (concatStringsSep "" luacpath)} .. package.cpath" - echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH',${lib.escapeShellArg (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" - echo "local ok, ll = pcall(require,'lualinux'); if ok then ll.setenv('PATH',${lib.escapeShellArg (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" - fennel ${if macropath != "" then "--add-macro-path ${lib.strings.escapeShellArg macropath}" else ""} ${if correlate then "--correlate" else ""} --compile ${source} + echo "package.path = ${quoteString (concatStringsSep "" luapath)} .. package.path" + echo "package.cpath = ${quoteString (concatStringsSep "" luacpath)} .. package.cpath" + echo "local ok, stdlib = pcall(require,'posix.stdlib'); if ok then stdlib.setenv('PATH',${quoteString (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" + echo "local ok, ll = pcall(require,'lualinux'); if ok then ll.setenv('PATH',${quoteString (lib.makeBinPath packages)} .. \":\" .. os.getenv('PATH')) end" + fennel ${if macropath != "" then "--add-macro-path ${quoteString macropath}" else ""} ${if correlate then "--correlate" else ""} --compile ${source} ) > ${name}.lua '';