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

@ -56,4 +56,5 @@
firewallgen = callPackage ./firewallgen {};
kernel-modules = callPackage ./kernel-modules {};
odhcp-script = callPackage ./odhcp-script {};
fennel = callPackage ./fennel {};
}

19
pkgs/fennel/default.nix Normal file
View file

@ -0,0 +1,19 @@
{
stdenv
, lua
, fetchFromSourcehut
}:
let pname = "fennel";
in stdenv.mkDerivation {
inherit pname;
version = "1.3";
nativeBuildInputs = [ lua ]; # used in build
buildInputs = [ lua ]; # needed for patchShebangs
src = fetchFromSourcehut {
owner = "~technomancy";
repo = pname;
rev = "1.3.0";
hash = "sha256-DXJOdYzfjTncqL7BsDbdvZcauDMkZV2X0U0FfhfwQrw=";
};
makeFlags = [ "PREFIX=${placeholder "out"}" ];
}

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
'';
}