fennel: extract some common functions into a shareable module

This commit is contained in:
Daniel Barlow 2023-07-05 20:23:27 +01:00
parent c3bb33c9ce
commit 2de4d7a8f9
7 changed files with 60 additions and 21 deletions

14
pkgs/anoia/README Normal file
View file

@ -0,0 +1,14 @@
In Terry Pratchett's Discworld novels, Anoi is a minor goddess of Things That Stick In Drawers
> Often, but not uniquely, a ladle, but sometimes a metal spatula or,
> rarely, a mechanical egg-whisk that nobody in the house admits to
> ever buying. The desperate mad rattling and cries of How can it
> close on the damn thing but not open with it? Who bought this? Do we
> ever use it? is as praise unto Anoia. She also eats corkscrews.
This is a library of miscellaneous Fennel code used in Liminix that is
shared between various scripts but doesn't really fit together. It is
not a public stable interface - while any Liminix code is welcome to
use it, it's suject to reshuffle, rearrangement, refactor or rejection
without notice.

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

@ -0,0 +1,19 @@
{
fennel
, stdenv
, lua
}:
let pname = "anoia";
in stdenv.mkDerivation {
inherit pname;
version = "0.1";
src = ./.;
nativeBuildInputs = [ fennel ];
buildPhase = ''
fennel --compile init.fnl > init.lua
'';
installPhase = ''
mkdir -p "$out/share/lua/${lua.luaversion}/${pname}"
cp *.lua "$out/share/lua/${lua.luaversion}/${pname}"
'';
}

16
pkgs/anoia/init.fnl Normal file
View file

@ -0,0 +1,16 @@
(fn merge [table1 table2]
(collect [k v (pairs table2) &into table1]
k v))
(fn split [sep string]
(icollect [v (string.gmatch string (.. "([^" sep "]+)"))]
v))
(fn file-exists? [name]
(match (io.open name :r)
f (do (f:close) true)
_ false))
(fn system [s] (assert (os.execute s)))
{ : merge : split : file-exists? : system }