add s6-rc-up-tree: start reverse deps of controlled service

When s6-rc stops a service, it also stops everything that
depends on it. but when it starts a service it starts only
that service, so we have to go through the other services
depending on it and figure out if they should be started too.
This commit is contained in:
Daniel Barlow
2024-06-15 14:59:34 +01:00
parent 1d337588f9
commit 49d1703428
8 changed files with 60 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ let
stdenvNoCC;
inherit (lib.lists) unique concatMap;
inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs.liminix.services) bundle;
inherit (pkgs.liminix.services) oneshot bundle;
s6-rc-db =
let
@@ -31,12 +31,25 @@ let
isControlled s ||
(lib.lists.any isDependentOnControlled s.dependencies);
# all controlled services depend on this oneshot, which
# makes a list of them so we can identify them at runtime
controlled = oneshot {
name = "controlled";
up = ''
mkdir -p /run/services/controlled
for s in $(s6-rc-db -d dependencies controlled); do
touch /run/services/controlled/$s
done
'';
down = "rm -r /run/services/controlled";
};
defaultStart =
builtins.filter
(s: !(isDependentOnControlled s)) allServices;
defaultDefaultTarget = bundle {
name = "default";
contents = defaultStart;
contents = defaultStart ++ [controlled];
};
servicesAttrs = {
default = defaultDefaultTarget;