2014-04-14 16:26:48 +02:00
|
|
|
|
{ config, lib, pkgs, utils, ... }:
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2013-01-01 14:42:43 +01:00
|
|
|
|
with utils;
|
2014-05-05 21:52:33 +02:00
|
|
|
|
with lib;
|
2014-04-14 16:26:48 +02:00
|
|
|
|
with import ./systemd-unit-options.nix { inherit config lib; };
|
2015-04-20 11:31:17 +02:00
|
|
|
|
with import ./systemd-lib.nix { inherit config lib pkgs; };
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
cfg = config.systemd;
|
2012-06-18 05:31:21 +02:00
|
|
|
|
|
2013-01-16 13:17:57 +01:00
|
|
|
|
systemd = cfg.package;
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
upstreamSystemUnits =
|
2012-06-15 00:44:56 +02:00
|
|
|
|
[ # Targets.
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"basic.target"
|
2013-01-08 17:26:51 +01:00
|
|
|
|
"sysinit.target"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"sockets.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"exit.target"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"graphical.target"
|
|
|
|
|
"multi-user.target"
|
|
|
|
|
"network.target"
|
2014-12-02 02:19:06 +01:00
|
|
|
|
"network-pre.target"
|
2013-07-16 11:55:12 +02:00
|
|
|
|
"network-online.target"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"nss-lookup.target"
|
|
|
|
|
"nss-user-lookup.target"
|
|
|
|
|
"time-sync.target"
|
2019-08-19 02:08:46 +02:00
|
|
|
|
"cryptsetup.target"
|
2012-08-15 00:14:48 +02: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-15 00:44:56 +02:00
|
|
|
|
|
2013-01-21 21:01:48 +01:00
|
|
|
|
# Rescue mode.
|
2013-01-08 18:24:06 +01:00
|
|
|
|
"rescue.target"
|
|
|
|
|
"rescue.service"
|
|
|
|
|
|
2012-06-15 19:09:22 +02:00
|
|
|
|
# Udev.
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"systemd-udevd-control.socket"
|
|
|
|
|
"systemd-udevd-kernel.socket"
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"systemd-udevd.service"
|
2012-06-15 19:09:22 +02:00
|
|
|
|
"systemd-udev-settle.service"
|
|
|
|
|
"systemd-udev-trigger.service"
|
2017-02-08 19:42:07 +01:00
|
|
|
|
# hwdb.bin is managed by NixOS
|
|
|
|
|
# "systemd-hwdb-update.service"
|
2012-06-15 19:09:22 +02:00
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Consoles.
|
|
|
|
|
"getty.target"
|
2018-02-11 23:43:24 +01:00
|
|
|
|
"getty-pre.target"
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"getty@.service"
|
|
|
|
|
"serial-getty@.service"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"console-getty.service"
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"container-getty@.service"
|
|
|
|
|
"systemd-vconsole-setup.service"
|
|
|
|
|
|
2012-08-15 00:14:48 +02:00
|
|
|
|
# Hardware (started by udev when a relevant device is plugged in).
|
|
|
|
|
"sound.target"
|
|
|
|
|
"bluetooth.target"
|
|
|
|
|
"printer.target"
|
|
|
|
|
"smartcard.target"
|
|
|
|
|
|
2012-06-15 00:44:56 +02:00
|
|
|
|
# Login stuff.
|
|
|
|
|
"systemd-logind.service"
|
|
|
|
|
"autovt@.service"
|
|
|
|
|
"systemd-user-sessions.service"
|
2019-10-03 22:24:15 +02:00
|
|
|
|
"dbus-org.freedesktop.import1.service"
|
2014-04-16 10:48:14 +02:00
|
|
|
|
"dbus-org.freedesktop.machine1.service"
|
2012-06-15 20:51:48 +02:00
|
|
|
|
"user@.service"
|
2018-08-04 12:22:37 +02:00
|
|
|
|
"user-runtime-dir@.service"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
|
|
|
|
|
# Journal.
|
|
|
|
|
"systemd-journald.socket"
|
|
|
|
|
"systemd-journald.service"
|
2012-07-20 18:02:42 +02:00
|
|
|
|
"systemd-journal-flush.service"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"systemd-journal-catalog-update.service"
|
2020-08-06 04:12:57 +02:00
|
|
|
|
] ++ (optional (!config.boot.isContainer) "systemd-journald-audit.socket") ++ [
|
2014-08-23 23:28:03 +02:00
|
|
|
|
"systemd-journald-dev-log.socket"
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"syslog.socket"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2019-08-16 11:29:41 +02:00
|
|
|
|
# Coredumps.
|
|
|
|
|
"systemd-coredump.socket"
|
|
|
|
|
"systemd-coredump@.service"
|
|
|
|
|
|
2012-08-06 22:52:08 +02:00
|
|
|
|
# Kernel module loading.
|
2014-04-17 18:52:31 +02:00
|
|
|
|
"systemd-modules-load.service"
|
|
|
|
|
"kmod-static-nodes.service"
|
2012-08-06 22:52:08 +02:00
|
|
|
|
|
2012-06-02 02:15:07 +02:00
|
|
|
|
# Filesystems.
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"systemd-fsck@.service"
|
|
|
|
|
"systemd-fsck-root.service"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"systemd-remount-fs.service"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"local-fs.target"
|
|
|
|
|
"local-fs-pre.target"
|
|
|
|
|
"remote-fs.target"
|
|
|
|
|
"remote-fs-pre.target"
|
|
|
|
|
"swap.target"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"dev-hugepages.mount"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"dev-mqueue.mount"
|
2014-04-28 09:13:57 +02:00
|
|
|
|
"sys-fs-fuse-connections.mount"
|
2020-08-06 04:12:57 +02:00
|
|
|
|
] ++ (optional (!config.boot.isContainer) "sys-kernel-config.mount") ++ [
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"sys-kernel-debug.mount"
|
|
|
|
|
|
2014-04-16 00:59:26 +02:00
|
|
|
|
# Maintaining state across reboots.
|
|
|
|
|
"systemd-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-15 00:44:56 +02:00
|
|
|
|
# Hibernate / suspend.
|
|
|
|
|
"hibernate.target"
|
|
|
|
|
"suspend.target"
|
2019-08-26 11:04:10 +02:00
|
|
|
|
"suspend-then-hibernate.target"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"sleep.target"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"hybrid-sleep.target"
|
2012-07-20 21:40:50 +02:00
|
|
|
|
"systemd-hibernate.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-02 02:15:07 +02:00
|
|
|
|
|
|
|
|
|
# Reboot stuff.
|
|
|
|
|
"reboot.target"
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"systemd-reboot.service"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"poweroff.target"
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"systemd-poweroff.service"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"halt.target"
|
2012-07-16 23:47:11 +02:00
|
|
|
|
"systemd-halt.service"
|
2012-06-02 02:15:07 +02:00
|
|
|
|
"shutdown.target"
|
|
|
|
|
"umount.target"
|
|
|
|
|
"final.target"
|
2012-08-15 00:14:48 +02:00
|
|
|
|
"kexec.target"
|
2013-09-16 17:15:42 +02:00
|
|
|
|
"systemd-kexec.service"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
"systemd-update-utmp.service"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
|
2012-06-19 23:02:54 +02: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
|
|
|
|
|
|
|
|
|
# Slices / containers.
|
|
|
|
|
"slices.target"
|
|
|
|
|
"user.slice"
|
|
|
|
|
"machine.slice"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"machines.target"
|
2019-10-03 22:24:15 +02:00
|
|
|
|
"systemd-importd.service"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
"systemd-machined.service"
|
2016-06-09 15:45:55 +02:00
|
|
|
|
"systemd-nspawn@.service"
|
2014-04-17 13:23:06 +02:00
|
|
|
|
|
|
|
|
|
# Temporary file creation / cleanup.
|
|
|
|
|
"systemd-tmpfiles-clean.service"
|
2014-04-17 16:10:48 +02:00
|
|
|
|
"systemd-tmpfiles-clean.timer"
|
2014-04-17 13:23:06 +02:00
|
|
|
|
"systemd-tmpfiles-setup.service"
|
|
|
|
|
"systemd-tmpfiles-setup-dev.service"
|
2014-04-17 18:52:31 +02:00
|
|
|
|
|
|
|
|
|
# Misc.
|
|
|
|
|
"systemd-sysctl.service"
|
2015-12-06 14:30:18 +01:00
|
|
|
|
"dbus-org.freedesktop.timedate1.service"
|
|
|
|
|
"dbus-org.freedesktop.locale1.service"
|
|
|
|
|
"dbus-org.freedesktop.hostname1.service"
|
|
|
|
|
"systemd-timedated.service"
|
|
|
|
|
"systemd-localed.service"
|
|
|
|
|
"systemd-hostnamed.service"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"systemd-exit.service"
|
2018-02-11 23:43:24 +01:00
|
|
|
|
"systemd-update-done.service"
|
2018-05-27 01:49:08 +02:00
|
|
|
|
] ++ optionals config.services.journald.enableHttpGateway [
|
|
|
|
|
"systemd-journal-gatewayd.socket"
|
|
|
|
|
"systemd-journal-gatewayd.service"
|
|
|
|
|
] ++ cfg.additionalUpstreamSystemUnits;
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
upstreamSystemWants =
|
2017-01-26 01:52:38 +01:00
|
|
|
|
[ "sysinit.target.wants"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"sockets.target.wants"
|
|
|
|
|
"local-fs.target.wants"
|
|
|
|
|
"multi-user.target.wants"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"timers.target.wants"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
];
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
upstreamUserUnits =
|
|
|
|
|
[ "basic.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"bluetooth.target"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"default.target"
|
|
|
|
|
"exit.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"graphical-session-pre.target"
|
|
|
|
|
"graphical-session.target"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"paths.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"printer.target"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"shutdown.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"smartcard.target"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"sockets.target"
|
2017-01-26 01:52:38 +01:00
|
|
|
|
"sound.target"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"systemd-exit.service"
|
2019-06-07 08:43:38 +02:00
|
|
|
|
"systemd-tmpfiles-clean.service"
|
|
|
|
|
"systemd-tmpfiles-clean.timer"
|
|
|
|
|
"systemd-tmpfiles-setup.service"
|
2014-04-18 00:38:40 +02:00
|
|
|
|
"timers.target"
|
|
|
|
|
];
|
|
|
|
|
|
2012-10-15 22:01:30 +02:00
|
|
|
|
makeJobScript = name: text:
|
2020-04-17 09:12:34 +02:00
|
|
|
|
let
|
|
|
|
|
scriptName = replaceChars [ "\\" "@" ] [ "-" "_" ] (shellEscape name);
|
2020-04-17 12:55:48 +02:00
|
|
|
|
out = pkgs.writeTextFile {
|
|
|
|
|
# The derivation name is different from the script file name
|
|
|
|
|
# to keep the script file name short to avoid cluttering logs.
|
|
|
|
|
name = "unit-script-${scriptName}";
|
|
|
|
|
executable = true;
|
|
|
|
|
destination = "/bin/${scriptName}";
|
|
|
|
|
text = ''
|
|
|
|
|
#!${pkgs.runtimeShell} -e
|
|
|
|
|
${text}
|
|
|
|
|
'';
|
|
|
|
|
checkPhase = ''
|
|
|
|
|
${pkgs.stdenv.shell} -n "$out/bin/${scriptName}"
|
|
|
|
|
'';
|
|
|
|
|
};
|
2020-04-17 09:12:34 +02:00
|
|
|
|
in "${out}/bin/${scriptName}";
|
2012-07-19 23:41:42 +02:00
|
|
|
|
|
2018-11-20 18:34:43 +01:00
|
|
|
|
unitConfig = { config, options, ... }: {
|
2012-10-09 21:14:15 +02:00
|
|
|
|
config = {
|
|
|
|
|
unitConfig =
|
2014-03-12 18:35:50 +01:00
|
|
|
|
optionalAttrs (config.requires != [])
|
|
|
|
|
{ Requires = toString config.requires; }
|
|
|
|
|
// optionalAttrs (config.wants != [])
|
|
|
|
|
{ Wants = toString config.wants; }
|
|
|
|
|
// optionalAttrs (config.after != [])
|
|
|
|
|
{ After = toString config.after; }
|
|
|
|
|
// optionalAttrs (config.before != [])
|
|
|
|
|
{ Before = toString config.before; }
|
|
|
|
|
// optionalAttrs (config.bindsTo != [])
|
|
|
|
|
{ BindsTo = toString config.bindsTo; }
|
|
|
|
|
// optionalAttrs (config.partOf != [])
|
|
|
|
|
{ PartOf = toString config.partOf; }
|
|
|
|
|
// optionalAttrs (config.conflicts != [])
|
|
|
|
|
{ Conflicts = toString config.conflicts; }
|
2014-11-19 22:11:30 +01:00
|
|
|
|
// optionalAttrs (config.requisite != [])
|
|
|
|
|
{ Requisite = toString config.requisite; }
|
2014-03-12 18:35:50 +01:00
|
|
|
|
// optionalAttrs (config.restartTriggers != [])
|
|
|
|
|
{ X-Restart-Triggers = toString config.restartTriggers; }
|
|
|
|
|
// optionalAttrs (config.description != "") {
|
2016-04-27 04:56:40 +02:00
|
|
|
|
Description = config.description; }
|
|
|
|
|
// optionalAttrs (config.documentation != []) {
|
|
|
|
|
Documentation = toString config.documentation; }
|
|
|
|
|
// optionalAttrs (config.onFailure != []) {
|
2018-11-20 18:34:43 +01:00
|
|
|
|
OnFailure = toString config.onFailure; }
|
|
|
|
|
// optionalAttrs (options.startLimitIntervalSec.isDefined) {
|
|
|
|
|
StartLimitIntervalSec = toString config.startLimitIntervalSec;
|
2012-10-09 21:14:15 +02:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-06 17:45:59 +02:00
|
|
|
|
serviceConfig = { name, config, ... }: {
|
2013-11-18 15:45:24 +01:00
|
|
|
|
config = mkMerge
|
2014-04-17 18:52:31 +02:00
|
|
|
|
[ { # Default path for systemd services. Should be quite minimal.
|
2020-01-06 15:58:06 +01:00
|
|
|
|
path = mkAfter
|
2013-11-18 15:45:24 +01:00
|
|
|
|
[ pkgs.coreutils
|
|
|
|
|
pkgs.findutils
|
|
|
|
|
pkgs.gnugrep
|
|
|
|
|
pkgs.gnused
|
|
|
|
|
systemd
|
|
|
|
|
];
|
|
|
|
|
environment.PATH = config.path;
|
2014-04-17 18:52:31 +02:00
|
|
|
|
}
|
2013-11-18 15:45:24 +01:00
|
|
|
|
(mkIf (config.preStart != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecStartPre =
|
|
|
|
|
makeJobScript "${name}-pre-start" config.preStart;
|
2013-11-18 15:45:24 +01:00
|
|
|
|
})
|
|
|
|
|
(mkIf (config.script != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecStart =
|
|
|
|
|
makeJobScript "${name}-start" config.script + " " + config.scriptArgs;
|
2013-11-18 15:45:24 +01:00
|
|
|
|
})
|
|
|
|
|
(mkIf (config.postStart != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecStartPost =
|
|
|
|
|
makeJobScript "${name}-post-start" config.postStart;
|
2013-11-18 15:45:24 +01:00
|
|
|
|
})
|
2014-09-16 05:03:20 +02:00
|
|
|
|
(mkIf (config.reload != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecReload =
|
|
|
|
|
makeJobScript "${name}-reload" config.reload;
|
2014-09-16 05:03:20 +02:00
|
|
|
|
})
|
2013-11-26 18:24:55 +01:00
|
|
|
|
(mkIf (config.preStop != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecStop =
|
|
|
|
|
makeJobScript "${name}-pre-stop" config.preStop;
|
2013-11-26 18:24:55 +01:00
|
|
|
|
})
|
2013-11-18 15:45:24 +01:00
|
|
|
|
(mkIf (config.postStop != "")
|
2020-04-20 10:42:47 +02:00
|
|
|
|
{ serviceConfig.ExecStopPost =
|
|
|
|
|
makeJobScript "${name}-post-stop" config.postStop;
|
2013-11-18 15:45:24 +01:00
|
|
|
|
})
|
|
|
|
|
];
|
2012-08-06 17:45:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
2018-07-20 22:56:59 +02:00
|
|
|
|
mountConfig = { config, ... }: {
|
2012-12-28 13:29:53 +01:00
|
|
|
|
config = {
|
|
|
|
|
mountConfig =
|
|
|
|
|
{ What = config.what;
|
|
|
|
|
Where = config.where;
|
|
|
|
|
} // optionalAttrs (config.type != "") {
|
|
|
|
|
Type = config.type;
|
|
|
|
|
} // optionalAttrs (config.options != "") {
|
|
|
|
|
Options = config.options;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-20 22:56:59 +02:00
|
|
|
|
automountConfig = { config, ... }: {
|
2013-09-23 22:56:05 +02:00
|
|
|
|
config = {
|
|
|
|
|
automountConfig =
|
|
|
|
|
{ Where = config.where;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
commonUnitText = def: ''
|
2014-03-12 18:20:57 +01:00
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
2012-10-02 00:58:11 +02:00
|
|
|
|
targetToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2012-10-02 00:58:11 +02:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-06-18 21:28:31 +02:00
|
|
|
|
|
2012-10-02 00:58:11 +02:00
|
|
|
|
serviceToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-12 18:20:57 +01:00
|
|
|
|
text = commonUnitText def +
|
2012-06-18 21:28:31 +02:00
|
|
|
|
''
|
|
|
|
|
[Service]
|
2012-10-30 17:27:14 +01:00
|
|
|
|
${let env = cfg.globalEnvironment // def.environment;
|
2014-07-30 10:28:05 +02:00
|
|
|
|
in concatMapStrings (n:
|
2019-08-13 23:52:01 +02:00
|
|
|
|
let s = optionalString (env.${n} != null)
|
2017-01-27 23:01:21 +01:00
|
|
|
|
"Environment=${builtins.toJSON "${n}=${env.${n}}"}\n";
|
2019-02-10 01:11:31 +01:00
|
|
|
|
# systemd max line length is now 1MiB
|
|
|
|
|
# https://github.com/systemd/systemd/commit/e6dde451a51dc5aaa7f4d98d39b8fe735f73d2af
|
|
|
|
|
in if stringLength s >= 1048576 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env)}
|
2014-03-17 15:02:53 +01:00
|
|
|
|
${if def.reloadIfChanged then ''
|
|
|
|
|
X-ReloadIfChanged=true
|
|
|
|
|
'' else if !def.restartIfChanged then ''
|
|
|
|
|
X-RestartIfChanged=false
|
|
|
|
|
'' else ""}
|
2013-01-05 01:05:25 +01:00
|
|
|
|
${optionalString (!def.stopIfChanged) "X-StopIfChanged=false"}
|
2012-10-01 22:27:42 +02:00
|
|
|
|
${attrsToSection def.serviceConfig}
|
2012-06-18 21:28:31 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-10-02 00:58:11 +02:00
|
|
|
|
socketToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-12 18:20:57 +01:00
|
|
|
|
text = commonUnitText def +
|
2012-10-02 00:58:11 +02:00
|
|
|
|
''
|
|
|
|
|
[Socket]
|
|
|
|
|
${attrsToSection def.socketConfig}
|
2013-05-14 16:07:55 +02:00
|
|
|
|
${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
|
2020-08-11 23:46:39 +02:00
|
|
|
|
${concatStringsSep "\n" (map (s: "ListenDatagram=${s}") def.listenDatagrams)}
|
2012-10-02 00:58:11 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-02 01:03:13 +01:00
|
|
|
|
timerToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-12 18:20:57 +01:00
|
|
|
|
text = commonUnitText def +
|
2013-03-02 01:03:13 +01:00
|
|
|
|
''
|
|
|
|
|
[Timer]
|
|
|
|
|
${attrsToSection def.timerConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-31 12:23:27 +02:00
|
|
|
|
pathToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-31 12:23:27 +02:00
|
|
|
|
text = commonUnitText def +
|
|
|
|
|
''
|
|
|
|
|
[Path]
|
|
|
|
|
${attrsToSection def.pathConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-28 13:29:53 +01:00
|
|
|
|
mountToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-12 18:20:57 +01:00
|
|
|
|
text = commonUnitText def +
|
2012-12-28 13:29:53 +01:00
|
|
|
|
''
|
|
|
|
|
[Mount]
|
|
|
|
|
${attrsToSection def.mountConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-23 22:56:05 +02:00
|
|
|
|
automountToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2014-03-12 18:20:57 +01:00
|
|
|
|
text = commonUnitText def +
|
2013-09-23 22:56:05 +02:00
|
|
|
|
''
|
|
|
|
|
[Automount]
|
|
|
|
|
${attrsToSection def.automountConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-20 07:21:52 +01:00
|
|
|
|
sliceToUnit = name: def:
|
2017-02-01 22:51:16 +01:00
|
|
|
|
{ inherit (def) aliases wantedBy requiredBy enable;
|
2016-12-20 07:21:52 +01:00
|
|
|
|
text = commonUnitText def +
|
|
|
|
|
''
|
|
|
|
|
[Slice]
|
|
|
|
|
${attrsToSection def.sliceConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-21 16:30:53 +02:00
|
|
|
|
logindHandlerType = types.enum [
|
|
|
|
|
"ignore" "poweroff" "reboot" "halt" "kexec" "suspend"
|
2018-10-28 21:41:21 +01:00
|
|
|
|
"hibernate" "hybrid-sleep" "suspend-then-hibernate" "lock"
|
2017-05-21 16:30:53 +02:00
|
|
|
|
];
|
|
|
|
|
|
2019-12-11 09:34:35 +01:00
|
|
|
|
proxy_env = config.networking.proxy.envVars;
|
|
|
|
|
|
2012-06-02 02:15:07 +02:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
2012-06-15 00:44:56 +02:00
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
2013-01-16 13:17:57 +01:00
|
|
|
|
systemd.package = mkOption {
|
|
|
|
|
default = pkgs.systemd;
|
2016-01-17 19:34:55 +01:00
|
|
|
|
defaultText = "pkgs.systemd";
|
2013-01-16 13:17:57 +01:00
|
|
|
|
type = types.package;
|
|
|
|
|
description = "The systemd package.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.units = mkOption {
|
2012-06-18 21:28:31 +02:00
|
|
|
|
description = "Definition of systemd units.";
|
2012-06-18 05:31:21 +02:00
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule (
|
|
|
|
|
{ name, config, ... }:
|
2014-04-17 23:35:05 +02:00
|
|
|
|
{ options = concreteUnitOptions;
|
2013-11-18 13:18:58 +01:00
|
|
|
|
config = {
|
2014-03-13 00:18:17 +01:00
|
|
|
|
unit = mkDefault (makeUnit name config);
|
2013-11-18 13:18:58 +01:00
|
|
|
|
};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
}));
|
2012-06-18 21:28:31 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.packages = mkOption {
|
2012-08-21 17:28:47 +02:00
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.package;
|
2019-07-26 11:11:44 +02:00
|
|
|
|
example = literalExample "[ pkgs.systemd-cryptsetup-generator ]";
|
|
|
|
|
description = "Packages providing systemd units and hooks.";
|
2012-08-21 17:28:47 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.targets = mkOption {
|
2012-10-02 00:58:11 +02:00
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig] );
|
2012-10-02 00:58:11 +02:00
|
|
|
|
description = "Definition of systemd target units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.services = mkOption {
|
2012-06-18 21:28:31 +02:00
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ]);
|
2012-10-02 00:58:11 +02:00
|
|
|
|
description = "Definition of systemd service units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.sockets = mkOption {
|
2012-10-02 00:58:11 +02:00
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ]);
|
2012-10-02 00:58:11 +02:00
|
|
|
|
description = "Definition of systemd socket units.";
|
2012-06-15 00:44:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
2013-03-02 01:03:13 +01:00
|
|
|
|
systemd.timers = mkOption {
|
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ]);
|
2013-03-02 01:03:13 +01:00
|
|
|
|
description = "Definition of systemd timer units.";
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-31 12:23:27 +02:00
|
|
|
|
systemd.paths = mkOption {
|
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]);
|
2014-03-31 12:23:27 +02:00
|
|
|
|
description = "Definition of systemd path units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.mounts = mkOption {
|
2012-12-28 13:29:53 +01:00
|
|
|
|
default = [];
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; listOf (submodule [ { options = mountOptions; } unitConfig mountConfig ]);
|
2012-12-28 13:29:53 +01:00
|
|
|
|
description = ''
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-23 22:56:05 +02:00
|
|
|
|
systemd.automounts = mkOption {
|
|
|
|
|
default = [];
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; listOf (submodule [ { options = automountOptions; } unitConfig automountConfig ]);
|
2013-09-23 22:56:05 +02:00
|
|
|
|
description = ''
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-20 07:21:52 +01:00
|
|
|
|
systemd.slices = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig] );
|
|
|
|
|
description = "Definition of slice configurations.";
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
systemd.generators = mkOption {
|
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
|
default = {};
|
2019-08-13 23:52:01 +02:00
|
|
|
|
example = { systemd-gpt-auto-generator = "/dev/null"; };
|
2015-09-26 18:34:36 +02:00
|
|
|
|
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>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-25 15:27:28 +02:00
|
|
|
|
systemd.shutdown = mkOption {
|
|
|
|
|
type = types.attrsOf types.path;
|
|
|
|
|
default = {};
|
|
|
|
|
description = ''
|
|
|
|
|
Definition of systemd shutdown executables.
|
|
|
|
|
For each <literal>NAME = VALUE</literal> pair of the attrSet, a link is generated from
|
|
|
|
|
<literal>/etc/systemd/system-shutdown/NAME</literal> to <literal>VALUE</literal>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.defaultUnit = mkOption {
|
2012-06-18 05:31:21 +02:00
|
|
|
|
default = "multi-user.target";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-06-18 05:31:21 +02:00
|
|
|
|
description = "Default unit started when the system boots.";
|
|
|
|
|
};
|
2012-07-19 23:32:50 +02:00
|
|
|
|
|
2016-07-19 09:42:53 +02:00
|
|
|
|
systemd.ctrlAltDelUnit = mkOption {
|
|
|
|
|
default = "reboot.target";
|
|
|
|
|
type = types.str;
|
|
|
|
|
example = "poweroff.target";
|
|
|
|
|
description = ''
|
|
|
|
|
Target that should be started when Ctrl-Alt-Delete is pressed.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.globalEnvironment = mkOption {
|
2019-08-08 23:35:52 +02:00
|
|
|
|
type = with types; attrsOf (nullOr (oneOf [ str path package ]));
|
2012-10-30 17:27:14 +01:00
|
|
|
|
default = {};
|
|
|
|
|
example = { TZ = "CET"; };
|
|
|
|
|
description = ''
|
|
|
|
|
Environment variables passed to <emphasis>all</emphasis> systemd units.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-10 22:23:42 +01:00
|
|
|
|
systemd.enableCgroupAccounting = mkOption {
|
2019-08-19 17:50:29 +02:00
|
|
|
|
default = true;
|
2018-03-10 22:23:42 +01:00
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to enable cgroup accounting.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-07 20:24:29 +02:00
|
|
|
|
systemd.coredump.enable = mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether core dumps should be processed by
|
|
|
|
|
<command>systemd-coredump</command>. If disabled, core dumps
|
|
|
|
|
appear in the current directory of the crashing process.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-16 11:29:41 +02:00
|
|
|
|
systemd.coredump.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "Storage=journal";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd-coredump. See coredump.conf(5) man page
|
|
|
|
|
for available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-15 19:49:01 +01:00
|
|
|
|
systemd.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "DefaultLimitCORE=infinity";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd. See man systemd-system.conf for
|
|
|
|
|
available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-07-19 23:32:50 +02:00
|
|
|
|
services.journald.console = mkOption {
|
|
|
|
|
default = "";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-11-02 14:10:06 +01:00
|
|
|
|
description = "If non-empty, write log messages to the specified TTY device.";
|
2012-07-19 23:32:50 +02:00
|
|
|
|
};
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2012-12-16 20:28:45 +01:00
|
|
|
|
services.journald.rateLimitInterval = mkOption {
|
2018-07-26 02:01:58 +02:00
|
|
|
|
default = "30s";
|
2013-10-30 11:02:04 +01:00
|
|
|
|
type = types.str;
|
2012-12-16 20:28:45 +01:00
|
|
|
|
description = ''
|
|
|
|
|
Configures the rate limiting interval that is applied to all
|
|
|
|
|
messages generated on the system. This rate limiting is applied
|
|
|
|
|
per-service, so that two services which log do not interfere with
|
|
|
|
|
each other's limit. The value may be specified in the following
|
|
|
|
|
units: s, min, h, ms, us. To turn off any kind of rate limiting,
|
|
|
|
|
set either value to 0.
|
2020-04-22 02:14:03 +02:00
|
|
|
|
|
|
|
|
|
See <option>services.journald.rateLimitBurst</option> for important
|
|
|
|
|
considerations when setting this value.
|
2012-12-16 20:28:45 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.journald.rateLimitBurst = mkOption {
|
2020-04-21 18:29:03 +02:00
|
|
|
|
default = 10000;
|
2015-06-15 18:11:32 +02:00
|
|
|
|
type = types.int;
|
2012-12-16 20:28:45 +01:00
|
|
|
|
description = ''
|
|
|
|
|
Configures the rate limiting burst limit (number of messages per
|
|
|
|
|
interval) that is applied to all messages generated on the system.
|
|
|
|
|
This rate limiting is applied per-service, so that two services
|
|
|
|
|
which log do not interfere with each other's limit.
|
2020-04-22 02:14:03 +02:00
|
|
|
|
|
|
|
|
|
Note that the effective rate limit is multiplied by a factor derived
|
|
|
|
|
from the available free disk space for the journal as described on
|
|
|
|
|
<link xlink:href="https://www.freedesktop.org/software/systemd/man/journald.conf.html">
|
|
|
|
|
journald.conf(5)</link>.
|
|
|
|
|
|
|
|
|
|
Note that the total amount of logs stored is limited by journald settings
|
|
|
|
|
such as <literal>SystemMaxUse</literal>, which defaults to a 4 GB cap.
|
|
|
|
|
|
|
|
|
|
It is thus recommended to compute what period of time that you will be
|
|
|
|
|
able to store logs for when an application logs at full burst rate.
|
|
|
|
|
With default settings for log lines that are 100 Bytes long, this can
|
|
|
|
|
amount to just a few hours.
|
2012-12-16 20:28:45 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-29 11:57:42 +01:00
|
|
|
|
services.journald.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "Storage=volatile";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd-journald. See man journald.conf
|
|
|
|
|
for available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-01 14:50:20 +01:00
|
|
|
|
services.journald.enableHttpGateway = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
2014-04-17 19:05:29 +02:00
|
|
|
|
Whether to enable the HTTP gateway to the journal.
|
2014-02-01 14:50:20 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-27 19:01:30 +02:00
|
|
|
|
services.journald.forwardToSyslog = mkOption {
|
|
|
|
|
default = config.services.rsyslogd.enable || config.services.syslog-ng.enable;
|
2019-02-18 20:21:04 +01:00
|
|
|
|
defaultText = "services.rsyslogd.enable || services.syslog-ng.enable";
|
2018-10-27 19:01:30 +02:00
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to forward log messages to syslog.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-24 11:54:01 +01:00
|
|
|
|
services.logind.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
2013-11-15 21:56:45 +01:00
|
|
|
|
type = types.lines;
|
2017-08-03 03:05:36 +02:00
|
|
|
|
example = "IdleAction=lock";
|
2013-02-24 11:54:01 +01:00
|
|
|
|
description = ''
|
2018-12-11 22:51:16 +01:00
|
|
|
|
Extra config options for systemd-logind. See
|
|
|
|
|
<link xlink:href="https://www.freedesktop.org/software/systemd/man/logind.conf.html">
|
|
|
|
|
logind.conf(5)</link> for available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.logind.killUserProcesses = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies whether the processes of a user should be killed
|
|
|
|
|
when the user logs out. If true, the scope unit corresponding
|
|
|
|
|
to the session and all processes inside that scope will be
|
|
|
|
|
terminated. If false, the scope is "abandoned" (see
|
|
|
|
|
<link xlink:href="https://www.freedesktop.org/software/systemd/man/systemd.scope.html#">
|
|
|
|
|
systemd.scope(5)</link>), and processes are not killed.
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>
|
|
|
|
|
See <link xlink:href="https://www.freedesktop.org/software/systemd/man/logind.conf.html#KillUserProcesses=">logind.conf(5)</link>
|
|
|
|
|
for more details.
|
2013-02-24 11:54:01 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-21 16:30:53 +02:00
|
|
|
|
services.logind.lidSwitch = mkOption {
|
|
|
|
|
default = "suspend";
|
|
|
|
|
example = "ignore";
|
|
|
|
|
type = logindHandlerType;
|
|
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies what to be done when the laptop lid is closed.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.logind.lidSwitchDocked = mkOption {
|
|
|
|
|
default = "ignore";
|
|
|
|
|
example = "suspend";
|
|
|
|
|
type = logindHandlerType;
|
|
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies what to be done when the laptop lid is closed
|
|
|
|
|
and another screen is added.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-16 23:56:22 +01:00
|
|
|
|
services.logind.lidSwitchExternalPower = mkOption {
|
|
|
|
|
default = config.services.logind.lidSwitch;
|
2019-02-18 20:21:04 +01:00
|
|
|
|
defaultText = "services.logind.lidSwitch";
|
2019-02-16 23:56:22 +01:00
|
|
|
|
example = "ignore";
|
|
|
|
|
type = logindHandlerType;
|
|
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies what to do when the laptop lid is closed and the system is
|
|
|
|
|
on external power. By default use the same action as specified in
|
|
|
|
|
services.logind.lidSwitch.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-03 17:31:46 +01:00
|
|
|
|
systemd.sleep.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "HibernateDelaySec=1h";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd sleep state logic.
|
|
|
|
|
See sleep.conf.d(5) man page for available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-08 10:40:54 +02:00
|
|
|
|
systemd.user.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.lines;
|
|
|
|
|
example = "DefaultCPUAccounting=yes";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd user instances. See man systemd-user.conf for
|
|
|
|
|
available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 16:10:48 +02:00
|
|
|
|
systemd.tmpfiles.rules = mkOption {
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
default = [];
|
|
|
|
|
example = [ "d /tmp 1777 root root 10d" ];
|
|
|
|
|
description = ''
|
|
|
|
|
Rules for creating and cleaning up temporary files
|
|
|
|
|
automatically. See
|
|
|
|
|
<citerefentry><refentrytitle>tmpfiles.d</refentrytitle><manvolnum>5</manvolnum></citerefentry>
|
2017-09-24 13:16:38 +02:00
|
|
|
|
for the exact format.
|
2014-04-17 16:10:48 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-13 18:12:38 +02:00
|
|
|
|
systemd.tmpfiles.packages = mkOption {
|
|
|
|
|
type = types.listOf types.package;
|
|
|
|
|
default = [];
|
|
|
|
|
example = literalExample "[ pkgs.lvm2 ]";
|
|
|
|
|
apply = map getLib;
|
|
|
|
|
description = ''
|
|
|
|
|
List of packages containing <command>systemd-tmpfiles</command> rules.
|
|
|
|
|
|
|
|
|
|
All files ending in .conf found in
|
|
|
|
|
<filename><replaceable>pkg</replaceable>/lib/tmpfiles.d</filename>
|
|
|
|
|
will be included.
|
|
|
|
|
If this folder does not exist or does not contain any files an error will be returned instead.
|
|
|
|
|
|
|
|
|
|
If a <filename>lib</filename> output is available, rules are searched there and only there.
|
|
|
|
|
If there is no <filename>lib</filename> output it will fall back to <filename>out</filename>
|
|
|
|
|
and if that does not exist either, the default output will be used.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
systemd.user.units = mkOption {
|
|
|
|
|
description = "Definition of systemd per-user units.";
|
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule (
|
|
|
|
|
{ name, config, ... }:
|
2014-04-18 00:38:40 +02:00
|
|
|
|
{ options = concreteUnitOptions;
|
|
|
|
|
config = {
|
|
|
|
|
unit = mkDefault (makeUnit name config);
|
|
|
|
|
};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
}));
|
2014-04-18 00:38:40 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-07-13 03:41:51 +02:00
|
|
|
|
systemd.user.paths = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = with types; attrsOf (submodule [ { options = pathOptions; } unitConfig ]);
|
|
|
|
|
description = "Definition of systemd per-user path units.";
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
systemd.user.services = mkOption {
|
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = serviceOptions; } unitConfig serviceConfig ] );
|
2014-04-18 00:38:40 +02:00
|
|
|
|
description = "Definition of systemd per-user service units.";
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-13 03:41:51 +02:00
|
|
|
|
systemd.user.slices = mkOption {
|
2014-12-30 05:46:36 +01:00
|
|
|
|
default = {};
|
2017-07-13 03:41:51 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = sliceOptions; } unitConfig ] );
|
|
|
|
|
description = "Definition of systemd per-user slice units.";
|
2014-12-30 05:46:36 +01:00
|
|
|
|
};
|
|
|
|
|
|
2014-06-20 20:34:21 +02:00
|
|
|
|
systemd.user.sockets = mkOption {
|
|
|
|
|
default = {};
|
2016-09-13 05:56:36 +02:00
|
|
|
|
type = with types; attrsOf (submodule [ { options = socketOptions; } unitConfig ] );
|
2014-06-20 20:34:21 +02:00
|
|
|
|
description = "Definition of systemd per-user socket units.";
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-27 04:56:40 +02:00
|
|
|
|
systemd.user.targets = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = with types; attrsOf (submodule [ { options = targetOptions; } unitConfig] );
|
|
|
|
|
description = "Definition of systemd per-user target units.";
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-13 03:41:51 +02:00
|
|
|
|
systemd.user.timers = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = with types; attrsOf (submodule [ { options = timerOptions; } unitConfig ] );
|
|
|
|
|
description = "Definition of systemd per-user timer units.";
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-25 20:05:57 +02:00
|
|
|
|
systemd.additionalUpstreamSystemUnits = mkOption {
|
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "debug-shell.service" "systemd-quotacheck.service" ];
|
|
|
|
|
description = ''
|
|
|
|
|
Additional units shipped with systemd that shall be enabled.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-18 12:40:48 +02:00
|
|
|
|
systemd.suppressedSystemUnits = mkOption {
|
|
|
|
|
default = [ ];
|
|
|
|
|
type = types.listOf types.str;
|
|
|
|
|
example = [ "systemd-backlight@.service" ];
|
|
|
|
|
description = ''
|
|
|
|
|
A list of units to suppress when generating system systemd configuration directory. This has
|
|
|
|
|
priority over upstream units, <option>systemd.units</option>, and
|
|
|
|
|
<option>systemd.additionalUpstreamSystemUnits</option>. The main purpose of this is to
|
|
|
|
|
suppress a upstream systemd unit with any modifications made to it by other NixOS modules.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-09 03:43:12 +02:00
|
|
|
|
systemd.watchdog.device = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
|
default = null;
|
2020-07-09 03:43:12 +02:00
|
|
|
|
example = "/dev/watchdog";
|
|
|
|
|
description = ''
|
|
|
|
|
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 {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-09 03:43:12 +02:00
|
|
|
|
example = "30s";
|
|
|
|
|
description = ''
|
|
|
|
|
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 {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-09 03:43:12 +02:00
|
|
|
|
example = "10m";
|
|
|
|
|
description = ''
|
|
|
|
|
The amount of time which can elapse after a reboot has been triggered
|
|
|
|
|
before a watchdog hardware device will automatically reboot the system.
|
|
|
|
|
Valid time units include "ms", "s", "min", "h", "d", and "w".
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.watchdog.kexecTime = mkOption {
|
2020-07-12 12:14:16 +02:00
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
2020-07-09 03:43:12 +02:00
|
|
|
|
example = "10m";
|
|
|
|
|
description = ''
|
|
|
|
|
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".
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-06-15 00:44:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2012-06-02 02:15:07 +02:00
|
|
|
|
###### implementation
|
|
|
|
|
|
2015-04-19 21:05:12 +02:00
|
|
|
|
config = {
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-22 23:23:05 +02:00
|
|
|
|
warnings = concatLists (mapAttrsToList (name: service:
|
2020-06-16 14:34:03 +02:00
|
|
|
|
let
|
|
|
|
|
type = service.serviceConfig.Type or "";
|
|
|
|
|
restart = service.serviceConfig.Restart or "no";
|
|
|
|
|
in optional
|
|
|
|
|
(type == "oneshot" && (restart == "always" || restart == "on-success"))
|
|
|
|
|
"Service '${name}.service' with 'Type=oneshot' cannot have 'Restart=always' or 'Restart=on-success'")
|
|
|
|
|
cfg.services);
|
2014-04-10 06:55:17 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
system.build.units = cfg.units;
|
2012-06-16 06:19:43 +02:00
|
|
|
|
|
2020-05-06 00:24:38 +02:00
|
|
|
|
system.nssModules = [ systemd.out ];
|
|
|
|
|
system.nssDatabases = {
|
2020-05-05 15:03:14 +02:00
|
|
|
|
hosts = (mkMerge [
|
|
|
|
|
[ "mymachines" ]
|
|
|
|
|
(mkOrder 1600 [ "myhostname" ] # 1600 to ensure it's always the last
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
passwd = (mkMerge [
|
|
|
|
|
(mkAfter [ "systemd" ])
|
|
|
|
|
]);
|
2020-05-06 00:06:40 +02:00
|
|
|
|
group = (mkMerge [
|
|
|
|
|
(mkAfter [ "systemd" ])
|
|
|
|
|
]);
|
2020-05-05 15:03:14 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-06-02 02:15:07 +02:00
|
|
|
|
environment.systemPackages = [ systemd ];
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2016-03-24 15:27:47 +01:00
|
|
|
|
environment.etc = let
|
2019-07-25 15:27:28 +02:00
|
|
|
|
# generate contents for /etc/systemd/system-${type} from attrset of links and packages
|
2019-07-26 11:11:44 +02:00
|
|
|
|
hooks = type: links: pkgs.runCommand "system-${type}" {
|
2018-11-08 11:59:03 +01:00
|
|
|
|
preferLocalBuild = true;
|
2019-07-26 11:11:44 +02:00
|
|
|
|
packages = cfg.packages;
|
2019-07-25 15:27:28 +02:00
|
|
|
|
} ''
|
|
|
|
|
set -e
|
2016-03-25 12:45:54 +01:00
|
|
|
|
mkdir -p $out
|
|
|
|
|
for package in $packages
|
|
|
|
|
do
|
2019-07-25 15:27:28 +02:00
|
|
|
|
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)}
|
2016-03-25 12:45:54 +01:00
|
|
|
|
'';
|
2019-04-18 12:40:48 +02:00
|
|
|
|
|
|
|
|
|
enabledUpstreamSystemUnits = filter (n: ! elem n cfg.suppressedSystemUnits) upstreamSystemUnits;
|
|
|
|
|
enabledUnits = filterAttrs (n: v: ! elem n cfg.suppressedSystemUnits) cfg.units;
|
2016-03-24 15:27:47 +01:00
|
|
|
|
in ({
|
2019-04-18 12:40:48 +02:00
|
|
|
|
"systemd/system".source = generateUnits "system" enabledUnits enabledUpstreamSystemUnits upstreamSystemWants;
|
2014-04-18 00:38:40 +02:00
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
"systemd/user".source = generateUnits "user" cfg.user.units upstreamUserUnits [];
|
2013-05-09 16:21:42 +02:00
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
"systemd/system.conf".text = ''
|
2013-05-09 16:21:42 +02:00
|
|
|
|
[Manager]
|
2018-03-10 22:23:42 +01:00
|
|
|
|
${optionalString config.systemd.enableCgroupAccounting ''
|
|
|
|
|
DefaultCPUAccounting=yes
|
|
|
|
|
DefaultIOAccounting=yes
|
|
|
|
|
DefaultBlockIOAccounting=yes
|
2019-08-19 17:43:57 +02:00
|
|
|
|
DefaultIPAccounting=yes
|
2018-03-10 22:23:42 +01:00
|
|
|
|
''}
|
2019-08-16 11:29:41 +02:00
|
|
|
|
DefaultLimitCORE=infinity
|
2020-07-12 12:14:16 +02:00
|
|
|
|
${optionalString (config.systemd.watchdog.device != null) ''
|
2020-07-09 03:43:12 +02:00
|
|
|
|
WatchdogDevice=${config.systemd.watchdog.device}
|
|
|
|
|
''}
|
2020-07-12 12:14:16 +02:00
|
|
|
|
${optionalString (config.systemd.watchdog.runtimeTime != null) ''
|
2020-07-09 03:43:12 +02:00
|
|
|
|
RuntimeWatchdogSec=${config.systemd.watchdog.runtimeTime}
|
|
|
|
|
''}
|
2020-07-12 12:14:16 +02:00
|
|
|
|
${optionalString (config.systemd.watchdog.rebootTime != null) ''
|
2020-07-09 03:43:12 +02:00
|
|
|
|
RebootWatchdogSec=${config.systemd.watchdog.rebootTime}
|
|
|
|
|
''}
|
2020-07-12 12:14:16 +02:00
|
|
|
|
${optionalString (config.systemd.watchdog.kexecTime != null) ''
|
2020-07-09 03:43:12 +02:00
|
|
|
|
KExecWatchdogSec=${config.systemd.watchdog.kexecTime}
|
|
|
|
|
''}
|
|
|
|
|
|
2013-11-15 19:49:01 +01:00
|
|
|
|
${config.systemd.extraConfig}
|
2013-05-09 16:21:42 +02:00
|
|
|
|
'';
|
|
|
|
|
|
2016-09-08 10:40:54 +02:00
|
|
|
|
"systemd/user.conf".text = ''
|
|
|
|
|
[Manager]
|
|
|
|
|
${config.systemd.user.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
"systemd/journald.conf".text = ''
|
2013-05-09 16:21:42 +02:00
|
|
|
|
[Journal]
|
2018-09-29 21:16:45 +02:00
|
|
|
|
Storage=persistent
|
2013-05-09 16:21:42 +02:00
|
|
|
|
RateLimitInterval=${config.services.journald.rateLimitInterval}
|
|
|
|
|
RateLimitBurst=${toString config.services.journald.rateLimitBurst}
|
|
|
|
|
${optionalString (config.services.journald.console != "") ''
|
|
|
|
|
ForwardToConsole=yes
|
|
|
|
|
TTYPath=${config.services.journald.console}
|
|
|
|
|
''}
|
2018-10-27 19:01:30 +02:00
|
|
|
|
${optionalString (config.services.journald.forwardToSyslog) ''
|
|
|
|
|
ForwardToSyslog=yes
|
|
|
|
|
''}
|
2013-11-29 11:57:42 +01:00
|
|
|
|
${config.services.journald.extraConfig}
|
2013-05-09 16:21:42 +02:00
|
|
|
|
'';
|
|
|
|
|
|
2019-08-16 11:29:41 +02:00
|
|
|
|
"systemd/coredump.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Coredump]
|
|
|
|
|
${config.systemd.coredump.extraConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
"systemd/logind.conf".text = ''
|
2013-05-09 16:21:42 +02:00
|
|
|
|
[Login]
|
2018-12-11 22:51:16 +01:00
|
|
|
|
KillUserProcesses=${if config.services.logind.killUserProcesses then "yes" else "no"}
|
2017-05-21 16:30:53 +02:00
|
|
|
|
HandleLidSwitch=${config.services.logind.lidSwitch}
|
|
|
|
|
HandleLidSwitchDocked=${config.services.logind.lidSwitchDocked}
|
2019-02-16 23:56:22 +01:00
|
|
|
|
HandleLidSwitchExternalPower=${config.services.logind.lidSwitchExternalPower}
|
2013-05-09 16:21:42 +02:00
|
|
|
|
${config.services.logind.extraConfig}
|
|
|
|
|
'';
|
2012-06-15 00:44:56 +02:00
|
|
|
|
|
2015-09-26 18:34:36 +02:00
|
|
|
|
"systemd/sleep.conf".text = ''
|
2013-05-09 16:25:24 +02:00
|
|
|
|
[Sleep]
|
2020-02-03 17:31:46 +01:00
|
|
|
|
${config.systemd.sleep.extraConfig}
|
2013-05-09 16:25:24 +02:00
|
|
|
|
'';
|
|
|
|
|
|
2019-08-11 13:32:24 +02:00
|
|
|
|
# install provided sysctl snippets
|
|
|
|
|
"sysctl.d/50-coredump.conf".source = "${systemd}/example/sysctl.d/50-coredump.conf";
|
|
|
|
|
"sysctl.d/50-default.conf".source = "${systemd}/example/sysctl.d/50-default.conf";
|
|
|
|
|
|
2020-08-16 10:14:21 +02:00
|
|
|
|
"tmpfiles.d".source = pkgs.symlinkJoin {
|
2020-07-13 18:12:38 +02:00
|
|
|
|
name = "tmpfiles.d";
|
2020-08-16 10:14:21 +02:00
|
|
|
|
paths = map (p: p + "/lib/tmpfiles.d") cfg.tmpfiles.packages;
|
2020-07-13 18:12:38 +02:00
|
|
|
|
postBuild = ''
|
|
|
|
|
for i in $(cat $pathsPath); do
|
2020-08-16 10:14:21 +02:00
|
|
|
|
(test -d "$i" && test $(ls "$i"/*.conf | wc -l) -ge 1) || (
|
|
|
|
|
echo "ERROR: The path '$i' from systemd.tmpfiles.packages contains no *.conf files."
|
2020-07-13 18:12:38 +02:00
|
|
|
|
exit 1
|
|
|
|
|
)
|
|
|
|
|
done
|
|
|
|
|
'';
|
2020-08-16 10:14:21 +02:00
|
|
|
|
};
|
2015-09-26 18:34:36 +02:00
|
|
|
|
|
2019-07-26 11:11:44 +02:00
|
|
|
|
"systemd/system-generators" = { source = hooks "generators" cfg.generators; };
|
|
|
|
|
"systemd/system-shutdown" = { source = hooks "shutdown" cfg.shutdown; };
|
2016-03-25 12:45:54 +01:00
|
|
|
|
});
|
2015-09-26 18:34:36 +02:00
|
|
|
|
|
2016-03-07 02:38:53 +01:00
|
|
|
|
services.dbus.enable = true;
|
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
|
users.users.systemd-network.uid = config.ids.uids.systemd-network;
|
|
|
|
|
users.groups.systemd-network.gid = config.ids.gids.systemd-network;
|
|
|
|
|
users.users.systemd-resolve.uid = config.ids.uids.systemd-resolve;
|
|
|
|
|
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 13:00:10 +01:00
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.targets.keys =
|
2012-11-01 23:32:12 +01:00
|
|
|
|
{ description = "Security Keys";
|
2014-02-26 19:35:04 +01:00
|
|
|
|
unitConfig.X-StopOnReconfiguration = true;
|
2012-11-01 23:32:12 +01:00
|
|
|
|
};
|
|
|
|
|
|
2020-07-13 18:12:38 +02:00
|
|
|
|
systemd.tmpfiles.packages = [
|
|
|
|
|
# Default tmpfiles rules provided by systemd
|
|
|
|
|
(pkgs.runCommand "systemd-default-tmpfiles" {} ''
|
|
|
|
|
mkdir -p $out/lib/tmpfiles.d
|
|
|
|
|
cd $out/lib/tmpfiles.d
|
|
|
|
|
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/home.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/journal-nocow.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/static-nodes-permissions.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/systemd.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/systemd-nologin.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/systemd-nspawn.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/systemd-tmp.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/tmp.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/var.conf"
|
|
|
|
|
ln -s "${systemd}/example/tmpfiles.d/x11.conf"
|
|
|
|
|
'')
|
|
|
|
|
# User-specified tmpfiles rules
|
|
|
|
|
(pkgs.writeTextFile {
|
|
|
|
|
name = "nixos-tmpfiles.d";
|
|
|
|
|
destination = "/lib/tmpfiles.d/00-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}
|
|
|
|
|
'';
|
|
|
|
|
})
|
|
|
|
|
];
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.units =
|
2017-07-13 03:41:51 +02:00
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.path" (pathToUnit n v)) cfg.paths
|
2012-10-02 00:58:11 +02:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
2017-07-13 03:41:51 +02:00
|
|
|
|
// 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
|
2012-12-28 13:29:53 +01:00
|
|
|
|
// listToAttrs (map
|
2013-01-01 14:42:43 +01:00
|
|
|
|
(v: let n = escapeSystemdPath v.where;
|
2013-09-23 22:56:05 +02:00
|
|
|
|
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);
|
2012-06-15 00:44:56 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
systemd.user.units =
|
2017-07-13 03:41:51 +02:00
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.path" (pathToUnit n v)) cfg.user.paths
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.user.services
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.slice" (sliceToUnit n v)) cfg.user.slices
|
2014-12-30 05:46:36 +01:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.user.sockets
|
2016-04-27 04:56:40 +02:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.user.targets
|
2014-12-30 05:46:36 +01:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.user.timers;
|
2014-04-18 00:38:40 +02:00
|
|
|
|
|
2014-04-30 13:53:12 +02:00
|
|
|
|
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled
|
|
|
|
|
[ "DEVTMPFS" "CGROUPS" "INOTIFY_USER" "SIGNALFD" "TIMERFD" "EPOLL" "NET"
|
2018-03-22 20:16:30 +01:00
|
|
|
|
"SYSFS" "PROC_FS" "FHANDLE" "CRYPTO_USER_API_HASH" "CRYPTO_HMAC"
|
|
|
|
|
"CRYPTO_SHA256" "DMIID" "AUTOFS4_FS" "TMPFS_POSIX_ACL"
|
2014-04-30 13:53:12 +02:00
|
|
|
|
"TMPFS_XATTR" "SECCOMP"
|
|
|
|
|
];
|
2012-11-29 18:51:44 +01:00
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
|
users.groups.systemd-journal.gid = config.ids.gids.systemd-journal;
|
|
|
|
|
users.users.systemd-journal-gateway.uid = config.ids.uids.systemd-journal-gateway;
|
|
|
|
|
users.groups.systemd-journal-gateway.gid = config.ids.gids.systemd-journal-gateway;
|
2013-07-19 21:18:44 +02:00
|
|
|
|
|
2013-10-09 14:28:35 +02:00
|
|
|
|
# Generate timer units for all services that have a ‘startAt’ value.
|
|
|
|
|
systemd.timers =
|
|
|
|
|
mapAttrs (name: service:
|
|
|
|
|
{ wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig.OnCalendar = service.startAt;
|
|
|
|
|
})
|
2016-10-19 02:10:46 +02:00
|
|
|
|
(filterAttrs (name: service: service.enable && service.startAt != []) cfg.services);
|
2013-10-09 14:28:35 +02:00
|
|
|
|
|
2015-08-21 08:45:13 +02:00
|
|
|
|
# Generate timer units for all services that have a ‘startAt’ value.
|
|
|
|
|
systemd.user.timers =
|
|
|
|
|
mapAttrs (name: service:
|
|
|
|
|
{ wantedBy = [ "timers.target" ];
|
|
|
|
|
timerConfig.OnCalendar = service.startAt;
|
|
|
|
|
})
|
2016-10-19 02:10:46 +02:00
|
|
|
|
(filterAttrs (name: service: service.startAt != []) cfg.user.services);
|
2015-08-21 08:45:13 +02:00
|
|
|
|
|
2014-04-17 19:05:29 +02:00
|
|
|
|
systemd.sockets.systemd-journal-gatewayd.wantedBy =
|
|
|
|
|
optional config.services.journald.enableHttpGateway "sockets.target";
|
|
|
|
|
|
2014-04-17 12:03:04 +02:00
|
|
|
|
# Provide the systemd-user PAM service, required to run systemd
|
|
|
|
|
# user instances.
|
|
|
|
|
security.pam.services.systemd-user =
|
|
|
|
|
{ # Ensure that pam_systemd gets included. This is special-cased
|
|
|
|
|
# in systemd to provide XDG_RUNTIME_DIR.
|
|
|
|
|
startSession = true;
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
2017-04-04 18:15:40 +02:00
|
|
|
|
systemd.services."systemd-fsck@".path = [ config.system.path ];
|
2014-05-20 11:10:20 +02:00
|
|
|
|
systemd.services."user@".restartIfChanged = false;
|
2014-07-17 20:59:25 +02:00
|
|
|
|
systemd.services.systemd-journal-flush.restartIfChanged = false;
|
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;
|
|
|
|
|
systemd.services.systemd-user-sessions.restartIfChanged = false; # Restart kills all active sessions.
|
2019-01-05 13:55:27 +01:00
|
|
|
|
systemd.services.systemd-udev-settle.restartIfChanged = false; # Causes long delays in nixos-rebuild
|
2017-09-27 23:23:19 +02:00
|
|
|
|
# Restarting systemd-logind breaks X11
|
|
|
|
|
# - upstream commit: https://cgit.freedesktop.org/xorg/xserver/commit/?id=dc48bd653c7e101
|
|
|
|
|
# - systemd announcement: https://github.com/systemd/systemd/blob/22043e4317ecd2bc7834b48a6d364de76bb26d91/NEWS#L103-L112
|
|
|
|
|
# - this might be addressed in the future by xorg
|
|
|
|
|
#systemd.services.systemd-logind.restartTriggers = [ config.environment.etc."systemd/logind.conf".source ];
|
|
|
|
|
systemd.services.systemd-logind.restartIfChanged = false;
|
2016-06-28 09:02:44 +02:00
|
|
|
|
systemd.services.systemd-logind.stopIfChanged = false;
|
2018-09-27 22:46:31 +02:00
|
|
|
|
# The user-runtime-dir@ service is managed by systemd-logind we should not touch it or else we break the users' sessions.
|
|
|
|
|
systemd.services."user-runtime-dir@".stopIfChanged = false;
|
|
|
|
|
systemd.services."user-runtime-dir@".restartIfChanged = false;
|
2016-09-30 14:46:22 +02:00
|
|
|
|
systemd.services.systemd-journald.restartTriggers = [ config.environment.etc."systemd/journald.conf".source ];
|
|
|
|
|
systemd.services.systemd-journald.stopIfChanged = false;
|
2015-05-11 12:39:37 +02:00
|
|
|
|
systemd.targets.local-fs.unitConfig.X-StopOnReconfiguration = true;
|
|
|
|
|
systemd.targets.remote-fs.unitConfig.X-StopOnReconfiguration = true;
|
2020-05-01 17:12:05 +02:00
|
|
|
|
systemd.targets.network-online.wantedBy = [ "multi-user.target" ];
|
2019-12-11 09:34:35 +01:00
|
|
|
|
systemd.services.systemd-importd.environment = proxy_env;
|
2014-07-11 23:33:40 +02:00
|
|
|
|
|
2015-05-11 15:48:45 +02: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";
|
2019-10-07 20:24:29 +02:00
|
|
|
|
|
|
|
|
|
boot.kernel.sysctl = mkIf (!cfg.coredump.enable) {
|
|
|
|
|
"kernel.core_pattern" = "core";
|
|
|
|
|
};
|
2015-04-19 21:05:12 +02:00
|
|
|
|
};
|
2014-11-19 22:11:30 +01:00
|
|
|
|
|
2015-10-14 18:05:50 +02:00
|
|
|
|
# FIXME: Remove these eventually.
|
|
|
|
|
imports =
|
|
|
|
|
[ (mkRenamedOptionModule [ "boot" "systemd" "sockets" ] [ "systemd" "sockets" ])
|
|
|
|
|
(mkRenamedOptionModule [ "boot" "systemd" "targets" ] [ "systemd" "targets" ])
|
|
|
|
|
(mkRenamedOptionModule [ "boot" "systemd" "services" ] [ "systemd" "services" ])
|
2019-12-10 02:51:19 +01:00
|
|
|
|
(mkRenamedOptionModule [ "jobs" ] [ "systemd" "services" ])
|
|
|
|
|
(mkRemovedOptionModule [ "systemd" "generator-packages" ] "Use systemd.packages instead.")
|
2015-10-14 18:05:50 +02:00
|
|
|
|
];
|
2012-06-02 02:15:07 +02:00
|
|
|
|
}
|