systemd module: add option to specify generators

Adding the configuration option 'systemd.generators' to
specify systemd system-generators. The option allows to
either add new system-generators to systemd, or to over-
ride or disable the system-generators provided by systemd.

Internally, the configuration option 'systemd.generators'
maps onto the 'environment.etc' configuration option.
Having a convenience wrapper around 'environment.etc' helps
to group the systemd system-generator configuration more
easily with other 'systemd...' configurations.
This commit is contained in:
Thomas Strobel 2015-09-26 18:34:36 +02:00
parent 3f27be8e5d
commit 05c46bfc05

View File

@ -445,6 +445,17 @@ in
''; '';
}; };
systemd.generators = mkOption {
type = types.attrsOf types.path;
default = {};
example = { "systemd-gpt-auto-generator" = "/dev/null"; };
description = ''
Definition of systemd generators.
For each <literal>NAME = VALUE</literal> pair of the attrSet, a link is generated from
<literal>/etc/systemd/system-generators/NAME</literal> to <literal>VALUE</literal>.
'';
};
systemd.defaultUnit = mkOption { systemd.defaultUnit = mkOption {
default = "multi-user.target"; default = "multi-user.target";
type = types.str; type = types.str;
@ -601,20 +612,17 @@ in
environment.systemPackages = [ systemd ]; environment.systemPackages = [ systemd ];
environment.etc."systemd/system".source = environment.etc = {
generateUnits "system" cfg.units upstreamSystemUnits upstreamSystemWants; "systemd/system".source = generateUnits "system" cfg.units upstreamSystemUnits upstreamSystemWants;
environment.etc."systemd/user".source = "systemd/user".source = generateUnits "user" cfg.user.units upstreamUserUnits [];
generateUnits "user" cfg.user.units upstreamUserUnits [];
environment.etc."systemd/system.conf".text = "systemd/system.conf".text = ''
''
[Manager] [Manager]
${config.systemd.extraConfig} ${config.systemd.extraConfig}
''; '';
environment.etc."systemd/journald.conf".text = "systemd/journald.conf".text = ''
''
[Journal] [Journal]
RateLimitInterval=${config.services.journald.rateLimitInterval} RateLimitInterval=${config.services.journald.rateLimitInterval}
RateLimitBurst=${toString config.services.journald.rateLimitBurst} RateLimitBurst=${toString config.services.journald.rateLimitBurst}
@ -625,17 +633,26 @@ in
${config.services.journald.extraConfig} ${config.services.journald.extraConfig}
''; '';
environment.etc."systemd/logind.conf".text = "systemd/logind.conf".text = ''
''
[Login] [Login]
${config.services.logind.extraConfig} ${config.services.logind.extraConfig}
''; '';
environment.etc."systemd/sleep.conf".text = "systemd/sleep.conf".text = ''
''
[Sleep] [Sleep]
''; '';
"tmpfiles.d/systemd.conf".source = "${systemd}/example/tmpfiles.d/systemd.conf";
"tmpfiles.d/x11.conf".source = "${systemd}/example/tmpfiles.d/x11.conf";
"tmpfiles.d/nixos.conf".text = ''
# This file is created automatically and should not be modified.
# Please change the option systemd.tmpfiles.rules instead.
${concatStringsSep "\n" cfg.tmpfiles.rules}
'';
} // mapAttrs' (n: v: nameValuePair "systemd/system-generators/${n}" {"source"=v;}) cfg.generators;
system.activationScripts.systemd = stringAfter [ "groups" ] system.activationScripts.systemd = stringAfter [ "groups" ]
'' ''
mkdir -m 0755 -p /var/lib/udev mkdir -m 0755 -p /var/lib/udev
@ -736,17 +753,6 @@ in
startSession = true; startSession = true;
}; };
environment.etc."tmpfiles.d/systemd.conf".source = "${systemd}/example/tmpfiles.d/systemd.conf";
environment.etc."tmpfiles.d/x11.conf".source = "${systemd}/example/tmpfiles.d/x11.conf";
environment.etc."tmpfiles.d/nixos.conf".text =
''
# This file is created automatically and should not be modified.
# Please change the option systemd.tmpfiles.rules instead.
${concatStringsSep "\n" cfg.tmpfiles.rules}
'';
# Some overrides to upstream units. # Some overrides to upstream units.
systemd.services."systemd-backlight@".restartIfChanged = false; systemd.services."systemd-backlight@".restartIfChanged = false;
systemd.services."systemd-rfkill@".restartIfChanged = false; systemd.services."systemd-rfkill@".restartIfChanged = false;