nixos/systemd-lib: Use module composition

This commit is contained in:
Janne Heß 2022-04-01 09:39:56 +02:00
parent fc91cdb5bc
commit 1e5261f31c
No known key found for this signature in database
GPG Key ID: 69165158F05265DF
2 changed files with 21 additions and 19 deletions

View File

@ -291,49 +291,51 @@ in rec {
};
};
mkServiceConfig = path: { name, config, ... }: {
serviceConfig = { name, config, ... }: {
config = mkMerge
[ {
path = mkAfter path;
environment.PATH = mkIf (config.path != []) "${makeBinPath config.path}:${makeSearchPathOutput "bin" "sbin" config.path}";
}
(mkIf (config.preStart != "")
(mkIf (config ? preStart && config.preStart != "")
{ serviceConfig.ExecStartPre =
[ (makeJobScript "${name}-pre-start" config.preStart) ];
})
(mkIf (config.script != "")
(mkIf (config ? script && config.script != "")
{ serviceConfig.ExecStart =
makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
})
(mkIf (config.postStart != "")
(mkIf (config ? postStart && config.postStart != "")
{ serviceConfig.ExecStartPost =
[ (makeJobScript "${name}-post-start" config.postStart) ];
})
(mkIf (config.reload != "")
(mkIf (config ? reload && config.reload != "")
{ serviceConfig.ExecReload =
makeJobScript "${name}-reload" config.reload;
})
(mkIf (config.preStop != "")
(mkIf (config ? preStop && config.preStop != "")
{ serviceConfig.ExecStop =
makeJobScript "${name}-pre-stop" config.preStop;
})
(mkIf (config.postStop != "")
(mkIf (config ? postStart && config.postStop != "")
{ serviceConfig.ExecStopPost =
makeJobScript "${name}-post-stop" config.postStop;
})
];
};
# Default path for systemd services. Should be quite minimal.
serviceConfig = mkServiceConfig [
pkgs.coreutils
pkgs.findutils
pkgs.gnugrep
pkgs.gnused
systemd
];
stage2ServiceConfig = {
imports = [ serviceConfig ];
# Default path for systemd services. Should be quite minimal.
config.path = mkAfter [
pkgs.coreutils
pkgs.findutils
pkgs.gnugrep
pkgs.gnused
systemd
];
};
initrdServiceConfig = mkServiceConfig [];
stage1ServiceConfig = serviceConfig;
mountConfig = { config, ... }: {
config = {

View File

@ -11,8 +11,8 @@ rec {
config = { unit = mkDefault (systemdUtils.lib.makeUnit name config); };
}));
services = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ]);
initrdServices = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig initrdServiceConfig ]);
services = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig stage2ServiceConfig ]);
initrdServices = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig stage1ServiceConfig ]);
targets = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig ]);