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