diff --git a/pkgs/default.nix b/pkgs/default.nix index 1c52a63..e1fa46c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -52,6 +52,7 @@ in { }; }; writeFennelScript = callPackage ./write-fennel-script {}; + writeFennel = callPackage ./write-fennel {}; writeAshScript = callPackage ./write-ash-script {}; systemconfig = callPackage ./systemconfig {}; s6-init-bin = callPackage ./s6-init-bin {}; diff --git a/pkgs/write-fennel-script/default.nix b/pkgs/write-fennel-script/default.nix index dfe36f4..09e46c4 100644 --- a/pkgs/write-fennel-script/default.nix +++ b/pkgs/write-fennel-script/default.nix @@ -2,30 +2,8 @@ lua , lib , fennel +, writeFennel , stdenv }: name : packages : source : - let - luapath = builtins.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; - in stdenv.mkDerivation { - inherit name; - src = ./.; - nativeBuildInputs = [ fennel ]; - buildPhase = '' - ( - echo "#!${lua}/bin/lua" - echo "package.path = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luapath)} .. package.path" - echo "package.cpath = ${lib.strings.escapeShellArg (builtins.concatStringsSep "" luacpath)} .. package.cpath" - fennel --correlate --compile ${source} - ) > ${name}.lua - ''; - installPhase = '' - cp ${name}.lua $out - chmod +x $out - ''; - } +writeFennel name { inherit packages; } source diff --git a/pkgs/write-fennel/default.nix b/pkgs/write-fennel/default.nix new file mode 100644 index 0000000..c9be23e --- /dev/null +++ b/pkgs/write-fennel/default.nix @@ -0,0 +1,37 @@ +{ + lua +, lib +, fennel +, stdenv +}: +name : +{ + packages ? [], + correlate ? false, + mainFunction ? null +} @ options : source : + let + luapath = builtins.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; + luaFlags = lib.optionalString (mainFunction !=null) "-e dofile(arg[0]).${mainFunction}()"; + in stdenv.mkDerivation { + inherit name; + src = ./.; + nativeBuildInputs = [ fennel ]; + 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" + fennel ${if correlate then "--correlate" else ""} --compile ${source} + ) > ${name}.lua + ''; + installPhase = '' + cp ${name}.lua $out + chmod +x $out + ''; + }