From 69bf6cb5fbe68a2a7ed4e3eeab0596a64d25ea5e Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 7 Sep 2024 22:31:44 +0100 Subject: [PATCH] write-fennel quote PATH properly escapeShellArg only quotes if the string contains special characters, but for a Lua string we must quote unconditionally --- pkgs/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 index 25be271..3f765c6 100644 --- 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 '';