subscriber.nix (1398B)
1 { 2 liminix, 3 lib, 4 lim, 5 s6, 6 s6-rc, 7 watch-outputs, 8 s6-rc-up-tree 9 }: 10 { 11 watch, 12 service, 13 action, 14 }: 15 let 16 inherit (liminix.services) oneshot longrun; 17 inherit (builtins) map length head toString; 18 inherit (lib) unique optional optionals concatStringsSep; 19 inherit (service) name; 20 21 watched-services = unique (map (f: f "service") watch); 22 23 restart-flag = 24 { 25 restart = "-r"; 26 restart-all = "-R"; 27 "hup" = "-s 1"; 28 "int" = "-s 2"; 29 "quit" = "-s 3"; 30 "kill" = "-s 9"; 31 "term" = "-s 15"; 32 "winch" = "-s 20"; 33 "usr1" = "-s usr1"; 34 "usr2" = "-s usr2"; 35 } 36 .${action}; 37 38 watcher = 39 let 40 name' = "restart-${name}"; 41 refs = concatStringsSep " " 42 (map (s: "${s "service"}:${s "path"}") watch); 43 in 44 longrun { 45 name = name'; 46 run = '' 47 dir=/run/service/${name} 48 echo waiting for $dir 49 if test -e $dir/notification-fd; then flag="-U"; else flag="-u"; fi 50 ${s6}/bin/s6-svwait $flag /run/service/${name} || exit 51 PATH=${s6-rc}/bin:${s6}/bin:${s6-rc-up-tree}/bin:$PATH 52 ${watch-outputs}/bin/watch-outputs ${restart-flag} ${name} ${refs} 53 ''; 54 }; 55 in 56 service.overrideAttrs (o: { 57 buildInputs = (lim.orEmpty o.buildInputs) ++ optional (watch != []) watcher; 58 dependencies = 59 (lim.orEmpty o.dependencies) 60 ++ optional (watch != []) watcher; 61 })