From 2b0972ed73222a104dbe45a330e29a398879e567 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 11 Mar 2025 00:21:44 +0000 Subject: [PATCH] svc.open accepts a /nix/store folder not an outputs folder this mostly makes things simpler --- NEWS | 14 +++++++++++++- modules/firewall/service.nix | 2 +- pkgs/anoia/Makefile | 14 ++++++++------ .../{ => .outputs}/addresses/1/attribute | 0 .../{ => .outputs}/addresses/3/attribute | 0 .../{ => .outputs}/addresses/5/attribute | 0 .../{ => .outputs}/addresses/6/attribute | 0 pkgs/anoia/example-output/.outputs/array/1 | 1 + pkgs/anoia/example-output/.outputs/array/2 | 1 + pkgs/anoia/example-output/.outputs/array/3 | 1 + pkgs/anoia/example-output/.outputs/array/4 | 1 + .../example-output/{ => .outputs}/colours/black | 0 .../example-output/{ => .outputs}/colours/blue | 0 .../example-output/{ => .outputs}/colours/green | 0 .../example-output/{ => .outputs}/colours/red | 0 pkgs/anoia/example-output/{ => .outputs}/name | 0 pkgs/anoia/svc.fnl | 16 +++++++++------- pkgs/output-template/output-template.fnl | 2 +- pkgs/watch-outputs/watch-outputs.fnl | 2 +- pkgs/watch-ssh-keys/watch-ssh-keys.fnl | 3 +-- 20 files changed, 38 insertions(+), 19 deletions(-) rename pkgs/anoia/example-output/{ => .outputs}/addresses/1/attribute (100%) rename pkgs/anoia/example-output/{ => .outputs}/addresses/3/attribute (100%) rename pkgs/anoia/example-output/{ => .outputs}/addresses/5/attribute (100%) rename pkgs/anoia/example-output/{ => .outputs}/addresses/6/attribute (100%) create mode 100644 pkgs/anoia/example-output/.outputs/array/1 create mode 100644 pkgs/anoia/example-output/.outputs/array/2 create mode 100644 pkgs/anoia/example-output/.outputs/array/3 create mode 100644 pkgs/anoia/example-output/.outputs/array/4 rename pkgs/anoia/example-output/{ => .outputs}/colours/black (100%) rename pkgs/anoia/example-output/{ => .outputs}/colours/blue (100%) rename pkgs/anoia/example-output/{ => .outputs}/colours/green (100%) rename pkgs/anoia/example-output/{ => .outputs}/colours/red (100%) rename pkgs/anoia/example-output/{ => .outputs}/name (100%) diff --git a/NEWS b/NEWS index d4ee589..02e3098 100644 --- a/NEWS +++ b/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. \ No newline at end of file +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 diff --git a/modules/firewall/service.nix b/modules/firewall/service.nix index dc50d0b..59066a9 100644 --- a/modules/firewall/service.nix +++ b/modules/firewall/service.nix @@ -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; diff --git a/pkgs/anoia/Makefile b/pkgs/anoia/Makefile index 93f4dbf..df1435c 100644 --- a/pkgs/anoia/Makefile +++ b/pkgs/anoia/Makefile @@ -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 diff --git a/pkgs/anoia/example-output/addresses/1/attribute b/pkgs/anoia/example-output/.outputs/addresses/1/attribute similarity index 100% rename from pkgs/anoia/example-output/addresses/1/attribute rename to pkgs/anoia/example-output/.outputs/addresses/1/attribute diff --git a/pkgs/anoia/example-output/addresses/3/attribute b/pkgs/anoia/example-output/.outputs/addresses/3/attribute similarity index 100% rename from pkgs/anoia/example-output/addresses/3/attribute rename to pkgs/anoia/example-output/.outputs/addresses/3/attribute diff --git a/pkgs/anoia/example-output/addresses/5/attribute b/pkgs/anoia/example-output/.outputs/addresses/5/attribute similarity index 100% rename from pkgs/anoia/example-output/addresses/5/attribute rename to pkgs/anoia/example-output/.outputs/addresses/5/attribute diff --git a/pkgs/anoia/example-output/addresses/6/attribute b/pkgs/anoia/example-output/.outputs/addresses/6/attribute similarity index 100% rename from pkgs/anoia/example-output/addresses/6/attribute rename to pkgs/anoia/example-output/.outputs/addresses/6/attribute diff --git a/pkgs/anoia/example-output/.outputs/array/1 b/pkgs/anoia/example-output/.outputs/array/1 new file mode 100644 index 0000000..ef07ddc --- /dev/null +++ b/pkgs/anoia/example-output/.outputs/array/1 @@ -0,0 +1 @@ +cat diff --git a/pkgs/anoia/example-output/.outputs/array/2 b/pkgs/anoia/example-output/.outputs/array/2 new file mode 100644 index 0000000..18a619c --- /dev/null +++ b/pkgs/anoia/example-output/.outputs/array/2 @@ -0,0 +1 @@ +dog diff --git a/pkgs/anoia/example-output/.outputs/array/3 b/pkgs/anoia/example-output/.outputs/array/3 new file mode 100644 index 0000000..cab3a22 --- /dev/null +++ b/pkgs/anoia/example-output/.outputs/array/3 @@ -0,0 +1 @@ +cow diff --git a/pkgs/anoia/example-output/.outputs/array/4 b/pkgs/anoia/example-output/.outputs/array/4 new file mode 100644 index 0000000..5dd9b45 --- /dev/null +++ b/pkgs/anoia/example-output/.outputs/array/4 @@ -0,0 +1 @@ +sheep diff --git a/pkgs/anoia/example-output/colours/black b/pkgs/anoia/example-output/.outputs/colours/black similarity index 100% rename from pkgs/anoia/example-output/colours/black rename to pkgs/anoia/example-output/.outputs/colours/black diff --git a/pkgs/anoia/example-output/colours/blue b/pkgs/anoia/example-output/.outputs/colours/blue similarity index 100% rename from pkgs/anoia/example-output/colours/blue rename to pkgs/anoia/example-output/.outputs/colours/blue diff --git a/pkgs/anoia/example-output/colours/green b/pkgs/anoia/example-output/.outputs/colours/green similarity index 100% rename from pkgs/anoia/example-output/colours/green rename to pkgs/anoia/example-output/.outputs/colours/green diff --git a/pkgs/anoia/example-output/colours/red b/pkgs/anoia/example-output/.outputs/colours/red similarity index 100% rename from pkgs/anoia/example-output/colours/red rename to pkgs/anoia/example-output/.outputs/colours/red diff --git a/pkgs/anoia/example-output/name b/pkgs/anoia/example-output/.outputs/name similarity index 100% rename from pkgs/anoia/example-output/name rename to pkgs/anoia/example-output/.outputs/name diff --git a/pkgs/anoia/svc.fnl b/pkgs/anoia/svc.fnl index 7bf2c46..9d2f757 100644 --- a/pkgs/anoia/svc.fnl +++ b/pkgs/anoia/svc.fnl @@ -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 diff --git a/pkgs/output-template/output-template.fnl b/pkgs/output-template/output-template.fnl index 186c8ae..3ec6157 100644 --- a/pkgs/output-template/output-template.fnl +++ b/pkgs/output-template/output-template.fnl @@ -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) "\"")) diff --git a/pkgs/watch-outputs/watch-outputs.fnl b/pkgs/watch-outputs/watch-outputs.fnl index 9ae6344..59ea7a0 100644 --- a/pkgs/watch-outputs/watch-outputs.fnl +++ b/pkgs/watch-outputs/watch-outputs.fnl @@ -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 {} diff --git a/pkgs/watch-ssh-keys/watch-ssh-keys.fnl b/pkgs/watch-ssh-keys/watch-ssh-keys.fnl index 3be0577..7d2fb6e 100644 --- a/pkgs/watch-ssh-keys/watch-ssh-keys.fnl +++ b/pkgs/watch-ssh-keys/watch-ssh-keys.fnl @@ -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) {})))))