liminix/pkgs/fennelrepl/default.nix

49 lines
1.3 KiB
Nix
Raw Permalink Normal View History

{
runCommand
, runtimeShell
, fetchurl
, lib
, luaPackages
, lua
2024-04-24 19:30:34 +02:00
, lualinux
, writeScriptBin
, linotify
, anoia
2024-03-04 23:47:56 +01:00
, netlink-lua
, fennel
}:
let packages = [
linotify
anoia
fennel
2024-04-24 19:30:34 +02:00
lualinux
2024-03-04 23:47:56 +01:00
netlink-lua
2024-04-24 19:28:39 +02:00
lua.pkgs.readline
];
join = ps: builtins.concatStringsSep ";" ps;
luapath = join (builtins.map (f:
"${f}/share/lua/${lua.luaversion}/?.lua;" +
"${f}/share/lua/${lua.luaversion}/?/init.lua"
) packages);
luacpath = join (builtins.map (f: "${f}/lib/lua/${lua.luaversion}/?.so") packages);
in writeScriptBin "fennelrepl" ''
#!${lua}/bin/lua
package.path = ${lib.strings.escapeShellArg luapath} .. ";" .. package.path
package.cpath = ${lib.strings.escapeShellArg luacpath} .. ";" .. (package.cpath or "")
local fennel = require "fennel"
table.insert(package.loaders or package.searchers,1, fennel.searcher)
fennel['macro-path'] = "${anoia.dev}/share/lua/${lua.luaversion}/?.fnl;" .. fennel['macro-path']
local more_fennel = os.getenv("FENNEL_PATH")
if more_fennel then
fennel.path = more_fennel .. ";" .. fennel.path
end
if #arg > 0 then
script = table.remove(arg, 1)
fennel.dofile(script, {correlate = true}, arg)
else
fennel.repl()
end
''