2025-04-01 20:10:43 +02:00
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
utils,
|
|
|
|
|
...
|
|
|
|
|
}:
|
2012-06-01 20:15:07 -04:00
|
|
|
|
|
2013-01-01 14:42:43 +01:00
|
|
|
|
with utils;
|
2021-11-20 12:34:13 -05:00
|
|
|
|
with systemdUtils.unitOptions;
|
2014-05-05 15:52:33 -04:00
|
|
|
|
with lib;
|
2012-06-01 20:15:07 -04:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
cfg = config.systemd;
|
2012-06-17 23:31:21 -04:00
|
|
|
|
|
2022-03-13 16:09:36 +01:00
|
|
|
|
inherit (systemdUtils.lib)
|
2022-03-13 16:11:28 +01:00
|
|
|
|
generateUnits
|
2022-03-13 16:09:36 +01:00
|
|
|
|
targetToUnit
|
|
|
|
|
serviceToUnit
|
|
|
|
|
socketToUnit
|
|
|
|
|
timerToUnit
|
|
|
|
|
pathToUnit
|
|
|
|
|
mountToUnit
|
|
|
|
|
automountToUnit
|
2025-04-01 20:10:43 +02:00
|
|
|
|
sliceToUnit
|
|
|
|
|
;
|
2022-03-13 16:09:36 +01:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
upstreamSystemUnits =
|
2025-04-01 20:10:43 +02:00
|
|
|
|
[
|
|
|
|
|
# Targets.
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"basic.target"
|
2013-01-08 17:26:51 +01:00
|
|
|
|
"sysinit.target"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"sockets.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"exit.target"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"graphical.target"
|
|
|
|
|
"multi-user.target"
|
|
|
|
|
"network.target"
|
2014-12-01 17:19:06 -08:00
|
|
|
|
"network-pre.target"
|
2013-07-16 11:55:12 +02:00
|
|
|
|
"network-online.target"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"nss-lookup.target"
|
|
|
|
|
"nss-user-lookup.target"
|
|
|
|
|
"time-sync.target"
|
2024-07-15 21:37:24 -07:00
|
|
|
|
"first-boot-complete.target"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withCryptsetup [
|
2019-08-19 02:08:46 +02:00
|
|
|
|
"cryptsetup.target"
|
2021-10-22 15:01:55 +02:00
|
|
|
|
"cryptsetup-pre.target"
|
|
|
|
|
"remote-cryptsetup.target"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ [
|
2012-08-14 18:14:48 -04:00
|
|
|
|
"sigpwr.target"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"timers.target"
|
|
|
|
|
"paths.target"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
"rpcbind.target"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2013-01-21 21:01:48 +01:00
|
|
|
|
# Rescue mode.
|
2013-01-08 18:24:06 +01:00
|
|
|
|
"rescue.target"
|
|
|
|
|
"rescue.service"
|
|
|
|
|
|
2024-03-28 05:50:01 -04:00
|
|
|
|
# systemd-debug-generator
|
|
|
|
|
"debug-shell.service"
|
|
|
|
|
|
2012-06-15 13:09:22 -04:00
|
|
|
|
# Udev.
|
2012-07-16 17:47:11 -04:00
|
|
|
|
"systemd-udevd-control.socket"
|
|
|
|
|
"systemd-udevd-kernel.socket"
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"systemd-udevd.service"
|
2012-06-15 13:09:22 -04:00
|
|
|
|
"systemd-udev-settle.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ (optional (!config.boot.isContainer) "systemd-udev-trigger.service")
|
|
|
|
|
++ [
|
2017-02-08 21:42:07 +03:00
|
|
|
|
# hwdb.bin is managed by NixOS
|
|
|
|
|
# "systemd-hwdb-update.service"
|
2012-06-15 13:09:22 -04:00
|
|
|
|
|
2012-08-14 18:14:48 -04:00
|
|
|
|
# Hardware (started by udev when a relevant device is plugged in).
|
|
|
|
|
"sound.target"
|
|
|
|
|
"bluetooth.target"
|
|
|
|
|
"printer.target"
|
|
|
|
|
"smartcard.target"
|
|
|
|
|
|
2012-08-06 16:52:08 -04:00
|
|
|
|
# Kernel module loading.
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"systemd-modules-load.service"
|
|
|
|
|
"kmod-static-nodes.service"
|
2021-03-04 15:05:16 -05:00
|
|
|
|
"modprobe@.service"
|
2012-08-06 16:52:08 -04:00
|
|
|
|
|
2012-06-01 20:15:07 -04:00
|
|
|
|
# Filesystems.
|
2012-07-16 17:47:11 -04:00
|
|
|
|
"systemd-fsck@.service"
|
|
|
|
|
"systemd-fsck-root.service"
|
2023-03-05 20:05:00 +01:00
|
|
|
|
"systemd-growfs@.service"
|
|
|
|
|
"systemd-growfs-root.service"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"systemd-remount-fs.service"
|
2020-12-02 00:54:35 +01:00
|
|
|
|
"systemd-pstore.service"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"local-fs.target"
|
|
|
|
|
"local-fs-pre.target"
|
|
|
|
|
"remote-fs.target"
|
|
|
|
|
"remote-fs-pre.target"
|
|
|
|
|
"swap.target"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"dev-hugepages.mount"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"dev-mqueue.mount"
|
2014-04-28 09:13:57 +02:00
|
|
|
|
"sys-fs-fuse-connections.mount"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ (optional (!config.boot.isContainer) "sys-kernel-config.mount")
|
|
|
|
|
++ [
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"sys-kernel-debug.mount"
|
2025-03-10 22:27:41 +05:30
|
|
|
|
"sys-kernel-tracing.mount"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2014-04-16 00:59:26 +02:00
|
|
|
|
# Maintaining state across reboots.
|
|
|
|
|
"systemd-random-seed.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ (optional cfg.package.withBootloader "systemd-boot-random-seed.service")
|
|
|
|
|
++ [
|
2014-04-18 19:37:15 +02:00
|
|
|
|
"systemd-backlight@.service"
|
2015-10-07 21:48:30 +02:00
|
|
|
|
"systemd-rfkill.service"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"systemd-rfkill.socket"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
|
2012-06-14 18:44:56 -04:00
|
|
|
|
# Hibernate / suspend.
|
|
|
|
|
"hibernate.target"
|
|
|
|
|
"suspend.target"
|
2019-08-26 11:04:10 +02:00
|
|
|
|
"suspend-then-hibernate.target"
|
2012-06-14 18:44:56 -04:00
|
|
|
|
"sleep.target"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"hybrid-sleep.target"
|
2012-07-20 15:40:50 -04:00
|
|
|
|
"systemd-hibernate.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ (lib.optional cfg.package.withEfi "systemd-hibernate-clear.service")
|
|
|
|
|
++ [
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"systemd-hybrid-sleep.service"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"systemd-suspend.service"
|
2019-08-26 11:04:10 +02:00
|
|
|
|
"systemd-suspend-then-hibernate.service"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
|
|
|
|
|
# Reboot stuff.
|
|
|
|
|
"reboot.target"
|
2012-07-16 17:47:11 -04:00
|
|
|
|
"systemd-reboot.service"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"poweroff.target"
|
2012-07-16 17:47:11 -04:00
|
|
|
|
"systemd-poweroff.service"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"halt.target"
|
2012-07-16 17:47:11 -04:00
|
|
|
|
"systemd-halt.service"
|
2012-06-01 20:15:07 -04:00
|
|
|
|
"shutdown.target"
|
|
|
|
|
"umount.target"
|
|
|
|
|
"final.target"
|
2012-08-14 18:14:48 -04:00
|
|
|
|
"kexec.target"
|
2013-09-16 17:15:42 +02:00
|
|
|
|
"systemd-kexec.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ lib.optional cfg.package.withUtmp "systemd-update-utmp.service"
|
|
|
|
|
++ [
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2012-06-19 17:02:54 -04:00
|
|
|
|
# Password entry.
|
|
|
|
|
"systemd-ask-password-console.path"
|
|
|
|
|
"systemd-ask-password-console.service"
|
|
|
|
|
"systemd-ask-password-wall.path"
|
|
|
|
|
"systemd-ask-password-wall.service"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
|
2024-04-26 23:18:12 +02:00
|
|
|
|
# Varlink APIs
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ lib.optionals cfg.package.withBootloader [
|
2024-04-26 23:18:12 +02:00
|
|
|
|
"systemd-bootctl@.service"
|
|
|
|
|
"systemd-bootctl.socket"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ [
|
2024-04-26 23:18:12 +02:00
|
|
|
|
"systemd-creds@.service"
|
|
|
|
|
"systemd-creds.socket"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ lib.optional cfg.package.withTpm2Units [
|
2024-04-26 23:18:12 +02:00
|
|
|
|
"systemd-pcrlock@.service"
|
|
|
|
|
"systemd-pcrlock.socket"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ [
|
2024-04-26 23:18:12 +02:00
|
|
|
|
|
2014-04-16 00:59:26 +02:00
|
|
|
|
# Slices / containers.
|
|
|
|
|
"slices.target"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withImportd [
|
2022-05-10 19:01:48 +02:00
|
|
|
|
"systemd-importd.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withMachined [
|
2014-04-16 00:59:26 +02:00
|
|
|
|
"machine.slice"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"machines.target"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
"systemd-machined.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ [
|
2016-06-09 15:45:55 +02:00
|
|
|
|
"systemd-nspawn@.service"
|
2014-04-17 13:23:06 +02:00
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Misc.
|
|
|
|
|
"systemd-sysctl.service"
|
2024-10-25 14:00:41 +02:00
|
|
|
|
"systemd-machine-id-commit.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withTimedated [
|
2015-12-06 14:30:18 +01:00
|
|
|
|
"dbus-org.freedesktop.timedate1.service"
|
|
|
|
|
"systemd-timedated.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withLocaled [
|
2022-05-10 19:01:48 +02:00
|
|
|
|
"dbus-org.freedesktop.locale1.service"
|
2015-12-06 14:30:18 +01:00
|
|
|
|
"systemd-localed.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withHostnamed [
|
2022-05-10 19:01:48 +02:00
|
|
|
|
"dbus-org.freedesktop.hostname1.service"
|
2015-12-06 14:30:18 +01:00
|
|
|
|
"systemd-hostnamed.service"
|
2024-04-26 23:18:12 +02:00
|
|
|
|
"systemd-hostnamed.socket"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ optionals cfg.package.withPortabled [
|
2022-09-29 12:36:05 +02:00
|
|
|
|
"dbus-org.freedesktop.portable1.service"
|
|
|
|
|
"systemd-portabled.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ [
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"systemd-exit.service"
|
2018-02-11 23:43:24 +01:00
|
|
|
|
"systemd-update-done.service"
|
2025-04-01 20:10:43 +02:00
|
|
|
|
]
|
|
|
|
|
++ cfg.additionalUpstreamSystemUnits;
|
|
|
|
|
|
|
|
|
|
upstreamSystemWants = [
|
|
|
|
|
"sysinit.target.wants"
|
|
|
|
|
"sockets.target.wants"
|
|
|
|
|
"local-fs.target.wants"
|
|
|
|
|
"multi-user.target.wants"
|
|
|
|
|
"timers.target.wants"
|
|
|
|
|
];
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2019-12-11 09:34:35 +01:00
|
|
|
|
proxy_env = config.networking.proxy.envVars;
|
|
|
|
|
|
2012-06-01 20:15:07 -04:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
2012-06-14 18:44:56 -04:00
|
|
|
|
###### interface
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
options.systemd = {
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
package = mkPackageOption pkgs "systemd" { };
|
2013-01-16 13:17:57 +01:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
enableStrictShellChecks = mkEnableOption "" // {
|
2025-04-24 22:07:40 +08:00
|
|
|
|
description = ''
|
|
|
|
|
Whether to run `shellcheck` on the generated scripts for systemd
|
|
|
|
|
units.
|
|
|
|
|
|
|
|
|
|
When enabled, all systemd scripts generated by NixOS will be checked
|
|
|
|
|
with `shellcheck` and any errors or warnings will cause the build to
|
|
|
|
|
fail.
|
|
|
|
|
|
|
|
|
|
This affects all scripts that have been created through the `script`,
|
|
|
|
|
`reload`, `preStart`, `postStart`, `preStop` and `postStop` options for
|
|
|
|
|
systemd services. This does not affect command lines passed directly
|
|
|
|
|
to `ExecStart`, `ExecReload`, `ExecStartPre`, `ExecStartPost`,
|
|
|
|
|
`ExecStop` or `ExecStopPost`.
|
|
|
|
|
|
|
|
|
|
It therefore also does not affect systemd units that are coming from
|
|
|
|
|
packages and that are not defined through the NixOS config. This option
|
|
|
|
|
is disabled by default, and although some services have already been
|
|
|
|
|
fixed, it is still likely that you will encounter build failures when
|
|
|
|
|
enabling this.
|
|
|
|
|
|
|
|
|
|
We encourage people to enable this option when they are willing and
|
|
|
|
|
able to submit fixes for potential build failures to Nixpkgs. The
|
|
|
|
|
option can also be enabled or disabled for individual services using
|
|
|
|
|
the `enableStrictShellChecks` option on the service itself, which will
|
|
|
|
|
take precedence over the global setting.
|
|
|
|
|
'';
|
2025-04-01 20:10:43 +02:00
|
|
|
|
};
|
2023-11-30 10:54:09 +01:00
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
units = mkOption {
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd units; see {manpage}`systemd.unit(5)`.";
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.units;
|
2012-06-18 15:28:31 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
packages = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = [ ];
|
2012-08-21 11:28:47 -04:00
|
|
|
|
type = types.listOf types.package;
|
2021-10-03 18:06:03 +02:00
|
|
|
|
example = literalExpression "[ pkgs.systemd-cryptsetup-generator ]";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = "Packages providing systemd units and hooks.";
|
2012-08-21 11:28:47 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
targets = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.targets;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd target units; see {manpage}`systemd.target(5)`";
|
2012-10-01 18:58:11 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
services = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.services;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd service units; see {manpage}`systemd.service(5)`.";
|
2012-10-01 18:58:11 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
sockets = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.sockets;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd socket units; see {manpage}`systemd.socket(5)`.";
|
2012-06-14 18:44:56 -04:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
timers = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.timers;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd timer units; see {manpage}`systemd.timer(5)`.";
|
2013-03-02 01:03:13 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
paths = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.paths;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of systemd path units; see {manpage}`systemd.path(5)`.";
|
2014-03-31 12:23:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
mounts = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = [ ];
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.mounts;
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Definition of systemd mount units; see {manpage}`systemd.mount(5)`.
|
2023-11-21 17:11:01 +00:00
|
|
|
|
|
|
|
|
|
This is a list instead of an attrSet, because systemd mandates
|
|
|
|
|
the names to be derived from the `where` attribute.
|
2012-12-28 13:29:53 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
automounts = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = [ ];
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.automounts;
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Definition of systemd automount units; see {manpage}`systemd.automount(5)`.
|
|
|
|
|
|
|
|
|
|
This is a list instead of an attrSet, because systemd mandates
|
|
|
|
|
the names to be derived from the `where` attribute.
|
2013-09-23 22:56:05 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
slices = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2022-03-19 04:02:39 -04:00
|
|
|
|
type = systemdUtils.types.slices;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = "Definition of slice configurations; see {manpage}`systemd.slice(5)`.";
|
2016-12-20 09:21:52 +03:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
generators = mkOption {
|
2015-09-26 18:34:36 +02:00
|
|
|
|
type = types.attrsOf types.path;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
|
|
|
|
example = {
|
|
|
|
|
systemd-gpt-auto-generator = "/dev/null";
|
|
|
|
|
};
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Definition of systemd generators; see {manpage}`systemd.generator(5)`.
|
|
|
|
|
|
2022-07-20 12:32:04 +02:00
|
|
|
|
For each `NAME = VALUE` pair of the attrSet, a link is generated from
|
|
|
|
|
`/etc/systemd/system-generators/NAME` to `VALUE`.
|
2015-09-26 18:34:36 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
shutdown = mkOption {
|
2019-07-25 16:27:28 +03:00
|
|
|
|
type = types.attrsOf types.path;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
default = { };
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2019-07-25 16:27:28 +03:00
|
|
|
|
Definition of systemd shutdown executables.
|
2022-07-20 12:32:04 +02:00
|
|
|
|
For each `NAME = VALUE` pair of the attrSet, a link is generated from
|
|
|
|
|
`/etc/systemd/system-shutdown/NAME` to `VALUE`.
|
2019-07-25 16:27:28 +03:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
defaultUnit = mkOption {
|
2012-06-17 23:31:21 -04:00
|
|
|
|
default = "multi-user.target";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2023-11-21 17:10:23 +00:00
|
|
|
|
description = ''
|
|
|
|
|
Default unit started when the system boots; see {manpage}`systemd.special(7)`.
|
|
|
|
|
'';
|
2012-06-17 23:31:21 -04:00
|
|
|
|
};
|
2012-07-19 17:32:50 -04:00
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
ctrlAltDelUnit = mkOption {
|
2016-07-19 09:42:53 +02:00
|
|
|
|
default = "reboot.target";
|
|
|
|
|
type = types.str;
|
|
|
|
|
example = "poweroff.target";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Target that should be started when Ctrl-Alt-Delete is pressed;
|
|
|
|
|
see {manpage}`systemd.special(7)`.
|
2016-07-19 09:42:53 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
globalEnvironment = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
type =
|
|
|
|
|
with types;
|
|
|
|
|
attrsOf (
|
|
|
|
|
nullOr (oneOf [
|
|
|
|
|
str
|
|
|
|
|
path
|
|
|
|
|
package
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
default = { };
|
|
|
|
|
example = {
|
|
|
|
|
TZ = "CET";
|
|
|
|
|
};
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2022-07-20 12:32:04 +02:00
|
|
|
|
Environment variables passed to *all* systemd units.
|
2012-10-30 17:27:14 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
managerEnvironment = mkOption {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
type =
|
|
|
|
|
with types;
|
|
|
|
|
attrsOf (
|
|
|
|
|
nullOr (oneOf [
|
|
|
|
|
str
|
|
|
|
|
path
|
|
|
|
|
package
|
|
|
|
|
])
|
|
|
|
|
);
|
|
|
|
|
default = { };
|
|
|
|
|
example = {
|
|
|
|
|
SYSTEMD_LOG_LEVEL = "debug";
|
|
|
|
|
};
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2022-03-23 15:56:23 +01:00
|
|
|
|
Environment variables of PID 1. These variables are
|
2022-07-20 12:32:04 +02:00
|
|
|
|
*not* passed to started units.
|
2022-03-23 15:56:23 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
enableCgroupAccounting = mkOption {
|
2019-08-19 17:50:29 +02:00
|
|
|
|
default = true;
|
2018-03-10 22:23:42 +01:00
|
|
|
|
type = types.bool;
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Whether to enable cgroup accounting; see {manpage}`cgroups(7)`.
|
2018-03-10 22:23:42 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
extraConfig = mkOption {
|
2013-11-15 19:49:01 +01:00
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "DefaultLimitCORE=infinity";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:10:23 +00:00
|
|
|
|
Extra config options for systemd. See {manpage}`systemd-system.conf(5)` man page
|
2022-10-03 11:10:46 +08:00
|
|
|
|
for available options.
|
2013-11-15 19:49:01 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
sleep.extraConfig = mkOption {
|
2020-02-03 18:31:46 +02:00
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "HibernateDelaySec=1h";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2020-02-03 18:31:46 +02:00
|
|
|
|
Extra config options for systemd sleep state logic.
|
2023-11-21 17:10:23 +00:00
|
|
|
|
See {manpage}`sleep.conf.d(5)` man page for available options.
|
2020-02-03 18:31:46 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
additionalUpstreamSystemUnits = mkOption {
|
2014-07-25 14:05:57 -04:00
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
example = [
|
|
|
|
|
"debug-shell.service"
|
|
|
|
|
"systemd-quotacheck.service"
|
|
|
|
|
];
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2014-07-25 14:05:57 -04:00
|
|
|
|
Additional units shipped with systemd that shall be enabled.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
suppressedSystemUnits = mkOption {
|
2019-04-18 10:40:48 +00:00
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "systemd-backlight@.service" ];
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2022-03-22 07:11:54 -04:00
|
|
|
|
A list of units to skip when generating system systemd configuration directory. This has
|
2022-07-20 12:32:04 +02:00
|
|
|
|
priority over upstream units, {option}`systemd.units`, and
|
|
|
|
|
{option}`systemd.additionalUpstreamSystemUnits`. The main purpose of this is to
|
2022-03-22 07:11:54 -04:00
|
|
|
|
prevent a upstream systemd unit from being added to the initrd with any modifications made to it
|
|
|
|
|
by other NixOS modules.
|
2019-04-18 10:40:48 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
watchdog.device = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
|
default = null;
|
2020-07-08 21:43:12 -04:00
|
|
|
|
example = "/dev/watchdog";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2020-07-08 21:43:12 -04:00
|
|
|
|
The path to a hardware watchdog device which will be managed by systemd.
|
2023-11-21 17:11:01 +00:00
|
|
|
|
If not specified, systemd will default to `/dev/watchdog`.
|
2020-07-08 21:43:12 -04:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
watchdog.runtimeTime = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-08 21:43:12 -04:00
|
|
|
|
example = "30s";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2020-07-08 21:43:12 -04:00
|
|
|
|
The amount of time which can elapse before a watchdog hardware device
|
2023-11-21 17:10:23 +00:00
|
|
|
|
will automatically reboot the system.
|
|
|
|
|
|
|
|
|
|
Valid time units include "ms", "s", "min", "h", "d", and "w";
|
|
|
|
|
see {manpage}`systemd.time(7)`.
|
2020-07-08 21:43:12 -04:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
watchdog.rebootTime = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-08 21:43:12 -04:00
|
|
|
|
example = "10m";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2020-07-08 21:43:12 -04:00
|
|
|
|
The amount of time which can elapse after a reboot has been triggered
|
|
|
|
|
before a watchdog hardware device will automatically reboot the system.
|
2023-11-21 17:10:23 +00:00
|
|
|
|
If left `null`, systemd will use its default of 10 minutes;
|
|
|
|
|
see {manpage}`systemd-system.conf(5)`.
|
|
|
|
|
|
|
|
|
|
Valid time units include "ms", "s", "min", "h", "d", and "w";
|
|
|
|
|
see also {manpage}`systemd.time(7)`.
|
2020-07-08 21:43:12 -04:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-21 16:22:50 +00:00
|
|
|
|
watchdog.kexecTime = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-08 21:43:12 -04:00
|
|
|
|
example = "10m";
|
2023-11-21 16:22:50 +00:00
|
|
|
|
description = ''
|
2023-11-21 17:11:01 +00:00
|
|
|
|
The amount of time which can elapse when `kexec` is being executed before
|
2020-07-08 21:43:12 -04:00
|
|
|
|
a watchdog hardware device will automatically reboot the system. This
|
2023-11-21 17:10:23 +00:00
|
|
|
|
option should only be enabled if `reloadTime` is also enabled;
|
|
|
|
|
see {manpage}`kexec(8)`.
|
|
|
|
|
|
|
|
|
|
Valid time units include "ms", "s", "min", "h", "d", and "w";
|
|
|
|
|
see also {manpage}`systemd.time(7)`.
|
2020-07-08 21:43:12 -04:00
|
|
|
|
'';
|
|
|
|
|
};
|
2012-06-14 18:44:56 -04:00
|
|
|
|
};
|
|
|
|
|
|
2012-06-01 20:15:07 -04:00
|
|
|
|
###### implementation
|
|
|
|
|
|
2015-04-19 21:05:12 +02:00
|
|
|
|
config = {
|
2012-06-01 20:15:07 -04:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
warnings =
|
|
|
|
|
let
|
|
|
|
|
mkOneNetOnlineWarn =
|
|
|
|
|
typeStr: name: def:
|
|
|
|
|
lib.optional (
|
|
|
|
|
lib.elem "network-online.target" def.after
|
|
|
|
|
&& !(lib.elem "network-online.target" (def.wants ++ def.requires ++ def.bindsTo))
|
|
|
|
|
) "${name}.${typeStr} is ordered after 'network-online.target' but doesn't depend on it";
|
|
|
|
|
mkNetOnlineWarns =
|
|
|
|
|
typeStr: defs: lib.concatLists (lib.mapAttrsToList (mkOneNetOnlineWarn typeStr) defs);
|
|
|
|
|
mkMountNetOnlineWarns =
|
|
|
|
|
typeStr: defs: lib.concatLists (map (m: mkOneNetOnlineWarn typeStr m.what m) defs);
|
|
|
|
|
in
|
|
|
|
|
concatLists (
|
|
|
|
|
mapAttrsToList (
|
|
|
|
|
name: service:
|
2020-10-31 16:50:25 +01:00
|
|
|
|
let
|
|
|
|
|
type = service.serviceConfig.Type or "";
|
|
|
|
|
restart = service.serviceConfig.Restart or "no";
|
2020-10-31 01:25:51 -07:00
|
|
|
|
hasDeprecated = builtins.hasAttr "StartLimitInterval" service.serviceConfig;
|
2020-10-31 16:50:25 +01:00
|
|
|
|
in
|
2025-04-01 20:10:43 +02:00
|
|
|
|
concatLists [
|
|
|
|
|
(optional (type == "oneshot" && (restart == "always" || restart == "on-success"))
|
|
|
|
|
"Service '${name}.service' with 'Type=oneshot' cannot have 'Restart=always' or 'Restart=on-success'"
|
|
|
|
|
)
|
|
|
|
|
(optional hasDeprecated "Service '${name}.service' uses the attribute 'StartLimitInterval' in the Service section, which is deprecated. See https://github.com/NixOS/nixpkgs/issues/45786.")
|
|
|
|
|
(optional (service.reloadIfChanged && service.reloadTriggers != [ ])
|
|
|
|
|
"Service '${name}.service' has both 'reloadIfChanged' and 'reloadTriggers' set. This is probably not what you want, because 'reloadTriggers' behave the same whay as 'restartTriggers' if 'reloadIfChanged' is set."
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
) cfg.services
|
|
|
|
|
)
|
|
|
|
|
++ (mkNetOnlineWarns "target" cfg.targets)
|
|
|
|
|
++ (mkNetOnlineWarns "service" cfg.services)
|
|
|
|
|
++ (mkNetOnlineWarns "socket" cfg.sockets)
|
|
|
|
|
++ (mkNetOnlineWarns "timer" cfg.timers)
|
|
|
|
|
++ (mkNetOnlineWarns "path" cfg.paths)
|
|
|
|
|
++ (mkMountNetOnlineWarns "mount" cfg.mounts)
|
|
|
|
|
++ (mkMountNetOnlineWarns "automount" cfg.automounts)
|
|
|
|
|
++ (mkNetOnlineWarns "slice" cfg.slices);
|
2024-01-25 14:23:56 -05:00
|
|
|
|
|
|
|
|
|
assertions = concatLists (
|
2025-04-01 20:10:43 +02:00
|
|
|
|
mapAttrsToList (
|
|
|
|
|
name: service:
|
|
|
|
|
map
|
|
|
|
|
(message: {
|
2024-01-25 14:23:56 -05:00
|
|
|
|
assertion = false;
|
|
|
|
|
inherit message;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
})
|
|
|
|
|
(concatLists [
|
|
|
|
|
(optional
|
|
|
|
|
(
|
|
|
|
|
(builtins.elem "network-interfaces.target" service.after)
|
|
|
|
|
|| (builtins.elem "network-interfaces.target" service.wants)
|
|
|
|
|
)
|
2024-01-25 14:23:56 -05:00
|
|
|
|
"Service '${name}.service' is using the deprecated target network-interfaces.target, which no longer exists. Using network.target is recommended instead."
|
|
|
|
|
)
|
|
|
|
|
])
|
2025-04-01 20:10:43 +02:00
|
|
|
|
) cfg.services
|
2020-10-31 16:50:25 +01:00
|
|
|
|
);
|
2014-04-09 23:55:17 -05:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
system.build.units = cfg.units;
|
2012-06-16 00:19:43 -04:00
|
|
|
|
|
2022-06-09 17:28:13 +02:00
|
|
|
|
system.nssModules = [ cfg.package.out ];
|
2020-05-06 00:24:38 +02:00
|
|
|
|
system.nssDatabases = {
|
2025-04-01 20:10:43 +02:00
|
|
|
|
hosts = (
|
|
|
|
|
mkMerge [
|
|
|
|
|
(mkOrder 400 [ "mymachines" ]) # 400 to ensure it comes before resolve (which is 501)
|
|
|
|
|
(mkOrder 999 [ "myhostname" ]) # after files (which is 998), but before regular nss modules
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
passwd = (
|
|
|
|
|
mkMerge [
|
|
|
|
|
(mkAfter [ "systemd" ])
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
group = (
|
|
|
|
|
mkMerge [
|
|
|
|
|
(mkAfter [ "[success=merge] systemd" ]) # need merge so that NSS won't stop at file-based groups
|
|
|
|
|
]
|
|
|
|
|
);
|
2020-05-05 15:03:14 +02:00
|
|
|
|
};
|
|
|
|
|
|
2022-06-09 17:28:13 +02:00
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
2012-08-06 11:45:59 -04:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
environment.etc =
|
|
|
|
|
let
|
|
|
|
|
# generate contents for /etc/systemd/${dir} from attrset of links and packages
|
|
|
|
|
hooks =
|
|
|
|
|
dir: links:
|
|
|
|
|
pkgs.runCommand "${dir}"
|
|
|
|
|
{
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
packages = cfg.packages;
|
|
|
|
|
}
|
|
|
|
|
''
|
|
|
|
|
set -e
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
for package in $packages
|
|
|
|
|
do
|
|
|
|
|
for hook in $package/lib/systemd/${dir}/*
|
|
|
|
|
do
|
|
|
|
|
ln -s $hook $out/
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
${concatStrings (mapAttrsToList (exec: target: "ln -s ${target} $out/${exec};\n") links)}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
enabledUpstreamSystemUnits = filter (n: !elem n cfg.suppressedSystemUnits) upstreamSystemUnits;
|
|
|
|
|
enabledUnits = filterAttrs (n: v: !elem n cfg.suppressedSystemUnits) cfg.units;
|
2024-07-16 16:52:17 -07:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
in
|
|
|
|
|
({
|
|
|
|
|
"systemd/system".source = generateUnits {
|
|
|
|
|
type = "system";
|
|
|
|
|
units = enabledUnits;
|
|
|
|
|
upstreamUnits = enabledUpstreamSystemUnits;
|
|
|
|
|
upstreamWants = upstreamSystemWants;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
"systemd/system.conf".text = ''
|
|
|
|
|
[Manager]
|
|
|
|
|
ManagerEnvironment=${
|
|
|
|
|
lib.concatStringsSep " " (
|
|
|
|
|
lib.mapAttrsToList (n: v: "${n}=${lib.escapeShellArg v}") cfg.managerEnvironment
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
${optionalString cfg.enableCgroupAccounting ''
|
|
|
|
|
DefaultCPUAccounting=yes
|
|
|
|
|
DefaultIOAccounting=yes
|
|
|
|
|
DefaultBlockIOAccounting=yes
|
|
|
|
|
DefaultIPAccounting=yes
|
|
|
|
|
''}
|
|
|
|
|
DefaultLimitCORE=infinity
|
|
|
|
|
${optionalString (cfg.watchdog.device != null) ''
|
|
|
|
|
WatchdogDevice=${cfg.watchdog.device}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (cfg.watchdog.runtimeTime != null) ''
|
|
|
|
|
RuntimeWatchdogSec=${cfg.watchdog.runtimeTime}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (cfg.watchdog.rebootTime != null) ''
|
|
|
|
|
RebootWatchdogSec=${cfg.watchdog.rebootTime}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (cfg.watchdog.kexecTime != null) ''
|
|
|
|
|
KExecWatchdogSec=${cfg.watchdog.kexecTime}
|
|
|
|
|
''}
|
|
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
"systemd/sleep.conf".text = ''
|
|
|
|
|
[Sleep]
|
|
|
|
|
${cfg.sleep.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
"systemd/user-generators" = {
|
|
|
|
|
source = hooks "user-generators" cfg.user.generators;
|
|
|
|
|
};
|
|
|
|
|
"systemd/system-generators" = {
|
|
|
|
|
source = hooks "system-generators" cfg.generators;
|
|
|
|
|
};
|
|
|
|
|
"systemd/system-shutdown" = {
|
|
|
|
|
source = hooks "system-shutdown" cfg.shutdown;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Ignore all other preset files so systemd doesn't try to enable/disable
|
|
|
|
|
# units during runtime.
|
|
|
|
|
"systemd/system-preset/00-nixos.preset".text = ''
|
|
|
|
|
ignore *
|
|
|
|
|
'';
|
|
|
|
|
"systemd/user-preset/00-nixos.preset".text = ''
|
|
|
|
|
ignore *
|
|
|
|
|
'';
|
|
|
|
|
});
|
2015-09-26 18:34:36 +02:00
|
|
|
|
|
2016-03-06 17:38:53 -08:00
|
|
|
|
services.dbus.enable = true;
|
|
|
|
|
|
2021-08-08 12:00:00 +00:00
|
|
|
|
users.users.systemd-network = {
|
|
|
|
|
uid = config.ids.uids.systemd-network;
|
|
|
|
|
group = "systemd-network";
|
|
|
|
|
};
|
2018-06-30 01:58:35 +02:00
|
|
|
|
users.groups.systemd-network.gid = config.ids.gids.systemd-network;
|
2021-08-08 12:00:00 +00:00
|
|
|
|
users.users.systemd-resolve = {
|
|
|
|
|
uid = config.ids.uids.systemd-resolve;
|
|
|
|
|
group = "systemd-resolve";
|
|
|
|
|
};
|
2018-06-30 01:58:35 +02:00
|
|
|
|
users.groups.systemd-resolve.gid = config.ids.gids.systemd-resolve;
|
2015-05-11 15:54:16 +02:00
|
|
|
|
|
2012-11-01 23:32:12 +01:00
|
|
|
|
# Target for ‘charon send-keys’ to hook into.
|
2018-06-30 01:58:35 +02:00
|
|
|
|
users.groups.keys.gid = config.ids.gids.keys;
|
2014-02-11 07:00:10 -05:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
systemd.targets.keys = {
|
|
|
|
|
description = "Security Keys";
|
|
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
};
|
2012-11-01 23:32:12 +01:00
|
|
|
|
|
2023-11-25 21:31:09 +01:00
|
|
|
|
# This target only exists so that services ordered before sysinit.target
|
|
|
|
|
# are restarted in the correct order, notably BEFORE the other services,
|
|
|
|
|
# when switching configurations.
|
|
|
|
|
systemd.targets.sysinit-reactivation = {
|
|
|
|
|
description = "Reactivate sysinit units";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.units =
|
2024-03-21 14:52:12 +01:00
|
|
|
|
let
|
|
|
|
|
withName = cfgToUnit: cfg: lib.nameValuePair cfg.name (cfgToUnit cfg);
|
|
|
|
|
in
|
2025-04-01 20:10:43 +02:00
|
|
|
|
mapAttrs' (_: withName pathToUnit) cfg.paths
|
2024-03-21 14:52:12 +01:00
|
|
|
|
// mapAttrs' (_: withName serviceToUnit) cfg.services
|
|
|
|
|
// mapAttrs' (_: withName sliceToUnit) cfg.slices
|
|
|
|
|
// mapAttrs' (_: withName socketToUnit) cfg.sockets
|
|
|
|
|
// mapAttrs' (_: withName targetToUnit) cfg.targets
|
|
|
|
|
// mapAttrs' (_: withName timerToUnit) cfg.timers
|
|
|
|
|
// listToAttrs (map (withName mountToUnit) cfg.mounts)
|
|
|
|
|
// listToAttrs (map (withName automountToUnit) cfg.automounts);
|
2012-06-14 18:44:56 -04:00
|
|
|
|
|
2025-04-01 20:10:43 +02:00
|
|
|
|
# Environment of PID 1
|
|
|
|
|
systemd.managerEnvironment = {
|
|
|
|
|
# Doesn't contain systemd itself - everything works so it seems to use the compiled-in value for its tools
|
|
|
|
|
# util-linux is needed for the main fsck utility wrapping the fs-specific ones
|
2025-04-02 18:21:52 +02:00
|
|
|
|
PATH = lib.makeBinPath (
|
|
|
|
|
config.system.fsPackages
|
|
|
|
|
++ [ cfg.package.util-linux ]
|
|
|
|
|
# systemd-ssh-generator needs sshd in PATH
|
|
|
|
|
++ lib.optional config.services.openssh.enable config.services.openssh.package
|
|
|
|
|
);
|
2025-04-01 20:10:43 +02:00
|
|
|
|
LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
|
|
|
|
|
TZDIR = "/etc/zoneinfo";
|
|
|
|
|
# If SYSTEMD_UNIT_PATH ends with an empty component (":"), the usual unit load path will be appended to the contents of the variable
|
|
|
|
|
SYSTEMD_UNIT_PATH = lib.mkIf (
|
|
|
|
|
config.boot.extraSystemdUnitPaths != [ ]
|
|
|
|
|
) "${builtins.concatStringsSep ":" config.boot.extraSystemdUnitPaths}:";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [
|
|
|
|
|
"DEVTMPFS"
|
|
|
|
|
"CGROUPS"
|
|
|
|
|
"INOTIFY_USER"
|
|
|
|
|
"SIGNALFD"
|
|
|
|
|
"TIMERFD"
|
|
|
|
|
"EPOLL"
|
|
|
|
|
"NET"
|
|
|
|
|
"SYSFS"
|
|
|
|
|
"PROC_FS"
|
|
|
|
|
"FHANDLE"
|
|
|
|
|
"CRYPTO_USER_API_HASH"
|
|
|
|
|
"CRYPTO_HMAC"
|
|
|
|
|
"CRYPTO_SHA256"
|
|
|
|
|
"DMIID"
|
|
|
|
|
"AUTOFS_FS"
|
|
|
|
|
"TMPFS_POSIX_ACL"
|
|
|
|
|
"TMPFS_XATTR"
|
|
|
|
|
"SECCOMP"
|
|
|
|
|
];
|
2012-11-29 18:51:44 +01:00
|
|
|
|
|
2013-10-09 14:28:35 +02:00
|
|
|
|
# Generate timer units for all services that have a ‘startAt’ value.
|
2025-04-01 20:10:43 +02:00
|
|
|
|
systemd.timers = mapAttrs (name: service: {
|
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig.OnCalendar = service.startAt;
|
|
|
|
|
}) (filterAttrs (name: service: service.enable && service.startAt != [ ]) cfg.services);
|
2013-10-09 14:28:35 +02:00
|
|
|
|
|
2015-05-11 12:39:37 +02:00
|
|
|
|
# Some overrides to upstream units.
|
|
|
|
|
systemd.services."systemd-backlight@".restartIfChanged = false;
|
2017-04-04 16:29:24 +02:00
|
|
|
|
systemd.services."systemd-fsck@".restartIfChanged = false;
|
2023-06-18 12:00:11 +02:00
|
|
|
|
systemd.services."systemd-fsck@".path = [ pkgs.util-linux ] ++ config.system.fsPackages;
|
2023-05-29 16:14:18 -04:00
|
|
|
|
systemd.services."systemd-makefs@" = {
|
|
|
|
|
restartIfChanged = false;
|
|
|
|
|
path = [ pkgs.util-linux ] ++ config.system.fsPackages;
|
|
|
|
|
# Since there is no /etc/systemd/system/systemd-makefs@.service
|
|
|
|
|
# file, the units generated in /run/systemd/generator would
|
|
|
|
|
# override anything we put here. But by forcing the use of a
|
|
|
|
|
# drop-in in /etc, it does apply.
|
|
|
|
|
overrideStrategy = "asDropin";
|
|
|
|
|
};
|
2023-07-29 14:01:11 -04:00
|
|
|
|
systemd.services."systemd-mkswap@" = {
|
|
|
|
|
restartIfChanged = false;
|
|
|
|
|
path = [ pkgs.util-linux ];
|
|
|
|
|
overrideStrategy = "asDropin";
|
|
|
|
|
};
|
2015-05-11 12:39:37 +02:00
|
|
|
|
systemd.services.systemd-random-seed.restartIfChanged = false;
|
|
|
|
|
systemd.services.systemd-remount-fs.restartIfChanged = false;
|
|
|
|
|
systemd.services.systemd-update-utmp.restartIfChanged = false;
|
2019-01-05 13:55:27 +01:00
|
|
|
|
systemd.services.systemd-udev-settle.restartIfChanged = false; # Causes long delays in nixos-rebuild
|
2015-05-11 12:39:37 +02:00
|
|
|
|
systemd.targets.local-fs.unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
systemd.targets.remote-fs.unitConfig.X-StopOnReconfiguration = true;
|
2019-12-11 09:34:35 +01:00
|
|
|
|
systemd.services.systemd-importd.environment = proxy_env;
|
2020-12-02 00:54:35 +01:00
|
|
|
|
systemd.services.systemd-pstore.wantedBy = [ "sysinit.target" ]; # see #81138
|
2014-07-11 23:33:40 +02:00
|
|
|
|
|
2022-06-30 12:54:47 +03:00
|
|
|
|
# NixOS has kernel modules in a different location, so override that here.
|
|
|
|
|
systemd.services.kmod-static-nodes.unitConfig.ConditionFileNotEmpty = [
|
2025-04-01 20:10:43 +02:00
|
|
|
|
"" # required to unset the previous value!
|
2022-06-30 12:54:47 +03:00
|
|
|
|
"/run/booted-system/kernel-modules/lib/modules/%v/modules.devname"
|
|
|
|
|
];
|
|
|
|
|
|
2015-05-11 15:48:45 +02:00
|
|
|
|
# Don't bother with certain units in containers.
|
|
|
|
|
systemd.services.systemd-remount-fs.unitConfig.ConditionVirtualization = "!container";
|
2019-10-07 20:24:29 +02:00
|
|
|
|
|
2021-04-03 10:11:52 +02:00
|
|
|
|
# Increase numeric PID range (set directly instead of copying a one-line file from systemd)
|
|
|
|
|
# https://github.com/systemd/systemd/pull/12226
|
2024-09-24 18:50:49 +03:00
|
|
|
|
boot.kernel.sysctl."kernel.pid_max" = mkIf pkgs.stdenv.hostPlatform.is64bit (lib.mkDefault 4194304);
|
2021-04-03 10:11:52 +02:00
|
|
|
|
|
2022-03-01 06:54:12 +09:00
|
|
|
|
services.logrotate.settings = {
|
2022-02-11 17:09:52 +09:00
|
|
|
|
"/var/log/btmp" = mapAttrs (_: mkDefault) {
|
|
|
|
|
frequency = "monthly";
|
2022-03-01 06:54:12 +09:00
|
|
|
|
rotate = 1;
|
|
|
|
|
create = "0660 root ${config.users.groups.utmp.name}";
|
|
|
|
|
minsize = "1M";
|
2022-02-11 17:09:52 +09:00
|
|
|
|
};
|
|
|
|
|
"/var/log/wtmp" = mapAttrs (_: mkDefault) {
|
|
|
|
|
frequency = "monthly";
|
2022-03-01 06:54:12 +09:00
|
|
|
|
rotate = 1;
|
|
|
|
|
create = "0664 root ${config.users.groups.utmp.name}";
|
|
|
|
|
minsize = "1M";
|
2022-02-11 17:09:52 +09:00
|
|
|
|
};
|
|
|
|
|
};
|
2015-04-19 21:05:12 +02:00
|
|
|
|
};
|
2014-11-19 13:11:30 -08:00
|
|
|
|
|
2015-10-14 18:05:50 +02:00
|
|
|
|
# FIXME: Remove these eventually.
|
2025-04-01 20:10:43 +02:00
|
|
|
|
imports = [
|
|
|
|
|
(mkRenamedOptionModule [ "boot" "systemd" "sockets" ] [ "systemd" "sockets" ])
|
|
|
|
|
(mkRenamedOptionModule [ "boot" "systemd" "targets" ] [ "systemd" "targets" ])
|
|
|
|
|
(mkRenamedOptionModule [ "boot" "systemd" "services" ] [ "systemd" "services" ])
|
|
|
|
|
(mkRenamedOptionModule [ "jobs" ] [ "systemd" "services" ])
|
|
|
|
|
(mkRemovedOptionModule [ "systemd" "generator-packages" ] "Use systemd.packages instead.")
|
|
|
|
|
(mkRemovedOptionModule [ "systemd" "enableUnifiedCgroupHierarchy" ] ''
|
|
|
|
|
In 256 support for cgroup v1 ('legacy' and 'hybrid' hierarchies) is now considered obsolete and systemd by default will refuse to boot under it.
|
|
|
|
|
To forcibly reenable cgroup v1 support, you can set boot.kernelParams = [ "systemd.unified_cgroup_hierarchy=0" "SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE=1" ].
|
|
|
|
|
NixOS does not officially support this configuration and might cause your system to be unbootable in future versions. You are on your own.
|
|
|
|
|
'')
|
|
|
|
|
];
|
2012-06-01 20:15:07 -04:00
|
|
|
|
}
|