1
0

Compare commits

..

No commits in common. "4e51977ae014e26e345304eb405e35a99dbf64f6" and "9dc0f2558761a5fe419608e044c9b62bac233f05" have entirely different histories.

23 changed files with 21 additions and 64 deletions

14
NEWS
View File

@ -156,16 +156,4 @@ https://www.liminix.org/doc/admin.html#updating-an-installed-system
2024-12-22 2024-12-22
outputs.zimage is now outputs.kernel.zImage. This is unlikely to 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

7
ci.nix
View File

@ -56,12 +56,7 @@ let
fennel fennel
luaPackages.lyaml luaPackages.lyaml
]; ];
src = ./.;
src = pkgs.lib.sources.sourceFilesBySuffices
(pkgs.lib.cleanSource ./. ) [
".nix" ".rst" "Makefile" ".svg" ".fnl" ".py"
];
buildPhase = '' buildPhase = ''
cat ${json} | fennel --correlate doc/parse-options.fnl > doc/modules-generated.inc.rst cat ${json} | fennel --correlate doc/parse-options.fnl > doc/modules-generated.inc.rst
cat ${json} | fennel --correlate doc/parse-options-outputs.fnl > doc/outputs-generated.inc.rst cat ${json} | fennel --correlate doc/parse-options-outputs.fnl > doc/outputs-generated.inc.rst

View File

@ -49,7 +49,7 @@ let
(mapAttrs' (n: _: mkSet "ip6" n) zones); (mapAttrs' (n: _: mkSet "ip6" n) zones);
allRules = lib.recursiveUpdate extraRules (lib.recursiveUpdate sets rules); allRules = lib.recursiveUpdate extraRules (lib.recursiveUpdate sets rules);
script = firewallgen "firewall1.nft" allRules; script = firewallgen "firewall1.nft" allRules;
watchArg = z: intfs: map (i: "${z}:${i}") intfs; watchArg = z: intfs: map (i: "${z}:${i}/.outputs") intfs;
name = "firewall"; name = "firewall";
service = longrun { service = longrun {
inherit name; inherit name;

View File

@ -1,5 +1,4 @@
servicedir:=$(shell mktemp -d) servicedir:=$(shell mktemp -d)
outputdir:=$(servicedir)/.outputs
default: fs.lua init.lua nl.lua svc.lua process.lua net/constants.lua default: fs.lua init.lua nl.lua svc.lua process.lua net/constants.lua
@ -10,13 +9,12 @@ check:
fennel ./run-tests.fnl $(CHECK) fennel ./run-tests.fnl $(CHECK)
fennel test.fnl fennel test.fnl
fennel test-svc.fnl $(servicedir) fennel test-svc.fnl $(servicedir)
find $(outputdir) -ls test -f $(servicedir)/fish
test -f $(outputdir)/fish test "`cat $(servicedir)/fish`" = "food"
test "`cat $(outputdir)/fish`" = "food" test -d $(servicedir)/nested/path
test -d $(outputdir)/nested/path test "`cat $(servicedir)/nested/path/name`" = "value"
test "`cat $(outputdir)/nested/path/name`" = "value" test "`cat $(servicedir)/nested/path/complex/attribute`" = "val"
test "`cat $(outputdir)/nested/path/complex/attribute`" = "val" test "`cat $(servicedir)/nested/path/complex/other`" = "42"
test "`cat $(outputdir)/nested/path/complex/other`" = "42"
net/constants.lua: net/constants.c net/constants.lua: net/constants.c

View File

@ -1 +0,0 @@
cat

View File

@ -1 +0,0 @@
dog

View File

@ -1 +0,0 @@
cow

View File

@ -1 +0,0 @@
sheep

View File

@ -1,5 +1,5 @@
(local inotify (require :inotify)) (local inotify (require :inotify))
(local { : file-exists? : dirname : append-path } (require :anoia)) (local { : file-exists? : dirname } (require :anoia))
(local { : file-type : dir : mktree &as fs } (require :anoia.fs)) (local { : file-type : dir : mktree &as fs } (require :anoia.fs))
(fn read-line [name] (fn read-line [name]
@ -25,7 +25,7 @@
(with-open [f (assert (io.open pathname :w) (.. "can't open " pathname))] (with-open [f (assert (io.open pathname :w) (.. "can't open " pathname))]
(f:write value)) (f:write value))
"table" (each [k v (pairs value)] "table" (each [k v (pairs value)]
(write-value (append-path pathname k) v)))) (write-value (.. pathname "/" k) v))))
(fn read-value [pathname] (fn read-value [pathname]
(case (file-type pathname) (case (file-type pathname)
@ -33,7 +33,7 @@
:directory :directory
(collect [f (fs.dir pathname)] (collect [f (fs.dir pathname)]
(when (not (or (= f ".") (= f ".."))) (when (not (or (= f ".") (= f "..")))
(values f (read-value (append-path pathname f))))) (values f (read-value ( .. pathname "/" f)))))
:file :file
(read-line pathname) (read-line pathname)
:link :link
@ -50,17 +50,15 @@
(fn open [directory] (fn open [directory]
(let [watcher (watch-fsevents directory) (let [watcher (watch-fsevents directory)
has-file? #(file-exists? (append-path directory $1)) has-file? (fn [filename] (file-exists? (.. directory "/" filename)))]
outputs-dir (append-path directory ".outputs")]
{ {
:wait #(watcher:read) :wait #(watcher:read)
:ready? (fn [self] :ready? (fn [self]
(and (has-file? ".outputs/state") (and (has-file? "state") (not (has-file? ".lock"))))
(not (has-file? ".outputs/.lock"))))
:output (fn [_ filename new-value] :output (fn [_ filename new-value]
(if new-value (if new-value
(write-value (append-path outputs-dir filename) new-value) (write-value (.. directory "/" filename) new-value)
(read-value (append-path outputs-dir filename)))) (read-value (.. directory "/" filename))))
:close #(watcher:close) :close #(watcher:close)
:fileno #(watcher:fileno) :fileno #(watcher:fileno)
: events : events

View File

@ -1,15 +1,5 @@
source $stdenv/setup source $stdenv/setup
mkdir -p $out/${name} mkdir -p $out/${name}
writepath(){
mkdir -p $(dirname $1)
echo $2 > $1
}
if test -n "$propertiesText"; then
mkdir $out/.properties
( cd $out/.properties; eval "$propertiesText" )
fi
echo $serviceType > $out/${name}/type echo $serviceType > $out/${name}/type
mkdir -p $out/${name}/dependencies.d mkdir -p $out/${name}/dependencies.d
echo $buildInputs > $out/buildInputs echo $buildInputs > $out/buildInputs

View File

@ -8,8 +8,6 @@
let let
prefix = "/run/services/outputs"; prefix = "/run/services/outputs";
output = service: name: "${prefix}/${service.name}/${name}"; output = service: name: "${prefix}/${service.name}/${name}";
inherit (lib.attrsets) mapAttrsRecursive collect;
inherit (lib.strings) concatStringsSep;
serviceScript = commands: '' serviceScript = commands: ''
#!/bin/sh #!/bin/sh
exec 2>&1 exec 2>&1
@ -40,7 +38,6 @@ let
buildInputs ? [ ], buildInputs ? [ ],
restart-on-upgrade ? false, restart-on-upgrade ? false,
controller ? null, controller ? null,
properties ? {}
}: }:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names # we use stdenvNoCC to avoid generating derivations with names
@ -59,13 +56,7 @@ let
timeout-up timeout-up
timeout-down timeout-down
restart-on-upgrade restart-on-upgrade
; ;
propertiesText =
let a = mapAttrsRecursive
(path: value: "writepath ${concatStringsSep "/" path} ${builtins.toString value}\n")
properties;
in collect builtins.isString a;
buildInputs = buildInputs =
buildInputs ++ dependencies ++ contents ++ lib.optional (controller != null) controller; buildInputs ++ dependencies ++ contents ++ lib.optional (controller != null) controller;
inherit controller dependencies contents; inherit controller dependencies contents;

View File

@ -28,7 +28,7 @@
: ipairs : ipairs
:output :output
(fn [service-path path default] (fn [service-path path default]
(let [s (assert (svc.open service-path))] (let [s (assert (svc.open (.. service-path "/.outputs")))]
(or (s:output path) default))) (or (s:output path) default)))
:lua_quote #(string.format "%q" $1) :lua_quote #(string.format "%q" $1)
:json_quote (fn [x] (.. "\"" (json-escape x) "\"")) :json_quote (fn [x] (.. "\"" (json-escape x) "\""))

View File

@ -71,7 +71,7 @@
(fn open-services [output-references] (fn open-services [output-references]
(collect [s p (pairs output-references)] (collect [s p (pairs output-references)]
(values (svc.open s) p))) (values (svc.open (.. s "/.outputs")) p)))
(fn run [] (fn run []
(let [trees {} (let [trees {}

View File

@ -50,7 +50,8 @@
(fn run [] (fn run []
(let [{: out-path : watched-service : path } (parse-args arg) (let [{: out-path : watched-service : path } (parse-args arg)
service (assert (svc.open watched-service))] dir (.. watched-service "/.outputs")
service (assert (svc.open dir))]
(accumulate [tree {} (accumulate [tree {}
v (service:events)] v (service:events)]
(write-changes out-path tree (or (service:output path) {}))))) (write-changes out-path tree (or (service:output path) {})))))