2020-04-24 23:36:52 +00:00
|
|
|
|
{ config, lib, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
|
|
with utils;
|
2021-12-19 01:06:50 +00:00
|
|
|
|
with systemdUtils.unitOptions;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
|
|
cfg = config.systemd;
|
|
|
|
|
|
2022-03-30 09:31:56 +00:00
|
|
|
|
inherit (systemdUtils.lib)
|
|
|
|
|
generateUnits
|
|
|
|
|
targetToUnit
|
|
|
|
|
serviceToUnit
|
|
|
|
|
socketToUnit
|
|
|
|
|
timerToUnit
|
|
|
|
|
pathToUnit
|
|
|
|
|
mountToUnit
|
|
|
|
|
automountToUnit
|
|
|
|
|
sliceToUnit;
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
upstreamSystemUnits =
|
|
|
|
|
[ # Targets.
|
|
|
|
|
"basic.target"
|
|
|
|
|
"sysinit.target"
|
|
|
|
|
"sockets.target"
|
|
|
|
|
"exit.target"
|
|
|
|
|
"graphical.target"
|
|
|
|
|
"multi-user.target"
|
|
|
|
|
"network.target"
|
|
|
|
|
"network-pre.target"
|
|
|
|
|
"network-online.target"
|
|
|
|
|
"nss-lookup.target"
|
|
|
|
|
"nss-user-lookup.target"
|
|
|
|
|
"time-sync.target"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ optionals cfg.package.withCryptsetup [
|
2020-09-25 04:45:31 +00:00
|
|
|
|
"cryptsetup.target"
|
2021-10-28 06:52:43 +00:00
|
|
|
|
"cryptsetup-pre.target"
|
|
|
|
|
"remote-cryptsetup.target"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"sigpwr.target"
|
|
|
|
|
"timers.target"
|
|
|
|
|
"paths.target"
|
|
|
|
|
"rpcbind.target"
|
|
|
|
|
|
|
|
|
|
# Rescue mode.
|
|
|
|
|
"rescue.target"
|
|
|
|
|
"rescue.service"
|
|
|
|
|
|
|
|
|
|
# Udev.
|
2023-10-09 19:29:22 +00:00
|
|
|
|
"systemd-tmpfiles-setup-dev-early.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-udevd-control.socket"
|
|
|
|
|
"systemd-udevd-kernel.socket"
|
|
|
|
|
"systemd-udevd.service"
|
|
|
|
|
"systemd-udev-settle.service"
|
2021-12-06 16:07:01 +00:00
|
|
|
|
] ++ (optional (!config.boot.isContainer) "systemd-udev-trigger.service") ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
# hwdb.bin is managed by NixOS
|
|
|
|
|
# "systemd-hwdb-update.service"
|
|
|
|
|
|
|
|
|
|
# Consoles.
|
|
|
|
|
"getty.target"
|
|
|
|
|
"getty-pre.target"
|
|
|
|
|
"getty@.service"
|
|
|
|
|
"serial-getty@.service"
|
|
|
|
|
"console-getty.service"
|
|
|
|
|
"container-getty@.service"
|
|
|
|
|
"systemd-vconsole-setup.service"
|
|
|
|
|
|
|
|
|
|
# Hardware (started by udev when a relevant device is plugged in).
|
|
|
|
|
"sound.target"
|
|
|
|
|
"bluetooth.target"
|
|
|
|
|
"printer.target"
|
|
|
|
|
"smartcard.target"
|
|
|
|
|
|
|
|
|
|
# Kernel module loading.
|
|
|
|
|
"systemd-modules-load.service"
|
|
|
|
|
"kmod-static-nodes.service"
|
2021-04-05 15:23:46 +00:00
|
|
|
|
"modprobe@.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
# Filesystems.
|
|
|
|
|
"systemd-fsck@.service"
|
|
|
|
|
"systemd-fsck-root.service"
|
2023-03-27 19:17:25 +00:00
|
|
|
|
"systemd-growfs@.service"
|
|
|
|
|
"systemd-growfs-root.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-remount-fs.service"
|
2021-05-20 23:08:51 +00:00
|
|
|
|
"systemd-pstore.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"local-fs.target"
|
|
|
|
|
"local-fs-pre.target"
|
|
|
|
|
"remote-fs.target"
|
|
|
|
|
"remote-fs-pre.target"
|
|
|
|
|
"swap.target"
|
|
|
|
|
"dev-hugepages.mount"
|
|
|
|
|
"dev-mqueue.mount"
|
|
|
|
|
"sys-fs-fuse-connections.mount"
|
2020-08-20 17:08:02 +00:00
|
|
|
|
] ++ (optional (!config.boot.isContainer) "sys-kernel-config.mount") ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"sys-kernel-debug.mount"
|
|
|
|
|
|
|
|
|
|
# Maintaining state across reboots.
|
|
|
|
|
"systemd-random-seed.service"
|
|
|
|
|
"systemd-backlight@.service"
|
|
|
|
|
"systemd-rfkill.service"
|
|
|
|
|
"systemd-rfkill.socket"
|
|
|
|
|
|
|
|
|
|
# Hibernate / suspend.
|
|
|
|
|
"hibernate.target"
|
|
|
|
|
"suspend.target"
|
|
|
|
|
"suspend-then-hibernate.target"
|
|
|
|
|
"sleep.target"
|
|
|
|
|
"hybrid-sleep.target"
|
|
|
|
|
"systemd-hibernate.service"
|
|
|
|
|
"systemd-hybrid-sleep.service"
|
|
|
|
|
"systemd-suspend.service"
|
|
|
|
|
"systemd-suspend-then-hibernate.service"
|
|
|
|
|
|
|
|
|
|
# Reboot stuff.
|
|
|
|
|
"reboot.target"
|
|
|
|
|
"systemd-reboot.service"
|
|
|
|
|
"poweroff.target"
|
|
|
|
|
"systemd-poweroff.service"
|
|
|
|
|
"halt.target"
|
|
|
|
|
"systemd-halt.service"
|
|
|
|
|
"shutdown.target"
|
|
|
|
|
"umount.target"
|
|
|
|
|
"final.target"
|
|
|
|
|
"kexec.target"
|
|
|
|
|
"systemd-kexec.service"
|
2022-09-22 12:36:57 +00:00
|
|
|
|
] ++ lib.optional cfg.package.withUtmp "systemd-update-utmp.service" ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
# Password entry.
|
|
|
|
|
"systemd-ask-password-console.path"
|
|
|
|
|
"systemd-ask-password-console.service"
|
|
|
|
|
"systemd-ask-password-wall.path"
|
|
|
|
|
"systemd-ask-password-wall.service"
|
|
|
|
|
|
|
|
|
|
# Slices / containers.
|
|
|
|
|
"slices.target"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ optionals cfg.package.withImportd [
|
|
|
|
|
"systemd-importd.service"
|
|
|
|
|
] ++ optionals cfg.package.withMachined [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"machine.slice"
|
|
|
|
|
"machines.target"
|
|
|
|
|
"systemd-machined.service"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-nspawn@.service"
|
|
|
|
|
|
|
|
|
|
# Misc.
|
|
|
|
|
"systemd-sysctl.service"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ optionals cfg.package.withTimedated [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"dbus-org.freedesktop.timedate1.service"
|
|
|
|
|
"systemd-timedated.service"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ optionals cfg.package.withLocaled [
|
|
|
|
|
"dbus-org.freedesktop.locale1.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-localed.service"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ optionals cfg.package.withHostnamed [
|
|
|
|
|
"dbus-org.freedesktop.hostname1.service"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-hostnamed.service"
|
2022-10-30 15:09:59 +00:00
|
|
|
|
] ++ optionals cfg.package.withPortabled [
|
|
|
|
|
"dbus-org.freedesktop.portable1.service"
|
|
|
|
|
"systemd-portabled.service"
|
2022-06-16 17:23:12 +00:00
|
|
|
|
] ++ [
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"systemd-exit.service"
|
|
|
|
|
"systemd-update-done.service"
|
|
|
|
|
] ++ cfg.additionalUpstreamSystemUnits;
|
|
|
|
|
|
|
|
|
|
upstreamSystemWants =
|
|
|
|
|
[ "sysinit.target.wants"
|
|
|
|
|
"sockets.target.wants"
|
|
|
|
|
"local-fs.target.wants"
|
|
|
|
|
"multi-user.target.wants"
|
|
|
|
|
"timers.target.wants"
|
|
|
|
|
];
|
|
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
|
proxy_env = config.networking.proxy.envVars;
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
|
|
systemd.package = mkOption {
|
|
|
|
|
default = pkgs.systemd;
|
2021-10-06 13:57:05 +00:00
|
|
|
|
defaultText = literalExpression "pkgs.systemd";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
type = types.package;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "The systemd package.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.units = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.units;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.packages = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.package;
|
2021-10-06 13:57:05 +00:00
|
|
|
|
example = literalExpression "[ pkgs.systemd-cryptsetup-generator ]";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Packages providing systemd units and hooks.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.targets = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.targets;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd target units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.services;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd service units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.sockets = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.sockets;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd socket units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.timers = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.timers;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd timer units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.paths = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.paths;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of systemd path units.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.mounts = mkOption {
|
|
|
|
|
default = [];
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.mounts;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Definition of systemd mount units.
|
|
|
|
|
This is a list instead of an attrSet, because systemd mandates the names to be derived from
|
|
|
|
|
the 'where' attribute.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.automounts = mkOption {
|
|
|
|
|
default = [];
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.automounts;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Definition of systemd automount units.
|
|
|
|
|
This is a list instead of an attrSet, because systemd mandates the names to be derived from
|
|
|
|
|
the 'where' attribute.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.slices = mkOption {
|
|
|
|
|
default = {};
|
2022-04-03 18:54:34 +00:00
|
|
|
|
type = systemdUtils.types.slices;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Definition of slice configurations.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.generators = mkOption {
|
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
|
default = {};
|
|
|
|
|
example = { systemd-gpt-auto-generator = "/dev/null"; };
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Definition of systemd generators.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
For each `NAME = VALUE` pair of the attrSet, a link is generated from
|
|
|
|
|
`/etc/systemd/system-generators/NAME` to `VALUE`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.shutdown = mkOption {
|
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Definition of systemd shutdown executables.
|
2022-08-12 12:06:08 +00:00
|
|
|
|
For each `NAME = VALUE` pair of the attrSet, a link is generated from
|
|
|
|
|
`/etc/systemd/system-shutdown/NAME` to `VALUE`.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.defaultUnit = mkOption {
|
|
|
|
|
default = "multi-user.target";
|
|
|
|
|
type = types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc "Default unit started when the system boots.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.ctrlAltDelUnit = mkOption {
|
|
|
|
|
default = "reboot.target";
|
|
|
|
|
type = types.str;
|
|
|
|
|
example = "poweroff.target";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Target that should be started when Ctrl-Alt-Delete is pressed.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.globalEnvironment = mkOption {
|
|
|
|
|
type = with types; attrsOf (nullOr (oneOf [ str path package ]));
|
|
|
|
|
default = {};
|
|
|
|
|
example = { TZ = "CET"; };
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
|
Environment variables passed to *all* systemd units.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
|
systemd.managerEnvironment = mkOption {
|
|
|
|
|
type = with types; attrsOf (nullOr (oneOf [ str path package ]));
|
|
|
|
|
default = {};
|
|
|
|
|
example = { SYSTEMD_LOG_LEVEL = "debug"; };
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2022-04-03 18:54:34 +00:00
|
|
|
|
Environment variables of PID 1. These variables are
|
2022-08-12 12:06:08 +00:00
|
|
|
|
*not* passed to started units.
|
2022-04-03 18:54:34 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.enableCgroupAccounting = mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Whether to enable cgroup accounting.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-03 08:41:04 +00:00
|
|
|
|
systemd.enableUnifiedCgroupHierarchy = mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
type = types.bool;
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-12-03 08:41:04 +00:00
|
|
|
|
Whether to enable the unified cgroup hierarchy (cgroupsv2).
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "DefaultLimitCORE=infinity";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2022-10-06 18:32:54 +00:00
|
|
|
|
Extra config options for systemd. See systemd-system.conf(5) man page
|
|
|
|
|
for available options.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.sleep.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "HibernateDelaySec=1h";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Extra config options for systemd sleep state logic.
|
|
|
|
|
See sleep.conf.d(5) man page for available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.additionalUpstreamSystemUnits = mkOption {
|
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "debug-shell.service" "systemd-quotacheck.service" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
|
Additional units shipped with systemd that shall be enabled.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.suppressedSystemUnits = mkOption {
|
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "systemd-backlight@.service" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2022-04-03 18:54:34 +00:00
|
|
|
|
A list of units to skip when generating system systemd configuration directory. This has
|
2022-08-12 12:06:08 +00:00
|
|
|
|
priority over upstream units, {option}`systemd.units`, and
|
|
|
|
|
{option}`systemd.additionalUpstreamSystemUnits`. The main purpose of this is to
|
2022-04-03 18:54:34 +00:00
|
|
|
|
prevent a upstream systemd unit from being added to the initrd with any modifications made to it
|
|
|
|
|
by other NixOS modules.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
|
systemd.watchdog.device = mkOption {
|
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "/dev/watchdog";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-07-18 16:06:22 +00:00
|
|
|
|
The path to a hardware watchdog device which will be managed by systemd.
|
|
|
|
|
If not specified, systemd will default to /dev/watchdog.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.watchdog.runtimeTime = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "30s";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-07-18 16:06:22 +00:00
|
|
|
|
The amount of time which can elapse before a watchdog hardware device
|
|
|
|
|
will automatically reboot the system. Valid time units include "ms",
|
|
|
|
|
"s", "min", "h", "d", and "w".
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.watchdog.rebootTime = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "10m";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-07-18 16:06:22 +00: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-10-09 19:29:22 +00:00
|
|
|
|
Valid time units include "ms", "s", "min", "h", "d", and "w". If left
|
|
|
|
|
`null`, systemd will use its default of `10min`; see also {command}`man
|
|
|
|
|
5 systemd-system.conf`.
|
2020-07-18 16:06:22 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.watchdog.kexecTime = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "10m";
|
2022-08-12 12:06:08 +00:00
|
|
|
|
description = lib.mdDoc ''
|
2020-07-18 16:06:22 +00:00
|
|
|
|
The amount of time which can elapse when kexec is being executed before
|
|
|
|
|
a watchdog hardware device will automatically reboot the system. This
|
|
|
|
|
option should only be enabled if reloadTime is also enabled. Valid
|
|
|
|
|
time units include "ms", "s", "min", "h", "d", and "w".
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
2020-11-03 02:18:15 +00:00
|
|
|
|
warnings = concatLists (
|
|
|
|
|
mapAttrsToList
|
|
|
|
|
(name: service:
|
|
|
|
|
let
|
|
|
|
|
type = service.serviceConfig.Type or "";
|
|
|
|
|
restart = service.serviceConfig.Restart or "no";
|
|
|
|
|
hasDeprecated = builtins.hasAttr "StartLimitInterval" service.serviceConfig;
|
|
|
|
|
in
|
|
|
|
|
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."
|
|
|
|
|
)
|
2022-02-20 05:27:41 +00:00
|
|
|
|
(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."
|
|
|
|
|
)
|
2020-11-03 02:18:15 +00:00
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
cfg.services
|
|
|
|
|
);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
system.build.units = cfg.units;
|
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
|
system.nssModules = [ cfg.package.out ];
|
2020-05-15 21:57:56 +00:00
|
|
|
|
system.nssDatabases = {
|
|
|
|
|
hosts = (mkMerge [
|
2021-07-24 12:14:16 +00:00
|
|
|
|
(mkOrder 400 ["mymachines"]) # 400 to ensure it comes before resolve (which is mkBefore'd)
|
|
|
|
|
(mkOrder 999 ["myhostname"]) # after files (which is 998), but before regular nss modules
|
2020-05-15 21:57:56 +00:00
|
|
|
|
]);
|
|
|
|
|
passwd = (mkMerge [
|
|
|
|
|
(mkAfter [ "systemd" ])
|
|
|
|
|
]);
|
|
|
|
|
group = (mkMerge [
|
2023-01-20 10:41:00 +00:00
|
|
|
|
(mkAfter [ "[success=merge] systemd" ]) # need merge so that NSS won't stop at file-based groups
|
2020-05-15 21:57:56 +00:00
|
|
|
|
]);
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
environment.etc = let
|
|
|
|
|
# generate contents for /etc/systemd/system-${type} from attrset of links and packages
|
|
|
|
|
hooks = type: links: pkgs.runCommand "system-${type}" {
|
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
packages = cfg.packages;
|
|
|
|
|
} ''
|
|
|
|
|
set -e
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
for package in $packages
|
|
|
|
|
do
|
|
|
|
|
for hook in $package/lib/systemd/system-${type}/*
|
|
|
|
|
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;
|
2022-04-03 18:54:34 +00:00
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
in ({
|
2022-04-03 18:54:34 +00:00
|
|
|
|
"systemd/system".source = generateUnits {
|
|
|
|
|
type = "system";
|
|
|
|
|
units = enabledUnits;
|
|
|
|
|
upstreamUnits = enabledUpstreamSystemUnits;
|
|
|
|
|
upstreamWants = upstreamSystemWants;
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
"systemd/system.conf".text = ''
|
|
|
|
|
[Manager]
|
2022-04-03 18:54:34 +00:00
|
|
|
|
ManagerEnvironment=${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${lib.escapeShellArg v}") cfg.managerEnvironment)}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
${optionalString config.systemd.enableCgroupAccounting ''
|
|
|
|
|
DefaultCPUAccounting=yes
|
|
|
|
|
DefaultIOAccounting=yes
|
|
|
|
|
DefaultBlockIOAccounting=yes
|
|
|
|
|
DefaultIPAccounting=yes
|
|
|
|
|
''}
|
|
|
|
|
DefaultLimitCORE=infinity
|
2020-07-18 16:06:22 +00:00
|
|
|
|
${optionalString (config.systemd.watchdog.device != null) ''
|
|
|
|
|
WatchdogDevice=${config.systemd.watchdog.device}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (config.systemd.watchdog.runtimeTime != null) ''
|
|
|
|
|
RuntimeWatchdogSec=${config.systemd.watchdog.runtimeTime}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (config.systemd.watchdog.rebootTime != null) ''
|
|
|
|
|
RebootWatchdogSec=${config.systemd.watchdog.rebootTime}
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (config.systemd.watchdog.kexecTime != null) ''
|
|
|
|
|
KExecWatchdogSec=${config.systemd.watchdog.kexecTime}
|
|
|
|
|
''}
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
${config.systemd.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
"systemd/sleep.conf".text = ''
|
|
|
|
|
[Sleep]
|
|
|
|
|
${config.systemd.sleep.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
"systemd/system-generators" = { source = hooks "generators" cfg.generators; };
|
|
|
|
|
"systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
services.dbus.enable = true;
|
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
|
users.users.systemd-network = {
|
|
|
|
|
uid = config.ids.uids.systemd-network;
|
|
|
|
|
group = "systemd-network";
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
users.groups.systemd-network.gid = config.ids.gids.systemd-network;
|
2021-09-18 10:52:07 +00:00
|
|
|
|
users.users.systemd-resolve = {
|
|
|
|
|
uid = config.ids.uids.systemd-resolve;
|
|
|
|
|
group = "systemd-resolve";
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
users.groups.systemd-resolve.gid = config.ids.gids.systemd-resolve;
|
|
|
|
|
|
|
|
|
|
# Target for ‘charon send-keys’ to hook into.
|
|
|
|
|
users.groups.keys.gid = config.ids.gids.keys;
|
|
|
|
|
|
|
|
|
|
systemd.targets.keys =
|
|
|
|
|
{ description = "Security Keys";
|
|
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.units =
|
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.path" (pathToUnit n v)) cfg.paths
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.slice" (sliceToUnit n v)) cfg.slices
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.targets
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
|
|
|
|
|
// listToAttrs (map
|
|
|
|
|
(v: let n = escapeSystemdPath v.where;
|
|
|
|
|
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts)
|
|
|
|
|
// listToAttrs (map
|
|
|
|
|
(v: let n = escapeSystemdPath v.where;
|
|
|
|
|
in nameValuePair "${n}.automount" (automountToUnit n v)) cfg.automounts);
|
|
|
|
|
|
2022-04-03 18:54:34 +00: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
|
2022-11-21 17:40:18 +00:00
|
|
|
|
# util-linux is needed for the main fsck utility wrapping the fs-specific ones
|
|
|
|
|
PATH = lib.makeBinPath (config.system.fsPackages ++ [cfg.package.util-linux]);
|
2022-04-03 18:54:34 +00: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}:";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
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"
|
2023-11-16 04:20:00 +00:00
|
|
|
|
"CRYPTO_SHA256" "DMIID" "AUTOFS_FS" "TMPFS_POSIX_ACL"
|
2020-04-24 23:36:52 +00:00
|
|
|
|
"TMPFS_XATTR" "SECCOMP"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# Generate timer units for all services that have a ‘startAt’ value.
|
|
|
|
|
systemd.timers =
|
|
|
|
|
mapAttrs (name: service:
|
|
|
|
|
{ wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig.OnCalendar = service.startAt;
|
|
|
|
|
})
|
|
|
|
|
(filterAttrs (name: service: service.enable && service.startAt != []) cfg.services);
|
|
|
|
|
|
|
|
|
|
# Some overrides to upstream units.
|
|
|
|
|
systemd.services."systemd-backlight@".restartIfChanged = false;
|
|
|
|
|
systemd.services."systemd-fsck@".restartIfChanged = false;
|
2023-07-15 17:15:38 +00:00
|
|
|
|
systemd.services."systemd-fsck@".path = [ pkgs.util-linux ] ++ config.system.fsPackages;
|
|
|
|
|
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-08-04 22:07:22 +00:00
|
|
|
|
systemd.services."systemd-mkswap@" = {
|
|
|
|
|
restartIfChanged = false;
|
|
|
|
|
path = [ pkgs.util-linux ];
|
|
|
|
|
overrideStrategy = "asDropin";
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
systemd.services.systemd-random-seed.restartIfChanged = false;
|
|
|
|
|
systemd.services.systemd-remount-fs.restartIfChanged = false;
|
|
|
|
|
systemd.services.systemd-update-utmp.restartIfChanged = false;
|
|
|
|
|
systemd.services.systemd-udev-settle.restartIfChanged = false; # Causes long delays in nixos-rebuild
|
|
|
|
|
systemd.targets.local-fs.unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
systemd.targets.remote-fs.unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
systemd.targets.network-online.wantedBy = [ "multi-user.target" ];
|
2020-05-15 21:57:56 +00:00
|
|
|
|
systemd.services.systemd-importd.environment = proxy_env;
|
2021-05-20 23:08:51 +00:00
|
|
|
|
systemd.services.systemd-pstore.wantedBy = [ "sysinit.target" ]; # see #81138
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
|
# NixOS has kernel modules in a different location, so override that here.
|
|
|
|
|
systemd.services.kmod-static-nodes.unitConfig.ConditionFileNotEmpty = [
|
|
|
|
|
"" # required to unset the previous value!
|
|
|
|
|
"/run/booted-system/kernel-modules/lib/modules/%v/modules.devname"
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
|
# Don't bother with certain units in containers.
|
|
|
|
|
systemd.services.systemd-remount-fs.unitConfig.ConditionVirtualization = "!container";
|
|
|
|
|
systemd.services.systemd-random-seed.unitConfig.ConditionVirtualization = "!container";
|
|
|
|
|
|
2021-04-05 15:23:46 +00:00
|
|
|
|
# Increase numeric PID range (set directly instead of copying a one-line file from systemd)
|
|
|
|
|
# https://github.com/systemd/systemd/pull/12226
|
|
|
|
|
boot.kernel.sysctl."kernel.pid_max" = mkIf pkgs.stdenv.is64bit (lib.mkDefault 4194304);
|
|
|
|
|
|
2020-12-03 08:41:04 +00:00
|
|
|
|
boot.kernelParams = optional (!cfg.enableUnifiedCgroupHierarchy) "systemd.unified_cgroup_hierarchy=0";
|
2022-03-05 16:20:37 +00:00
|
|
|
|
|
2022-12-02 08:20:57 +00:00
|
|
|
|
# Avoid potentially degraded system state due to
|
|
|
|
|
# "Userspace Out-Of-Memory (OOM) Killer was skipped because of a failed condition check (ConditionControlGroupController=v2)."
|
2023-03-15 16:39:30 +00:00
|
|
|
|
systemd.oomd.enable = mkIf (!cfg.enableUnifiedCgroupHierarchy) false;
|
2022-12-02 08:20:57 +00:00
|
|
|
|
|
2022-04-03 18:54:34 +00:00
|
|
|
|
services.logrotate.settings = {
|
2022-03-05 16:20:37 +00:00
|
|
|
|
"/var/log/btmp" = mapAttrs (_: mkDefault) {
|
|
|
|
|
frequency = "monthly";
|
2022-04-03 18:54:34 +00:00
|
|
|
|
rotate = 1;
|
|
|
|
|
create = "0660 root ${config.users.groups.utmp.name}";
|
|
|
|
|
minsize = "1M";
|
2022-03-05 16:20:37 +00:00
|
|
|
|
};
|
|
|
|
|
"/var/log/wtmp" = mapAttrs (_: mkDefault) {
|
|
|
|
|
frequency = "monthly";
|
2022-04-03 18:54:34 +00:00
|
|
|
|
rotate = 1;
|
|
|
|
|
create = "0664 root ${config.users.groups.utmp.name}";
|
|
|
|
|
minsize = "1M";
|
2022-03-05 16:20:37 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# FIXME: Remove these eventually.
|
|
|
|
|
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.")
|
|
|
|
|
];
|
|
|
|
|
}
|