convert anoia.fs to use lualinux

This commit is contained in:
Daniel Barlow 2024-04-25 21:14:37 +01:00
parent dbd1264352
commit cdb23b147c
9 changed files with 44 additions and 21 deletions

View file

@ -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

View file

@ -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

View file

@ -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 $< > $@

View file

@ -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;

View file

@ -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))
}

View file

@ -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 "\""))))

View file

@ -1,4 +1,4 @@
(local svc (require :anoia.svc))
(local svc (require :svc))
(local { : view } (require :fennel))
(local ex (svc.open "./example-output"))

View file

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

View file

@ -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: