1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-09-30 02:07:28 +02:00

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:
Robert Helgesson 2017-05-15 23:53:49 +02:00
parent 1a491f24f7
commit f60a1ed689
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -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
''; '';
}; })
];
} }