systemd: handle non-Linux systems better
This commit causes an error to be printed if running under a non-Linux system when a systemd service, target, or timer is active. It will also prevent running systemd during activation if running under a non-Linux system.
This commit is contained in:
parent
1a491f24f7
commit
f60a1ed689
|
@ -5,6 +5,10 @@ with import ./lib/dag.nix;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
cfg = config.systemd.user;
|
||||||
|
|
||||||
|
enabled = cfg.services != {} || cfg.targets != {} || cfg.timers != {};
|
||||||
|
|
||||||
toSystemdIni = (import lib/generators.nix).toINI {
|
toSystemdIni = (import lib/generators.nix).toINI {
|
||||||
mkKeyValue = key: value:
|
mkKeyValue = key: value:
|
||||||
let
|
let
|
||||||
|
@ -60,14 +64,32 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = mkMerge [
|
||||||
|
{
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = enabled -> pkgs.stdenv.isLinux;
|
||||||
|
message =
|
||||||
|
let
|
||||||
|
names = concatStringsSep ", " (
|
||||||
|
attrNames (cfg.services // cfg.targets // cfg.timers)
|
||||||
|
);
|
||||||
|
in
|
||||||
|
"Must use Linux for modules that require systemd: " + names;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
# If we run under a Linux system we assume that systemd is
|
||||||
|
# available, in particular we assume that systemctl is in PATH.
|
||||||
|
(mkIf pkgs.stdenv.isLinux {
|
||||||
home.file =
|
home.file =
|
||||||
listToAttrs (
|
listToAttrs (
|
||||||
(buildServices "service" config.systemd.user.services)
|
(buildServices "service" cfg.services)
|
||||||
++
|
++
|
||||||
(buildServices "target" config.systemd.user.targets)
|
(buildServices "target" cfg.targets)
|
||||||
++
|
++
|
||||||
(buildServices "timer" config.systemd.user.timers)
|
(buildServices "timer" cfg.timers)
|
||||||
);
|
);
|
||||||
|
|
||||||
home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] ''
|
home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] ''
|
||||||
|
@ -153,5 +175,6 @@ in
|
||||||
$DRY_RUN_CMD systemctl --user daemon-reload
|
$DRY_RUN_CMD systemctl --user daemon-reload
|
||||||
systemdPostReload
|
systemdPostReload
|
||||||
'';
|
'';
|
||||||
};
|
})
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue