convert anoia.fs to use lualinux instead of lfs

This commit is contained in:
Daniel Barlow 2024-04-24 20:44:32 +01:00
parent 834858d5bc
commit dbd1264352
4 changed files with 27 additions and 12 deletions

View file

@ -2,6 +2,7 @@
fennel
, stdenv
, lua
, lualinux
}:
let pname = "anoia";
in stdenv.mkDerivation {
@ -9,7 +10,7 @@ in stdenv.mkDerivation {
version = "0.1";
src = ./.;
nativeBuildInputs = [ fennel ];
buildInputs = with lua.pkgs; [ luafilesystem ];
buildInputs = with lua.pkgs; [ luafilesystem lualinux ];
outputs = [ "out" "dev" ];
doCheck = true;

View file

@ -1,7 +1,19 @@
(local lfs (require :lfs))
(local ll (require :lualinux))
(local S_IFMT 0xf000)
(local S_IFSOCK 0xc000)
(local S_IFLNK 0xa000)
(local S_IFREG 0x8000)
(local S_IFBLK 0x6000)
(local S_IFDIR 0x4000)
(local S_IFCHR 0x2000)
(local S_IFIFO 0x1000)
(fn ifmt-bits [mode] (and mode (band mode 0xf000)))
(fn directory? [pathname]
(= (lfs.symlinkattributes pathname :mode) "directory"))
(let [(mode size mtime) (ll.lstat3 pathname)]
(= (ifmt-bits mode) S_IFDIR)))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
@ -10,28 +22,28 @@
(or (directory? pathname)
(let [parent (string.gsub pathname "/[^/]+/?$" "")]
(or (directory? parent) (mktree parent))
(assert (lfs.mkdir pathname)))))
(assert (ll.mkdir pathname)))))
(fn rmtree [pathname]
(case (lfs.symlinkattributes pathname)
(case (ifmt-bits (ll.lstat3 pathname))
nil true
{:mode "directory"}
S_IFDIR
(do
(each [f (lfs.dir pathname)]
(when (not (or (= f ".") (= f "..")))
(rmtree ( .. pathname "/" f)))
(lfs.rmdir pathname)))
{:mode "file"}
S_IFREG
(os.remove pathname)
{:mode "link"}
S_IFLNK
(os.remove pathname)
unknown
(error (.. "can't remove " pathname " of kind \"" unknown.mode "\""))))
(error (.. "can't remove " pathname " of mode \"" unknown "\""))))
{
: mktree
: rmtree
: directory?
:symlink (fn [from to] (lfs.link from to true))
:symlink (fn [from to] (ll.symlink from to))
}

View file

@ -2,5 +2,6 @@
writeFennelScript
, anoia
, lua
, lualinux
}:
writeFennelScript "odhcpc-script" [anoia lua.pkgs.luafilesystem] ./odhcp6-script.fnl
writeFennelScript "odhcpc-script" [anoia lualinux] ./odhcp6-script.fnl

View file

@ -1,6 +1,7 @@
{
lua
, nellie
, lualinux
, writeFennel
, runCommand
, anoia
@ -15,7 +16,7 @@ stdenv.mkDerivation {
installPhase = ''
mkdir -p $out/bin
cp -p ${writeFennel "uevent-watch" {
packages = [fennel anoia nellie lua.pkgs.luafilesystem];
packages = [fennel anoia nellie lualinux];
mainFunction = "run";
} ./watch.fnl} $out/bin/uevent-watch
'';