forked from dan/liminix
add macros param to write-fennel
This commit is contained in:
parent
b475a680fb
commit
f34abc85ae
@ -7,15 +7,19 @@
|
||||
name:
|
||||
{
|
||||
packages ? [ ],
|
||||
macros ? [ ],
|
||||
correlate ? false,
|
||||
mainFunction ? null,
|
||||
}:
|
||||
source:
|
||||
let
|
||||
luapath = builtins.map (
|
||||
inherit (builtins) concatStringsSep map;
|
||||
luapath = map (
|
||||
f: "${f}/share/lua/${lua.luaversion}/?.lua;" + "${f}/share/lua/${lua.luaversion}/?/init.lua;"
|
||||
) packages;
|
||||
luacpath = builtins.map (f: "${f}/lib/lua/${lua.luaversion}/?.so;") packages;
|
||||
luacpath = map (f: "${f}/lib/lua/${lua.luaversion}/?.so;") packages;
|
||||
macropath = concatStringsSep ";"
|
||||
(map (f: "${f}/share/lua/${lua.luaversion}/?.fnl") macros);
|
||||
luaFlags = lib.optionalString (mainFunction != null) "-e dofile(arg[0]).${mainFunction}()";
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
@ -25,12 +29,13 @@ stdenv.mkDerivation {
|
||||
buildPhase = ''
|
||||
(
|
||||
echo "#!${lua}/bin/lua ${luaFlags}"
|
||||
echo "package.path = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luapath)} .. package.path"
|
||||
echo "package.cpath = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luacpath)} .. package.cpath"
|
||||
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 correlate then "--correlate" else ""} --compile ${source}
|
||||
fennel ${if macropath != "" then "--add-macro-path ${lib.strings.escapeShellArg macropath}" else ""} ${if correlate then "--correlate" else ""} --compile ${source}
|
||||
) > ${name}.lua
|
||||
|
||||
'';
|
||||
installPhase = ''
|
||||
cp ${name}.lua $out
|
||||
|
Loading…
Reference in New Issue
Block a user