liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c3f550698de2951208ec74e96ae085548cae3079
parent 05991225de57c2441a434142c4a35bc6eddd12fa
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 25 Mar 2025 23:44:21 +0000

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

Diffstat:
Mpkgs/watch-outputs/watch-outputs.fnl | 24++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/pkgs/watch-outputs/watch-outputs.fnl b/pkgs/watch-outputs/watch-outputs.fnl @@ -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)))) +