install fennel from source as a package

nixos lua packaging is giving me a headache
This commit is contained in:
Daniel Barlow
2023-07-04 22:56:17 +01:00
parent 41687e916d
commit 24befe6bf7
3 changed files with 40 additions and 24 deletions

View File

@@ -1,31 +1,27 @@
{
runCommand
, lua
, runtimeShell
, fetchurl
lua
, lib
, lua53Packages
, fennel
, stdenv
}:
let inherit (lua53Packages) lua;
in name : packages : source :
name : packages : source :
let
fennel = fetchurl {
url = "https://fennel-lang.org/downloads/fennel-1.3.0";
hash = "sha256-hYSD3rBYF8iTjBOA1m+TvUu8BSp8q6uIMUXi0xwo/dU=";
};
luapath = builtins.map (f: "${f}/share/lua/${lua.luaversion}/?.lua;") packages;
luacpath = builtins.map (f: "${f}/lib/lua/${lua.luaversion}/?.so;") packages;
in runCommand name {
nativeBuildInputs = [ lua ];
} ''
echo $PATH
#!${runtimeShell}
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"
lua ${fennel} --correlate --compile ${source}
) > $out
chmod a+x $out
''
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
'';
}