svc.open accepts a /nix/store folder not an outputs folder
this mostly makes things simpler
This commit is contained in:
parent
f22237a3b3
commit
2b0972ed73
14
NEWS
14
NEWS
@ -156,4 +156,16 @@ https://www.liminix.org/doc/admin.html#updating-an-installed-system
|
||||
2024-12-22
|
||||
|
||||
outputs.zimage is now outputs.kernel.zImage. This is unlikely to
|
||||
affect many people at all but I mention it anyway.
|
||||
affect many people at all but I mention it anyway.
|
||||
|
||||
2024-03-11
|
||||
|
||||
The fennel function (svc.open ...) now expects to be given the store
|
||||
directory of a service derivation, not a direct path to the .outputs
|
||||
directory. Thus
|
||||
|
||||
(svc.open "/nix/store/eeeeeeeeeeeeee-hellod")
|
||||
not
|
||||
(svc.open "/nix/store/eeeeeeeeeeeeee-hellod/.outputs")
|
||||
|
||||
This simplifies most extant uses of it
|
||||
|
@ -49,7 +49,7 @@ let
|
||||
(mapAttrs' (n: _: mkSet "ip6" n) zones);
|
||||
allRules = lib.recursiveUpdate extraRules (lib.recursiveUpdate sets rules);
|
||||
script = firewallgen "firewall1.nft" allRules;
|
||||
watchArg = z: intfs: map (i: "${z}:${i}/.outputs") intfs;
|
||||
watchArg = z: intfs: map (i: "${z}:${i}") intfs;
|
||||
name = "firewall";
|
||||
service = longrun {
|
||||
inherit name;
|
||||
|
@ -1,4 +1,5 @@
|
||||
servicedir:=$(shell mktemp -d)
|
||||
outputdir:=$(servicedir)/.outputs
|
||||
|
||||
default: fs.lua init.lua nl.lua svc.lua process.lua net/constants.lua
|
||||
|
||||
@ -9,12 +10,13 @@ check:
|
||||
fennel ./run-tests.fnl $(CHECK)
|
||||
fennel test.fnl
|
||||
fennel test-svc.fnl $(servicedir)
|
||||
test -f $(servicedir)/fish
|
||||
test "`cat $(servicedir)/fish`" = "food"
|
||||
test -d $(servicedir)/nested/path
|
||||
test "`cat $(servicedir)/nested/path/name`" = "value"
|
||||
test "`cat $(servicedir)/nested/path/complex/attribute`" = "val"
|
||||
test "`cat $(servicedir)/nested/path/complex/other`" = "42"
|
||||
find $(outputdir) -ls
|
||||
test -f $(outputdir)/fish
|
||||
test "`cat $(outputdir)/fish`" = "food"
|
||||
test -d $(outputdir)/nested/path
|
||||
test "`cat $(outputdir)/nested/path/name`" = "value"
|
||||
test "`cat $(outputdir)/nested/path/complex/attribute`" = "val"
|
||||
test "`cat $(outputdir)/nested/path/complex/other`" = "42"
|
||||
|
||||
|
||||
net/constants.lua: net/constants.c
|
||||
|
1
pkgs/anoia/example-output/.outputs/array/1
Normal file
1
pkgs/anoia/example-output/.outputs/array/1
Normal file
@ -0,0 +1 @@
|
||||
cat
|
1
pkgs/anoia/example-output/.outputs/array/2
Normal file
1
pkgs/anoia/example-output/.outputs/array/2
Normal file
@ -0,0 +1 @@
|
||||
dog
|
1
pkgs/anoia/example-output/.outputs/array/3
Normal file
1
pkgs/anoia/example-output/.outputs/array/3
Normal file
@ -0,0 +1 @@
|
||||
cow
|
1
pkgs/anoia/example-output/.outputs/array/4
Normal file
1
pkgs/anoia/example-output/.outputs/array/4
Normal file
@ -0,0 +1 @@
|
||||
sheep
|
@ -1,5 +1,5 @@
|
||||
(local inotify (require :inotify))
|
||||
(local { : file-exists? : dirname } (require :anoia))
|
||||
(local { : file-exists? : dirname : append-path } (require :anoia))
|
||||
(local { : file-type : dir : mktree &as fs } (require :anoia.fs))
|
||||
|
||||
(fn read-line [name]
|
||||
@ -25,7 +25,7 @@
|
||||
(with-open [f (assert (io.open pathname :w) (.. "can't open " pathname))]
|
||||
(f:write value))
|
||||
"table" (each [k v (pairs value)]
|
||||
(write-value (.. pathname "/" k) v))))
|
||||
(write-value (append-path pathname k) v))))
|
||||
|
||||
(fn read-value [pathname]
|
||||
(case (file-type pathname)
|
||||
@ -33,7 +33,7 @@
|
||||
:directory
|
||||
(collect [f (fs.dir pathname)]
|
||||
(when (not (or (= f ".") (= f "..")))
|
||||
(values f (read-value ( .. pathname "/" f)))))
|
||||
(values f (read-value (append-path pathname f)))))
|
||||
:file
|
||||
(read-line pathname)
|
||||
:link
|
||||
@ -50,15 +50,17 @@
|
||||
|
||||
(fn open [directory]
|
||||
(let [watcher (watch-fsevents directory)
|
||||
has-file? (fn [filename] (file-exists? (.. directory "/" filename)))]
|
||||
has-file? #(file-exists? (append-path directory $1))
|
||||
outputs-dir (append-path directory ".outputs")]
|
||||
{
|
||||
:wait #(watcher:read)
|
||||
:ready? (fn [self]
|
||||
(and (has-file? "state") (not (has-file? ".lock"))))
|
||||
(and (has-file? ".outputs/state")
|
||||
(not (has-file? ".outputs/.lock"))))
|
||||
:output (fn [_ filename new-value]
|
||||
(if new-value
|
||||
(write-value (.. directory "/" filename) new-value)
|
||||
(read-value (.. directory "/" filename))))
|
||||
(write-value (append-path outputs-dir filename) new-value)
|
||||
(read-value (append-path outputs-dir filename))))
|
||||
:close #(watcher:close)
|
||||
:fileno #(watcher:fileno)
|
||||
: events
|
||||
|
@ -28,7 +28,7 @@
|
||||
: ipairs
|
||||
:output
|
||||
(fn [service-path path default]
|
||||
(let [s (assert (svc.open (.. service-path "/.outputs")))]
|
||||
(let [s (assert (svc.open service-path))]
|
||||
(or (s:output path) default)))
|
||||
:lua_quote #(string.format "%q" $1)
|
||||
:json_quote (fn [x] (.. "\"" (json-escape x) "\""))
|
||||
|
@ -71,7 +71,7 @@
|
||||
|
||||
(fn open-services [output-references]
|
||||
(collect [s p (pairs output-references)]
|
||||
(values (svc.open (.. s "/.outputs")) p)))
|
||||
(values (svc.open s) p)))
|
||||
|
||||
(fn run []
|
||||
(let [trees {}
|
||||
|
@ -50,8 +50,7 @@
|
||||
|
||||
(fn run []
|
||||
(let [{: out-path : watched-service : path } (parse-args arg)
|
||||
dir (.. watched-service "/.outputs")
|
||||
service (assert (svc.open dir))]
|
||||
service (assert (svc.open watched-service))]
|
||||
(accumulate [tree {}
|
||||
v (service:events)]
|
||||
(write-changes out-path tree (or (service:output path) {})))))
|
||||
|
Loading…
Reference in New Issue
Block a user