commit dbd1264352542267eb941738e42b582d5f7ab9f0
parent 834858d5bc276ab962e717369eff7465285563af
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 24 Apr 2024 20:44:32 +0100
convert anoia.fs to use lualinux instead of lfs
Diffstat:
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/pkgs/anoia/default.nix b/pkgs/anoia/default.nix
@@ -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;
diff --git a/pkgs/anoia/fs.fnl b/pkgs/anoia/fs.fnl
@@ -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))
}
diff --git a/pkgs/odhcp-script/default.nix b/pkgs/odhcp-script/default.nix
@@ -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
diff --git a/pkgs/uevent-watch/default.nix b/pkgs/uevent-watch/default.nix
@@ -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
'';