2014-04-14 16:26:48 +02:00
|
|
|
|
{ config, lib, pkgs, utils, ... }:
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
|
with lib;
|
2013-01-01 14:42:43 +01:00
|
|
|
|
with utils;
|
2014-04-14 16:26:48 +02:00
|
|
|
|
with import ./systemd-unit-options.nix { inherit config lib; };
|
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-10-19 17:18:50 +02:00
|
|
|
|
|
2012-06-18 05:31:21 +02:00
|
|
|
|
makeUnit = name: unit:
|
2014-10-19 17:18:50 +02:00
|
|
|
|
let
|
2014-10-20 01:34:53 +02:00
|
|
|
|
pathSafeName = lib.replaceChars ["@" "\\"] ["-" "-"] name;
|
2014-10-19 17:18:50 +02:00
|
|
|
|
in
|
2014-03-12 18:40:28 +01:00
|
|
|
|
if unit.enable then
|
2014-10-19 17:18:50 +02:00
|
|
|
|
pkgs.runCommand "unit-${pathSafeName}" { preferLocalBuild = true; inherit (unit) text; }
|
2014-03-12 18:40:28 +01:00
|
|
|
|
''
|
|
|
|
|
mkdir -p $out
|
2014-06-09 21:41:07 +02:00
|
|
|
|
echo -n "$text" > $out/${shellEscape name}
|
2014-03-12 18:40:28 +01:00
|
|
|
|
''
|
|
|
|
|
else
|
2014-10-19 17:18:50 +02:00
|
|
|
|
pkgs.runCommand "unit-${pathSafeName}-disabled" { preferLocalBuild = true; }
|
2014-03-12 18:40:28 +01:00
|
|
|
|
''
|
|
|
|
|
mkdir -p $out
|
2014-06-09 21:41:07 +02:00
|
|
|
|
ln -s /dev/null $out/${shellEscape name}
|
2014-03-12 18:40:28 +01:00
|
|
|
|
'';
|
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"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"graphical.target"
|
|
|
|
|
"multi-user.target"
|
|
|
|
|
"network.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"
|
2012-08-11 00:56:12 +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"
|
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Consoles.
|
|
|
|
|
"getty.target"
|
|
|
|
|
"getty@.service"
|
|
|
|
|
"serial-getty@.service"
|
|
|
|
|
"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"
|
2012-10-18 17:54:07 +02:00
|
|
|
|
#"systemd-vconsole-setup.service"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"systemd-user-sessions.service"
|
2012-06-15 19:09:22 +02:00
|
|
|
|
"dbus-org.freedesktop.login1.service"
|
2014-04-16 10:48:14 +02:00
|
|
|
|
"dbus-org.freedesktop.machine1.service"
|
2012-06-15 20:51:48 +02:00
|
|
|
|
"user@.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"
|
2014-04-17 19:05:29 +02:00
|
|
|
|
"systemd-journal-gatewayd.socket"
|
|
|
|
|
"systemd-journal-gatewayd.service"
|
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
|
|
|
|
|
2012-06-15 00:44:56 +02:00
|
|
|
|
# SysV init compatibility.
|
|
|
|
|
"systemd-initctl.socket"
|
|
|
|
|
"systemd-initctl.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
|
|
|
|
|
2014-11-13 22:33:55 +01:00
|
|
|
|
# Networking
|
|
|
|
|
"systemd-networkd.service"
|
2014-11-19 22:11:30 +01:00
|
|
|
|
"systemd-networkd-wait-online.service"
|
|
|
|
|
"systemd-resolved.service"
|
|
|
|
|
"systemd-timesyncd.service"
|
2014-11-13 22:33:55 +01: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-16 00:59:26 +02:00
|
|
|
|
"proc-sys-fs-binfmt_misc.mount"
|
2014-04-28 09:13:57 +02:00
|
|
|
|
"sys-fs-fuse-connections.mount"
|
|
|
|
|
"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"
|
|
|
|
|
"systemd-rfkill@.service"
|
2014-04-16 00:59:26 +02:00
|
|
|
|
|
2012-06-15 00:44:56 +02:00
|
|
|
|
# Hibernate / suspend.
|
|
|
|
|
"hibernate.target"
|
|
|
|
|
"suspend.target"
|
|
|
|
|
"sleep.target"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"hybrid-sleep.target"
|
2012-07-20 21:40:50 +02:00
|
|
|
|
"systemd-hibernate.service"
|
|
|
|
|
"systemd-suspend.service"
|
2013-03-27 13:58:12 +01:00
|
|
|
|
"systemd-hybrid-sleep.service"
|
2012-07-20 21:40:50 +02:00
|
|
|
|
"systemd-shutdownd.socket"
|
|
|
|
|
"systemd-shutdownd.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
|
|
|
|
"ctrl-alt-del.target"
|
|
|
|
|
"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"
|
|
|
|
|
"-.slice"
|
|
|
|
|
"system.slice"
|
|
|
|
|
"user.slice"
|
|
|
|
|
"machine.slice"
|
|
|
|
|
"systemd-machined.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"
|
2013-01-21 21:01:48 +01:00
|
|
|
|
]
|
|
|
|
|
|
2014-07-25 20:05:57 +02:00
|
|
|
|
++ cfg.additionalUpstreamSystemUnits;
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
upstreamSystemWants =
|
2013-03-27 13:58:12 +01:00
|
|
|
|
[ #"basic.target.wants"
|
2012-06-15 00:44:56 +02:00
|
|
|
|
"sysinit.target.wants"
|
|
|
|
|
"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"
|
|
|
|
|
"default.target"
|
|
|
|
|
"exit.target"
|
|
|
|
|
"paths.target"
|
|
|
|
|
"shutdown.target"
|
|
|
|
|
"sockets.target"
|
|
|
|
|
"systemd-exit.service"
|
|
|
|
|
"timers.target"
|
|
|
|
|
];
|
|
|
|
|
|
2014-06-09 21:41:07 +02:00
|
|
|
|
shellEscape = s: (replaceChars [ "\\" ] [ "\\\\" ] s);
|
|
|
|
|
|
2012-10-15 22:01:30 +02:00
|
|
|
|
makeJobScript = name: text:
|
2014-06-09 21:41:07 +02:00
|
|
|
|
let x = pkgs.writeTextFile { name = "unit-script"; executable = true; destination = "/bin/${shellEscape name}"; inherit text; };
|
|
|
|
|
in "${x}/bin/${shellEscape name}";
|
2012-07-19 23:41:42 +02:00
|
|
|
|
|
2012-10-09 21:14:15 +02:00
|
|
|
|
unitConfig = { name, config, ... }: {
|
|
|
|
|
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 != "") {
|
2012-10-09 21:14:15 +02:00
|
|
|
|
Description = config.description;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
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.
|
2013-11-18 15:45:24 +01:00
|
|
|
|
path =
|
|
|
|
|
[ 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 != "")
|
|
|
|
|
{ serviceConfig.ExecStartPre = makeJobScript "${name}-pre-start" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.preStart}
|
|
|
|
|
'';
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.script != "")
|
|
|
|
|
{ serviceConfig.ExecStart = makeJobScript "${name}-start" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.script}
|
|
|
|
|
'' + " " + config.scriptArgs;
|
|
|
|
|
})
|
|
|
|
|
(mkIf (config.postStart != "")
|
|
|
|
|
{ serviceConfig.ExecStartPost = makeJobScript "${name}-post-start" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.postStart}
|
|
|
|
|
'';
|
|
|
|
|
})
|
2014-09-16 05:03:20 +02:00
|
|
|
|
(mkIf (config.reload != "")
|
|
|
|
|
{ serviceConfig.ExecReload = makeJobScript "${name}-reload" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.reload}
|
|
|
|
|
'';
|
|
|
|
|
})
|
2013-11-26 18:24:55 +01:00
|
|
|
|
(mkIf (config.preStop != "")
|
|
|
|
|
{ serviceConfig.ExecStop = makeJobScript "${name}-pre-stop" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.preStop}
|
|
|
|
|
'';
|
|
|
|
|
})
|
2013-11-18 15:45:24 +01:00
|
|
|
|
(mkIf (config.postStop != "")
|
|
|
|
|
{ serviceConfig.ExecStopPost = makeJobScript "${name}-post-stop" ''
|
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${config.postStop}
|
|
|
|
|
'';
|
|
|
|
|
})
|
|
|
|
|
];
|
2012-08-06 17:45:59 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-12-28 13:29:53 +01:00
|
|
|
|
mountConfig = { name, config, ... }: {
|
|
|
|
|
config = {
|
|
|
|
|
mountConfig =
|
|
|
|
|
{ What = config.what;
|
|
|
|
|
Where = config.where;
|
|
|
|
|
} // optionalAttrs (config.type != "") {
|
|
|
|
|
Type = config.type;
|
|
|
|
|
} // optionalAttrs (config.options != "") {
|
|
|
|
|
Options = config.options;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2013-09-23 22:56:05 +02:00
|
|
|
|
automountConfig = { name, config, ... }: {
|
|
|
|
|
config = {
|
|
|
|
|
automountConfig =
|
|
|
|
|
{ Where = config.where;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2012-10-01 22:27:42 +02:00
|
|
|
|
toOption = x:
|
|
|
|
|
if x == true then "true"
|
|
|
|
|
else if x == false then "false"
|
|
|
|
|
else toString x;
|
|
|
|
|
|
|
|
|
|
attrsToSection = as:
|
|
|
|
|
concatStrings (concatLists (mapAttrsToList (name: value:
|
|
|
|
|
map (x: ''
|
|
|
|
|
${name}=${toOption x}
|
|
|
|
|
'')
|
|
|
|
|
(if isList value then value else [value]))
|
|
|
|
|
as));
|
|
|
|
|
|
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:
|
2013-04-19 22:28:00 +02:00
|
|
|
|
{ inherit (def) 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:
|
2013-04-19 22:28:00 +02:00
|
|
|
|
{ inherit (def) 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:
|
2014-10-05 00:03:52 +02:00
|
|
|
|
let s = "Environment=\"${n}=${env.${n}}\"\n";
|
2014-07-30 10:28:05 +02:00
|
|
|
|
in if stringLength s >= 2048 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:
|
2013-04-19 22:28:00 +02:00
|
|
|
|
{ inherit (def) 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)}
|
2012-10-02 00:58:11 +02:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-02 01:03:13 +01:00
|
|
|
|
timerToUnit = name: def:
|
2013-04-19 22:28:00 +02:00
|
|
|
|
{ inherit (def) 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:
|
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
|
|
|
|
text = commonUnitText def +
|
|
|
|
|
''
|
|
|
|
|
[Path]
|
|
|
|
|
${attrsToSection def.pathConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-28 13:29:53 +01:00
|
|
|
|
mountToUnit = name: def:
|
2013-04-19 22:28:00 +02:00
|
|
|
|
{ inherit (def) 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:
|
|
|
|
|
{ inherit (def) 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}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-13 22:33:55 +01:00
|
|
|
|
commonMatchText = def: ''
|
|
|
|
|
[Match]
|
|
|
|
|
${attrsToSection def.matchConfig}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
linkToUnit = name: def:
|
|
|
|
|
{ inherit (def) enable;
|
|
|
|
|
text = commonMatchText def +
|
|
|
|
|
''
|
|
|
|
|
[Link]
|
|
|
|
|
${attrsToSection def.linkConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
netdevToUnit = name: def:
|
|
|
|
|
{ inherit (def) enable;
|
|
|
|
|
text = commonMatchText def +
|
|
|
|
|
''
|
|
|
|
|
[NetDev]
|
|
|
|
|
${attrsToSection def.netdevConfig}
|
|
|
|
|
|
|
|
|
|
${optionalString (def.vlanConfig != { }) ''
|
|
|
|
|
[VLAN]
|
|
|
|
|
${attrsToSection def.vlanConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.macvlanConfig != { }) ''
|
|
|
|
|
[MACVLAN]
|
|
|
|
|
${attrsToSection def.macvlanConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.vxlanConfig != { }) ''
|
|
|
|
|
[VXLAN]
|
|
|
|
|
${attrsToSection def.vxlanConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.tunnelConfig != { }) ''
|
|
|
|
|
[Tunnel]
|
|
|
|
|
${attrsToSection def.tunnelConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.peerConfig != { }) ''
|
|
|
|
|
[Peer]
|
|
|
|
|
${attrsToSection def.peerConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.tunConfig != { }) ''
|
|
|
|
|
[Tun]
|
|
|
|
|
${attrsToSection def.tunConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.tapConfig != { }) ''
|
|
|
|
|
[Tap]
|
|
|
|
|
${attrsToSection def.tapConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${optionalString (def.bondConfig != { }) ''
|
|
|
|
|
[Bond]
|
|
|
|
|
${attrsToSection def.bondConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networkToUnit = name: def:
|
|
|
|
|
{ inherit (def) enable;
|
|
|
|
|
text = commonMatchText def +
|
|
|
|
|
''
|
|
|
|
|
[Network]
|
|
|
|
|
${attrsToSection def.networkConfig}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "Address=${s}") def.address)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "Gateway=${s}") def.gateway)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "DNS=${s}") def.dns)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "NTP=${s}") def.ntp)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "VLAN=${s}") def.vlan)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "MACVLAN=${s}") def.macvlan)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "VXLAN=${s}") def.vxlan)}
|
|
|
|
|
${concatStringsSep "\n" (map (s: "Tunnel=${s}") def.tunnel)}
|
|
|
|
|
|
|
|
|
|
${optionalString (def.dhcpConfig != { }) ''
|
|
|
|
|
[DHCP]
|
|
|
|
|
${attrsToSection def.dhcpConfig}
|
|
|
|
|
|
|
|
|
|
''}
|
|
|
|
|
${flip concatMapStrings def.addresses (x: ''
|
|
|
|
|
[Address]
|
|
|
|
|
${attrsToSection x.addressConfig}
|
|
|
|
|
|
|
|
|
|
'')}
|
|
|
|
|
${flip concatMapStrings def.routes (x: ''
|
|
|
|
|
[Route]
|
|
|
|
|
${attrsToSection x.routeConfig}
|
|
|
|
|
|
|
|
|
|
'')}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
generateUnits = type: units: upstreamUnits: upstreamWants:
|
|
|
|
|
pkgs.runCommand "${type}-units" { preferLocalBuild = true; } ''
|
2012-07-19 23:32:50 +02:00
|
|
|
|
mkdir -p $out
|
2014-04-17 18:52:31 +02:00
|
|
|
|
|
|
|
|
|
# Copy the upstream systemd units we're interested in.
|
2012-06-02 02:15:07 +02:00
|
|
|
|
for i in ${toString upstreamUnits}; do
|
2014-04-18 00:38:40 +02:00
|
|
|
|
fn=${systemd}/example/systemd/${type}/$i
|
2012-08-11 00:56:12 +02:00
|
|
|
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
2012-06-15 00:44:56 +02:00
|
|
|
|
if [ -L $fn ]; then
|
2014-04-18 17:38:06 +02:00
|
|
|
|
target="$(readlink "$fn")"
|
|
|
|
|
if [ ''${target:0:3} = ../ ]; then
|
|
|
|
|
ln -s "$(readlink -f "$fn")" $out/
|
|
|
|
|
else
|
|
|
|
|
cp -pd $fn $out/
|
|
|
|
|
fi
|
2012-06-15 00:44:56 +02:00
|
|
|
|
else
|
2012-07-19 23:32:50 +02:00
|
|
|
|
ln -s $fn $out/
|
2012-06-15 00:44:56 +02:00
|
|
|
|
fi
|
2012-06-02 02:15:07 +02:00
|
|
|
|
done
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Copy .wants links, but only those that point to units that
|
|
|
|
|
# we're interested in.
|
2012-06-15 00:44:56 +02:00
|
|
|
|
for i in ${toString upstreamWants}; do
|
2014-04-18 00:38:40 +02:00
|
|
|
|
fn=${systemd}/example/systemd/${type}/$i
|
2012-08-11 00:56:12 +02:00
|
|
|
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
2012-07-19 23:32:50 +02:00
|
|
|
|
x=$out/$(basename $fn)
|
2012-06-15 00:44:56 +02:00
|
|
|
|
mkdir $x
|
|
|
|
|
for i in $fn/*; do
|
|
|
|
|
y=$x/$(basename $i)
|
|
|
|
|
cp -pd $i $y
|
2014-04-17 18:52:31 +02:00
|
|
|
|
if ! [ -e $y ]; then rm $y; fi
|
2012-06-15 00:44:56 +02:00
|
|
|
|
done
|
|
|
|
|
done
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Symlink all units provided listed in systemd.packages.
|
|
|
|
|
for i in ${toString cfg.packages}; do
|
2014-04-22 15:36:04 +02:00
|
|
|
|
for fn in $i/etc/systemd/${type}/* $i/lib/systemd/${type}/*; do
|
|
|
|
|
if ! [[ "$fn" =~ .wants$ ]]; then
|
|
|
|
|
ln -s $fn $out/
|
|
|
|
|
fi
|
|
|
|
|
done
|
2012-06-02 02:15:07 +02:00
|
|
|
|
done
|
2012-06-18 05:31:21 +02:00
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Symlink all units defined by systemd.units. If these are also
|
|
|
|
|
# provided by systemd or systemd.packages, then add them as
|
|
|
|
|
# <unit-name>.d/overrides.conf, which makes them extend the
|
|
|
|
|
# upstream unit.
|
2014-04-18 00:38:40 +02:00
|
|
|
|
for i in ${toString (mapAttrsToList (n: v: v.unit) units)}; do
|
2014-04-17 18:52:31 +02:00
|
|
|
|
fn=$(basename $i/*)
|
|
|
|
|
if [ -e $out/$fn ]; then
|
|
|
|
|
if [ "$(readlink -f $i/$fn)" = /dev/null ]; then
|
|
|
|
|
ln -sfn /dev/null $out/$fn
|
|
|
|
|
else
|
|
|
|
|
mkdir $out/$fn.d
|
|
|
|
|
ln -s $i/$fn $out/$fn.d/overrides.conf
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
ln -fs $i/$fn $out/
|
|
|
|
|
fi
|
2012-08-21 17:28:47 +02:00
|
|
|
|
done
|
|
|
|
|
|
2014-04-17 18:52:31 +02:00
|
|
|
|
# Created .wants and .requires symlinks from the wantedBy and
|
|
|
|
|
# requiredBy options.
|
2012-06-18 05:31:21 +02:00
|
|
|
|
${concatStrings (mapAttrsToList (name: unit:
|
|
|
|
|
concatMapStrings (name2: ''
|
2013-11-12 16:58:36 +01:00
|
|
|
|
mkdir -p $out/'${name2}.wants'
|
|
|
|
|
ln -sfn '../${name}' $out/'${name2}.wants'/
|
2014-04-18 00:38:40 +02:00
|
|
|
|
'') unit.wantedBy) units)}
|
2012-06-18 05:31:21 +02:00
|
|
|
|
|
2013-04-19 22:28:00 +02:00
|
|
|
|
${concatStrings (mapAttrsToList (name: unit:
|
|
|
|
|
concatMapStrings (name2: ''
|
2013-11-12 16:58:36 +01:00
|
|
|
|
mkdir -p $out/'${name2}.requires'
|
|
|
|
|
ln -sfn '../${name}' $out/'${name2}.requires'/
|
2014-04-18 00:38:40 +02:00
|
|
|
|
'') unit.requiredBy) units)}
|
2013-04-19 22:28:00 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
${optionalString (type == "system") ''
|
|
|
|
|
# Stupid misc. symlinks.
|
|
|
|
|
ln -s ${cfg.defaultUnit} $out/default.target
|
2012-07-21 00:32:24 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
ln -s rescue.target $out/kbrequest.target
|
2013-01-08 18:24:06 +01:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
mkdir -p $out/getty.target.wants/
|
|
|
|
|
ln -s ../autovt@tty1.service $out/getty.target.wants/
|
2013-01-24 14:55:55 +01:00
|
|
|
|
|
2014-11-19 22:11:30 +01:00
|
|
|
|
ln -s ../local-fs.target ../remote-fs.target ../network.target \
|
|
|
|
|
../nss-lookup.target ../nss-user-lookup.target ../swap.target \
|
|
|
|
|
$out/multi-user.target.wants/
|
2014-04-18 00:38:40 +02:00
|
|
|
|
''}
|
2012-06-02 02:15:07 +02:00
|
|
|
|
''; # */
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
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;
|
|
|
|
|
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 = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2013-11-18 13:18:58 +01:00
|
|
|
|
options = { 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
|
|
|
|
};
|
2012-06-18 05:31:21 +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;
|
|
|
|
|
description = "Packages providing systemd units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.targets = mkOption {
|
2012-10-02 00:58:11 +02:00
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2014-04-17 23:35:05 +02:00
|
|
|
|
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 = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2012-10-09 21:14:15 +02:00
|
|
|
|
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 = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2012-10-09 21:14:15 +02:00
|
|
|
|
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 = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ timerOptions unitConfig ];
|
|
|
|
|
description = "Definition of systemd timer units.";
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-31 12:23:27 +02:00
|
|
|
|
systemd.paths = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ pathOptions unitConfig ];
|
|
|
|
|
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 = [];
|
|
|
|
|
type = types.listOf types.optionSet;
|
|
|
|
|
options = [ mountOptions unitConfig mountConfig ];
|
|
|
|
|
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 = [];
|
|
|
|
|
type = types.listOf types.optionSet;
|
|
|
|
|
options = [ automountOptions unitConfig automountConfig ];
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-13 22:33:55 +01:00
|
|
|
|
systemd.network.enable = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to enable networkd or not.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.network.links = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ linkOptions ];
|
|
|
|
|
description = "Definiton of systemd network links.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.network.netdevs = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ netdevOptions ];
|
|
|
|
|
description = "Definiton of systemd network devices.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.network.networks = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ networkOptions ];
|
|
|
|
|
description = "Definiton of systemd networks.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.network.units = mkOption {
|
|
|
|
|
description = "Definition of networkd units.";
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = { name, config, ... }:
|
|
|
|
|
{ options = concreteUnitOptions;
|
|
|
|
|
config = {
|
|
|
|
|
unit = mkDefault (makeUnit name config);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.globalEnvironment = mkOption {
|
2012-10-30 17:27:14 +01:00
|
|
|
|
type = types.attrs;
|
|
|
|
|
default = {};
|
|
|
|
|
example = { TZ = "CET"; };
|
|
|
|
|
description = ''
|
|
|
|
|
Environment variables passed to <emphasis>all</emphasis> systemd units.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
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 {
|
|
|
|
|
default = "10s";
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.journald.rateLimitBurst = mkOption {
|
|
|
|
|
default = 100;
|
|
|
|
|
type = types.uniq types.int;
|
|
|
|
|
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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-24 11:54:01 +01:00
|
|
|
|
services.logind.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
2013-11-15 21:56:45 +01:00
|
|
|
|
type = types.lines;
|
2013-02-24 11:54:01 +01:00
|
|
|
|
example = "HandleLidSwitch=ignore";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd-logind. See man logind.conf for
|
|
|
|
|
available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-19 22:11:30 +01:00
|
|
|
|
services.resolved.enable = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Enables the systemd dns resolver daemon.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.timesyncd.enable = mkOption {
|
|
|
|
|
default = false;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Enables the systemd ntp client daemon.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
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>
|
|
|
|
|
for the exact format. You should not use this option to create
|
|
|
|
|
files required by systemd services, since there is no
|
|
|
|
|
guarantee that <command>systemd-tmpfiles</command> runs when
|
|
|
|
|
the system is reconfigured using
|
|
|
|
|
<command>nixos-rebuild</command>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
systemd.user.units = mkOption {
|
|
|
|
|
description = "Definition of systemd per-user units.";
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = { name, config, ... }:
|
|
|
|
|
{ options = concreteUnitOptions;
|
|
|
|
|
config = {
|
|
|
|
|
unit = mkDefault (makeUnit name config);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.user.services = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ serviceOptions unitConfig serviceConfig ];
|
|
|
|
|
description = "Definition of systemd per-user service units.";
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-20 20:34:21 +02:00
|
|
|
|
systemd.user.sockets = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ socketOptions unitConfig ];
|
|
|
|
|
description = "Definition of systemd per-user socket 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.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
|
|
2014-11-19 22:11:30 +01:00
|
|
|
|
config = mkMerge [ {
|
2012-06-02 02:15:07 +02:00
|
|
|
|
|
2014-04-22 23:23:05 +02:00
|
|
|
|
warnings = concatLists (mapAttrsToList (name: service:
|
|
|
|
|
optional (service.serviceConfig.Type or "" == "oneshot" && service.serviceConfig.Restart or "no" != "no")
|
|
|
|
|
"Service ‘${name}.service’ with ‘Type=oneshot’ must have ‘Restart=no’") 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
|
|
|
|
|
2012-06-02 02:15:07 +02:00
|
|
|
|
environment.systemPackages = [ systemd ];
|
2012-08-06 17:45:59 +02:00
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
environment.etc."systemd/system".source =
|
|
|
|
|
generateUnits "system" cfg.units upstreamSystemUnits upstreamSystemWants;
|
|
|
|
|
|
2014-11-13 22:33:55 +01:00
|
|
|
|
environment.etc."systemd/network".source =
|
|
|
|
|
generateUnits "network" cfg.network.units [] [];
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
environment.etc."systemd/user".source =
|
|
|
|
|
generateUnits "user" cfg.user.units upstreamUserUnits [];
|
2013-05-09 16:21:42 +02:00
|
|
|
|
|
|
|
|
|
environment.etc."systemd/system.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Manager]
|
2013-11-15 19:49:01 +01:00
|
|
|
|
${config.systemd.extraConfig}
|
2013-05-09 16:21:42 +02:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/journald.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Journal]
|
|
|
|
|
RateLimitInterval=${config.services.journald.rateLimitInterval}
|
|
|
|
|
RateLimitBurst=${toString config.services.journald.rateLimitBurst}
|
|
|
|
|
${optionalString (config.services.journald.console != "") ''
|
|
|
|
|
ForwardToConsole=yes
|
|
|
|
|
TTYPath=${config.services.journald.console}
|
|
|
|
|
''}
|
2013-11-29 11:57:42 +01:00
|
|
|
|
${config.services.journald.extraConfig}
|
2013-05-09 16:21:42 +02:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/logind.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Login]
|
|
|
|
|
${config.services.logind.extraConfig}
|
|
|
|
|
'';
|
2012-06-15 00:44:56 +02:00
|
|
|
|
|
2013-05-09 16:25:24 +02:00
|
|
|
|
environment.etc."systemd/sleep.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Sleep]
|
|
|
|
|
'';
|
|
|
|
|
|
2013-07-19 21:18:44 +02:00
|
|
|
|
system.activationScripts.systemd = stringAfter [ "groups" ]
|
2012-11-29 18:51:44 +01:00
|
|
|
|
''
|
2013-07-20 17:07:26 +02:00
|
|
|
|
mkdir -m 0755 -p /var/lib/udev
|
|
|
|
|
mkdir -p /var/log/journal
|
|
|
|
|
chmod 0755 /var/log/journal
|
2012-11-29 18:51:44 +01:00
|
|
|
|
|
2013-07-19 21:18:44 +02:00
|
|
|
|
# Make all journals readable to users in the wheel and adm
|
|
|
|
|
# groups, in addition to those in the systemd-journal group.
|
|
|
|
|
# Users can always read their own journals.
|
2014-08-18 14:21:45 +02:00
|
|
|
|
${pkgs.acl}/bin/setfacl -nm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal || true
|
2012-11-29 18:51:44 +01:00
|
|
|
|
'';
|
|
|
|
|
|
2012-11-01 23:32:12 +01:00
|
|
|
|
# Target for ‘charon send-keys’ to hook into.
|
2014-02-11 13:00:10 +01:00
|
|
|
|
users.extraGroups.keys.gid = config.ids.gids.keys;
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.units =
|
2013-01-08 18:24:06 +01:00
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.targets
|
2012-10-02 00:58:11 +02:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
2012-12-28 13:29:53 +01:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
2013-03-02 01:03:13 +01:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
|
2014-03-31 12:23:27 +02:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.path" (pathToUnit n v)) cfg.paths
|
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-11-13 22:33:55 +01:00
|
|
|
|
systemd.network.units =
|
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.link" (linkToUnit n v)) cfg.network.links
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.netdev" (netdevToUnit n v)) cfg.network.netdevs
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.network" (networkToUnit n v)) cfg.network.networks;
|
|
|
|
|
|
2014-04-18 00:38:40 +02:00
|
|
|
|
systemd.user.units =
|
2014-06-20 20:34:21 +02:00
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.user.services
|
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.user.sockets;
|
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"
|
|
|
|
|
"SYSFS" "PROC_FS" "FHANDLE" "DMIID" "AUTOFS4_FS" "TMPFS_POSIX_ACL"
|
|
|
|
|
"TMPFS_XATTR" "SECCOMP"
|
|
|
|
|
];
|
2012-11-29 18:51:44 +01:00
|
|
|
|
|
2012-11-30 16:12:04 +01:00
|
|
|
|
environment.shellAliases =
|
|
|
|
|
{ start = "systemctl start";
|
|
|
|
|
stop = "systemctl stop";
|
|
|
|
|
restart = "systemctl restart";
|
|
|
|
|
status = "systemctl status";
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-19 21:18:44 +02:00
|
|
|
|
users.extraGroups.systemd-journal.gid = config.ids.gids.systemd-journal;
|
2014-02-01 14:50:20 +01:00
|
|
|
|
users.extraUsers.systemd-journal-gateway.uid = config.ids.uids.systemd-journal-gateway;
|
|
|
|
|
users.extraGroups.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;
|
|
|
|
|
})
|
|
|
|
|
(filterAttrs (name: service: service.startAt != "") cfg.services);
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-17 13:23:06 +02:00
|
|
|
|
environment.etc."tmpfiles.d/x11.conf".source = "${systemd}/example/tmpfiles.d/x11.conf";
|
|
|
|
|
|
2014-04-17 16:10:48 +02:00
|
|
|
|
environment.etc."tmpfiles.d/nixos.conf".text =
|
|
|
|
|
''
|
|
|
|
|
# This file is created automatically and should not be modified.
|
|
|
|
|
# Please change the option ‘systemd.tmpfiles.rules’ instead.
|
|
|
|
|
${concatStringsSep "\n" cfg.tmpfiles.rules}
|
|
|
|
|
'';
|
|
|
|
|
|
2014-05-20 11:10:20 +02:00
|
|
|
|
systemd.services."user@".restartIfChanged = false;
|
|
|
|
|
|
2014-07-11 23:33:40 +02:00
|
|
|
|
systemd.services.systemd-remount-fs.restartIfChanged = false;
|
2014-07-17 20:59:25 +02:00
|
|
|
|
systemd.services.systemd-journal-flush.restartIfChanged = false;
|
2014-07-11 23:33:40 +02:00
|
|
|
|
|
2014-11-19 22:11:30 +01:00
|
|
|
|
}
|
|
|
|
|
(mkIf config.systemd.network.enable {
|
|
|
|
|
users.extraUsers.systemd-network.uid = config.ids.uids.systemd-network;
|
|
|
|
|
users.extraGroups.systemd-network.gid = config.ids.gids.systemd-network;
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-networkd = {
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
restartTriggers = [ config.environment.etc."systemd/network".source ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-networkd-wait-online.wantedBy = [ "network-online.target" ];
|
|
|
|
|
|
|
|
|
|
systemd.services."systemd-network-wait-online@" = {
|
|
|
|
|
description = "Wait for Network Interface %I to be Configured";
|
|
|
|
|
conflicts = [ "shutdown.target" ];
|
|
|
|
|
requisite = [ "systemd-networkd.service" ];
|
|
|
|
|
after = [ "systemd-networkd.service" ];
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
RemainAfterExit = true;
|
|
|
|
|
ExecStart = "${config.systemd.package}/lib/systemd/systemd-networkd-wait-online -i %I";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services.resolved.enable = mkDefault true;
|
|
|
|
|
services.timesyncd.enable = mkDefault config.services.ntp.enable;
|
|
|
|
|
})
|
|
|
|
|
(mkIf config.services.resolved.enable {
|
|
|
|
|
users.extraUsers.systemd-resolve.uid = config.ids.uids.systemd-resolve;
|
|
|
|
|
users.extraGroups.systemd-resolve.gid = config.ids.gids.systemd-resolve;
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-resolved = {
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
restartTriggers = [ config.environment.etc."systemd/resolved.conf".source ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/resolved.conf".text = ''
|
|
|
|
|
[Resolve]
|
|
|
|
|
DNS=${concatStringsSep " " config.networking.nameservers}
|
|
|
|
|
'';
|
|
|
|
|
})
|
|
|
|
|
(mkIf config.services.timesyncd.enable {
|
|
|
|
|
users.extraUsers.systemd-timesync.uid = config.ids.uids.systemd-timesync;
|
|
|
|
|
users.extraGroups.systemd-timesync.gid = config.ids.gids.systemd-timesync;
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-timesyncd = {
|
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
|
|
|
|
restartTriggers = [ config.environment.etc."systemd/timesyncd.conf".source ];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/timesyncd.conf".text = ''
|
|
|
|
|
[Time]
|
|
|
|
|
NTP=${concatStringsSep " " config.services.ntp.servers}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
systemd.services.ntpd.enable = false;
|
|
|
|
|
})
|
|
|
|
|
];
|
2012-06-02 02:15:07 +02:00
|
|
|
|
}
|