systemd: remove platform assertion

Allow modules to define systemd services on macOS. It won't actually
have any effect, but it would allow modules to define both systemd
services and launchd agents without boilerplate conditionals.

As a consequence of this change, each module would have to check for
compatibility with the OS target instead.
This commit is contained in:
midchildan 2022-04-24 23:26:25 +09:00 committed by Robert Helgesson
parent 17dc593930
commit edb3645383
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -10,16 +10,6 @@ let
mkPathSafeName = mkPathSafeName =
lib.replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ]; lib.replaceStrings [ "@" ":" "\\" "[" "]" ] [ "-" "-" "-" "" "" ];
enabled = cfg.services != { } # \
|| cfg.slices != { } # \
|| cfg.sockets != { } # \
|| cfg.targets != { } # \
|| cfg.timers != { } # \
|| cfg.paths != { } # \
|| cfg.mounts != { } # \
|| cfg.automounts != { } # \
|| cfg.sessionVariables != { };
toSystemdIni = lib.generators.toINI { toSystemdIni = lib.generators.toINI {
listsAsDuplicateKeys = true; listsAsDuplicateKeys = true;
mkKeyValue = key: value: mkKeyValue = key: value:
@ -239,28 +229,10 @@ in {
}; };
}; };
config = mkMerge [
{
assertions = [{
assertion = enabled -> pkgs.stdenv.isLinux;
message = let
names = lib.concatStringsSep ", " (lib.attrNames ( # \
cfg.services # \
// cfg.slices # \
// cfg.sockets # \
// cfg.targets # \
// cfg.timers # \
// cfg.paths # \
// cfg.mounts # \
// cfg.sessionVariables));
in "Must use Linux for modules that require systemd: " + names;
}];
}
# If we run under a Linux system we assume that systemd is # If we run under a Linux system we assume that systemd is
# available, in particular we assume that systemctl is in PATH. # available, in particular we assume that systemctl is in PATH.
# Do not install any user services if username is root. # Do not install any user services if username is root.
(mkIf (pkgs.stdenv.isLinux && config.home.username != "root") { config = mkIf (pkgs.stdenv.isLinux && config.home.username != "root") {
xdg.configFile = mkMerge [ xdg.configFile = mkMerge [
(lib.listToAttrs ((buildServices "service" cfg.services) (lib.listToAttrs ((buildServices "service" cfg.services)
++ (buildServices "slice" cfg.slices) ++ (buildServices "slice" cfg.slices)
@ -278,8 +250,7 @@ in {
# running this from the NixOS module then XDG_RUNTIME_DIR is not # running this from the NixOS module then XDG_RUNTIME_DIR is not
# set and systemd commands will fail. We'll therefore have to # set and systemd commands will fail. We'll therefore have to
# set it ourselves in that case. # set it ourselves in that case.
home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ] home.activation.reloadSystemd = hm.dag.entryAfter [ "linkGeneration" ] (let
(let
cmd = { cmd = {
suggest = '' suggest = ''
PATH=${dirOf cfg.systemctlPath}:$PATH \ PATH=${dirOf cfg.systemctlPath}:$PATH \
@ -325,6 +296,5 @@ in {
unset systemdStatus unset systemdStatus
''); '');
}) };
];
} }