1
0

watch-outputs fix update logic

it was only working by accident, when it worked, which was by no
means all of the time

note that we unconditionally perform the action (restart or whatever)
once we've started and got the initial state of the outputs. That's
because we have no idea whether the outputs changed in the interval
between the controlled service initially starting and watch-outputs
starting, so updates in that interval could be lost
This commit is contained in:
Daniel Barlow 2025-03-25 23:44:21 +00:00
parent 05991225de
commit c3f550698d

View File

@ -38,7 +38,6 @@
"/nix/store/s2" [["out1"] ["out2" "ifname"]]}}
))
(fn changed? [paths old-tree new-tree]
(accumulate [changed? false
_ path (ipairs paths)]
@ -52,8 +51,6 @@
(expect (not (changed? [["mtu"]] {:ifname "true"} {:ifname "false"})))
)
(fn do-action [action service]
(case action
:restart (system (%% "s6-svc -r /run/service/%s" service))
@ -80,16 +77,19 @@
: controlled-service
: action
: watched-service
: paths } (parse-args arg)]
: paths } (parse-args arg)
services (open-services output-references)]
(while true
(let [services (open-services output-references)
trees (collect [s _ (pairs services)]
(values s (s:output ".")))]
(wait-for-change services)
(each [service paths (pairs services)]
(let [new-tree (service:output ".")]
(when (changed? paths (. trees service) new-tree)
(do-action action controlled-service))))))))
(when
(accumulate [changed false
service paths (pairs services)]
(let [new-tree (service:output ".")]
(if (changed? paths (or (. trees service) {}) new-tree)
(do (tset trees service new-tree) true)
changed)))
(do-action action controlled-service))
(wait-for-change services))))