commit cdb23b147c7a1c0996125a38b9e468ce1a9df2ce
parent dbd1264352542267eb941738e42b582d5f7ab9f0
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 25 Apr 2024 21:14:37 +0100
convert anoia.fs to use lualinux
Diffstat:
9 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/modules/dhcp6c/acquire-delegated-prefix.nix b/modules/dhcp6c/acquire-delegated-prefix.nix
@@ -3,8 +3,9 @@
, linotify
, anoia
, lua
+, lualinux
}:
writeFennel "acquire-delegated-prefix" {
- packages = [ linotify anoia lua.pkgs.luafilesystem ];
+ packages = [ linotify anoia lualinux ];
mainFunction = "run";
} ./acquire-delegated-prefix.fnl
diff --git a/modules/dhcp6c/acquire-wan-address.nix b/modules/dhcp6c/acquire-wan-address.nix
@@ -2,9 +2,10 @@
writeFennel
, linotify
, anoia
+, lualinux
, lua
}:
writeFennel "acquire-wan-address" {
- packages = [ linotify anoia lua.pkgs.luafilesystem ];
+ packages = [ linotify anoia lualinux ];
mainFunction = "run";
} ./acquire-wan-address.fnl
diff --git a/pkgs/anoia/Makefile b/pkgs/anoia/Makefile
@@ -2,7 +2,9 @@
default: fs.lua init.lua nl.lua svc.lua
test:
+ ln -s . anoia
fennel test.fnl
+ fennel test-svc.fnl
%.lua: %.fnl
fennel --compile $< > $@
diff --git a/pkgs/anoia/default.nix b/pkgs/anoia/default.nix
@@ -1,6 +1,7 @@
{
fennel
, stdenv
+, linotify
, lua
, lualinux
}:
@@ -10,7 +11,7 @@ in stdenv.mkDerivation {
version = "0.1";
src = ./.;
nativeBuildInputs = [ fennel ];
- buildInputs = with lua.pkgs; [ luafilesystem lualinux ];
+ buildInputs = with lua.pkgs; [ linotify lualinux ];
outputs = [ "out" "dev" ];
doCheck = true;
diff --git a/pkgs/anoia/fs.fnl b/pkgs/anoia/fs.fnl
@@ -11,9 +11,20 @@
(fn ifmt-bits [mode] (and mode (band mode 0xf000)))
+(fn file-type [pathname]
+ (. {
+ S_IFDIR :directory
+ S_IFSOCK :socket
+ S_IFLNK :link
+ S_IFREG :file
+ S_IFBLK :block-device
+ S_IFCHR :character-device
+ S_IFIFO :fifo
+ }
+ (ifmt-bits (ll.lstat3 pathname))))
+
(fn directory? [pathname]
- (let [(mode size mtime) (ll.lstat3 pathname)]
- (= (ifmt-bits mode) S_IFDIR)))
+ (= (file-type pathname) :directory))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
@@ -24,18 +35,25 @@
(or (directory? parent) (mktree parent))
(assert (ll.mkdir pathname)))))
+(fn dir [name]
+ (let [dp (assert (ll.opendir name) name)]
+ (fn []
+ (match (ll.readdir dp)
+ (name type) (values name type)
+ (nil err) (do (if err (print err)) (ll.closedir dp) nil)))))
+
(fn rmtree [pathname]
- (case (ifmt-bits (ll.lstat3 pathname))
+ (case (file-type pathname)
nil true
- S_IFDIR
+ :directory
(do
- (each [f (lfs.dir pathname)]
+ (each [f (dir pathname)]
(when (not (or (= f ".") (= f "..")))
(rmtree ( .. pathname "/" f)))
- (lfs.rmdir pathname)))
- S_IFREG
+ (ll.rmdir pathname)))
+ :file
(os.remove pathname)
- S_IFLNK
+ :link
(os.remove pathname)
unknown
(error (.. "can't remove " pathname " of mode \"" unknown "\""))))
@@ -45,5 +63,7 @@
: mktree
: rmtree
: directory?
+ : dir
+ : file-type
:symlink (fn [from to] (ll.symlink from to))
}
diff --git a/pkgs/anoia/svc.fnl b/pkgs/anoia/svc.fnl
@@ -1,7 +1,6 @@
(local inotify (require :inotify))
(local { : file-exists? } (require :anoia))
-(local { : directory? } (require :anoia.fs))
-(local lfs (require :lfs))
+(local { : file-type : dir &as fs } (require :anoia.fs))
(fn read-line [name]
(with-open [f (assert (io.open name :r) (.. "can't open file " name))]
@@ -20,15 +19,15 @@
handle))
(fn read-value [pathname]
- (case (lfs.symlinkattributes pathname)
+ (case (file-type pathname)
nil nil
- {:mode "directory"}
- (collect [f (lfs.dir pathname)]
+ :directory
+ (collect [f (fs.dir pathname)]
(when (not (or (= f ".") (= f "..")))
(values f (read-value ( .. pathname "/" f)))))
- {:mode "file"}
+ :file
(read-line pathname)
- {:mode "link"}
+ :link
(read-line pathname)
unknown
(error (.. "can't read " pathname " of kind \"" unknown.mode "\""))))
diff --git a/pkgs/anoia/test-svc.fnl b/pkgs/anoia/test-svc.fnl
@@ -1,4 +1,4 @@
-(local svc (require :anoia.svc))
+(local svc (require :svc))
(local { : view } (require :fennel))
(local ex (svc.open "./example-output"))
diff --git a/pkgs/devout/default.nix b/pkgs/devout/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
installPhase = ''
mkdir -p $out/bin
cp -p ${writeFennel "devout" {
- packages = [fennel anoia nellie lua.pkgs.luafilesystem lualinux];
+ packages = [fennel anoia nellie lualinux];
mainFunction = "run";
} ./devout.fnl} $out/bin/devout
'';
diff --git a/pkgs/fennelrepl/default.nix b/pkgs/fennelrepl/default.nix
@@ -19,7 +19,6 @@ let packages = [
lualinux
netlink-lua
lua.pkgs.readline
- lua.pkgs.luafilesystem
];
join = ps: builtins.concatStringsSep ";" ps;
luapath = join (builtins.map (f: