liminix-fork/pkgs/write-fennel-script/default.nix
Daniel Barlow 24befe6bf7 install fennel from source as a package
nixos lua packaging is giving me a headache
2023-07-04 22:56:17 +01:00

27 lines
715 B
Nix

{
lua
, lib
, fennel
, stdenv
}:
name : packages : source :
let
luapath = builtins.map (f: "${f}/share/lua/${lua.luaversion}/?.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 luapath} .. package.path"
echo "package.cpath = ${lib.strings.escapeShellArg luacpath} .. package.cpath"
fennel --correlate --compile ${source}
) > ${name}.lua
'';
installPhase = ''
cp ${name}.lua $out
chmod +x $out
'';
}