refactor: modules/users/s6-rc.nix
This commit is contained in:
parent
40f6f88a64
commit
d4f217a4f5
|
@ -6,65 +6,61 @@ let
|
|||
# infers the service type from the arguments and dispatches appropriately
|
||||
genService = { name, run, finish, depends }: let
|
||||
name' = normalizeName name;
|
||||
runFile = pkgs.writeTextFile {
|
||||
name = "s6-${name'}-run";
|
||||
destination = "/${name'}/run";
|
||||
executable = true;
|
||||
# TODO: consider using `makeWrapper`/`makeBinaryWrapper`?
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
echo "starting: s6-${name'}"
|
||||
${run} 2>&1
|
||||
'';
|
||||
};
|
||||
finishFile = pkgs.writeTextFile {
|
||||
# TODO: use 'writeShellScript'?
|
||||
name = "s6-${name'}-finish";
|
||||
destination = "/${name'}/finish";
|
||||
executable = true;
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
${finish}
|
||||
'';
|
||||
};
|
||||
in if run != null then
|
||||
genService' name' "longrun" depends (
|
||||
[ runFile ]
|
||||
++ lib.optionals (finish != null) [ finishFile ]
|
||||
)
|
||||
else
|
||||
type = if run != null then "longrun" else "bundle";
|
||||
in genService' {
|
||||
name = name';
|
||||
inherit type;
|
||||
# TODO: a bundle can totally have dependencies. i can't just map them *all* to contents.
|
||||
# genService' (normalizeName name) "bundle" [] (
|
||||
# (builtins.map
|
||||
# (d: pkgs.writeTextFile {
|
||||
# name = "s6-${name}-contains-${d}";
|
||||
# destination = "/${normalizeName name}/contents.d/${normalizeName d}";
|
||||
# text = "";
|
||||
# })
|
||||
# depends
|
||||
# ) ++ [
|
||||
# # in case the bundle has no contents, ensure `contents.d` still gets made
|
||||
# (pkgs.runCommandLocal "s6-${name}-contains.d" {} ''
|
||||
# mkdir -p $out/"${normalizeName name}"/contents.d
|
||||
# '')
|
||||
# ]
|
||||
# )
|
||||
genService' name' "bundle" [] [
|
||||
(pkgs.writeTextFile {
|
||||
name = "s6-${name'}-contents";
|
||||
destination = "/${name'}/contents";
|
||||
text = lib.concatStringsSep "\n" (builtins.map normalizeName depends);
|
||||
})
|
||||
]
|
||||
;
|
||||
genService' = name: type: depends: others: pkgs.symlinkJoin {
|
||||
depends = lib.optionals (type == "longrun") depends;
|
||||
finish = finish;
|
||||
longrun-run = run;
|
||||
bundle-contents = lib.optionals (type == "bundle") depends;
|
||||
};
|
||||
|
||||
genService' = {
|
||||
name,
|
||||
type,
|
||||
depends,
|
||||
finish,
|
||||
longrun-run,
|
||||
bundle-contents,
|
||||
}: pkgs.symlinkJoin {
|
||||
name = "s6-${name}";
|
||||
paths = others ++ [
|
||||
paths = [
|
||||
(pkgs.writeTextFile {
|
||||
name = "s6-${name}-type";
|
||||
destination = "/${name}/type";
|
||||
text = type;
|
||||
})
|
||||
] ++ lib.optionals (finish != null) [
|
||||
(pkgs.writeTextFile {
|
||||
# TODO: use 'writeShellScript'?
|
||||
name = "s6-${name}-finish";
|
||||
destination = "/${name}/finish";
|
||||
executable = true;
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
${finish}
|
||||
'';
|
||||
})
|
||||
] ++ lib.optionals (longrun-run != null) [
|
||||
(pkgs.writeTextFile {
|
||||
name = "s6-${name}-run";
|
||||
destination = "/${name}/run";
|
||||
executable = true;
|
||||
# TODO: consider using `makeWrapper`/`makeBinaryWrapper`?
|
||||
text = ''
|
||||
#!/bin/sh
|
||||
echo "starting: s6-${name}"
|
||||
${longrun-run} 2>&1
|
||||
'';
|
||||
})
|
||||
] ++ lib.optionals (bundle-contents != null) [
|
||||
(pkgs.writeTextFile {
|
||||
name = "s6-${name}-contents";
|
||||
destination = "/${name}/contents";
|
||||
text = lib.concatStringsSep "\n" (builtins.map normalizeName bundle-contents);
|
||||
})
|
||||
] ++ builtins.map
|
||||
(d: pkgs.writeTextFile {
|
||||
name = "s6-${name}-depends-${d}";
|
||||
|
@ -132,11 +128,13 @@ let
|
|||
implicitServices = {
|
||||
"default.target" = {
|
||||
serviceConfig.ExecStart = null;
|
||||
serviceConfig.ExecStopPost = null;
|
||||
wants = [];
|
||||
wantedBy = [];
|
||||
};
|
||||
"graphical-session.target" = {
|
||||
serviceConfig.ExecStart = null;
|
||||
serviceConfig.ExecStopPost = null;
|
||||
wants = [];
|
||||
wantedBy = [];
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user