From c3bb33c9ce9f1e337ae48eec4c6d345d83418787 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 4 Jul 2023 22:58:51 +0100 Subject: [PATCH] add fennelrepl package Runs fennel using a Lua compiled with the same options as the host system, and with packages set up so it can find all the local Lua packages To shorten the dev feedback loop further, allows FENNEL_PATH to be set on the command line so you can point directly it at the Fennel sources for some library you're working against instead of having to run nix-build and compile them to Lua --- default.nix | 1 + pkgs/default.nix | 1 + pkgs/fennelrepl/default.nix | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 pkgs/fennelrepl/default.nix diff --git a/default.nix b/default.nix index 120e9555..2c1027b5 100644 --- a/default.nix +++ b/default.nix @@ -58,6 +58,7 @@ in { borderVm.build.vm go-l2tp min-copy-closure + fennelrepl ]; }; } diff --git a/pkgs/default.nix b/pkgs/default.nix index 07b20c2e..e04ae515 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -57,4 +57,5 @@ kernel-modules = callPackage ./kernel-modules {}; odhcp-script = callPackage ./odhcp-script {}; fennel = callPackage ./fennel {}; + fennelrepl = callPackage ./fennelrepl {}; } diff --git a/pkgs/fennelrepl/default.nix b/pkgs/fennelrepl/default.nix new file mode 100644 index 00000000..cbc8ac0c --- /dev/null +++ b/pkgs/fennelrepl/default.nix @@ -0,0 +1,34 @@ +{ + runCommand +, runtimeShell +, fetchurl +, lib +, luaPackages +, lua +, writeScriptBin +, linotify +, anoia +, fennel +}: +let packages = [ + linotify + anoia + fennel + ]; + join = ps: builtins.concatStringsSep ";" ps; + luapath = join (builtins.map (f: "${f}/share/lua/${lua.luaversion}/?.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" + fennel.install() + local more_fennel = os.getenv("FENNEL_PATH") + if more_fennel then + fennel.path = more_fennel .. ";" .. fennel.path + end + print("path", fennel.path) + fennel.repl() + ''