2013-01-01 13:42:43 +00:00
|
|
|
|
{ config, pkgs, utils, ... }:
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2013-01-01 13:42:43 +00:00
|
|
|
|
with utils;
|
2012-08-06 16:45:59 +01:00
|
|
|
|
with import ./systemd-unit-options.nix { inherit config pkgs; };
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
cfg = config.systemd;
|
2012-06-18 04:31:21 +01:00
|
|
|
|
|
2013-01-16 12:17:57 +00:00
|
|
|
|
systemd = cfg.package;
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
2012-06-18 04:31:21 +01:00
|
|
|
|
makeUnit = name: unit:
|
2013-06-20 18:39:09 +01:00
|
|
|
|
pkgs.runCommand "unit" { inherit (unit) text; preferLocalBuild = true; }
|
2012-10-29 20:01:36 +00:00
|
|
|
|
(if unit.enable then ''
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
echo -n "$text" > $out/${name}
|
|
|
|
|
'' else ''
|
|
|
|
|
mkdir -p $out
|
|
|
|
|
ln -s /dev/null $out/${name}
|
|
|
|
|
'');
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
|
|
|
|
upstreamUnits =
|
2012-06-14 23:44:56 +01:00
|
|
|
|
[ # Targets.
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"basic.target"
|
2013-01-08 16:26:51 +00:00
|
|
|
|
"sysinit.target"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"sockets.target"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"graphical.target"
|
|
|
|
|
"multi-user.target"
|
|
|
|
|
"getty.target"
|
|
|
|
|
"network.target"
|
2013-07-16 10:55:12 +01:00
|
|
|
|
"network-online.target"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"nss-lookup.target"
|
|
|
|
|
"nss-user-lookup.target"
|
|
|
|
|
"time-sync.target"
|
2012-08-10 23:56:12 +01:00
|
|
|
|
#"cryptsetup.target"
|
2012-08-14 23:14:48 +01:00
|
|
|
|
"sigpwr.target"
|
2013-03-27 12:58:12 +00:00
|
|
|
|
"timers.target"
|
|
|
|
|
"paths.target"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
|
2013-01-21 20:01:48 +00:00
|
|
|
|
# Rescue mode.
|
2013-01-08 17:24:06 +00:00
|
|
|
|
"rescue.target"
|
|
|
|
|
"rescue.service"
|
|
|
|
|
|
2012-06-15 18:09:22 +01:00
|
|
|
|
# Udev.
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"systemd-udevd-control.socket"
|
|
|
|
|
"systemd-udevd-kernel.socket"
|
|
|
|
|
"systemd-udevd.service"
|
2012-06-15 18:09:22 +01:00
|
|
|
|
"systemd-udev-settle.service"
|
|
|
|
|
"systemd-udev-trigger.service"
|
|
|
|
|
|
2012-08-14 23:14:48 +01:00
|
|
|
|
# Hardware (started by udev when a relevant device is plugged in).
|
|
|
|
|
"sound.target"
|
|
|
|
|
"bluetooth.target"
|
|
|
|
|
"printer.target"
|
|
|
|
|
"smartcard.target"
|
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
# Login stuff.
|
|
|
|
|
"systemd-logind.service"
|
|
|
|
|
"autovt@.service"
|
2012-10-18 16:54:07 +01:00
|
|
|
|
#"systemd-vconsole-setup.service"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"systemd-user-sessions.service"
|
2012-06-15 18:09:22 +01:00
|
|
|
|
"dbus-org.freedesktop.login1.service"
|
2012-06-15 19:51:48 +01:00
|
|
|
|
"user@.service"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
|
|
|
|
|
# Journal.
|
|
|
|
|
"systemd-journald.socket"
|
|
|
|
|
"systemd-journald.service"
|
2012-07-20 17:02:42 +01:00
|
|
|
|
"systemd-journal-flush.service"
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"syslog.socket"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
# SysV init compatibility.
|
|
|
|
|
"systemd-initctl.socket"
|
|
|
|
|
"systemd-initctl.service"
|
|
|
|
|
|
|
|
|
|
# Random seed.
|
|
|
|
|
"systemd-random-seed-load.service"
|
|
|
|
|
"systemd-random-seed-save.service"
|
|
|
|
|
|
|
|
|
|
# Utmp maintenance.
|
|
|
|
|
"systemd-update-utmp-shutdown.service"
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-08-06 21:52:08 +01:00
|
|
|
|
# Kernel module loading.
|
2012-10-11 22:58:46 +01:00
|
|
|
|
#"systemd-modules-load.service"
|
2012-08-06 21:52:08 +01:00
|
|
|
|
|
2012-06-02 01:15:07 +01:00
|
|
|
|
# Filesystems.
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"systemd-fsck@.service"
|
|
|
|
|
"systemd-fsck-root.service"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"systemd-remount-fs.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"local-fs.target"
|
|
|
|
|
"local-fs-pre.target"
|
|
|
|
|
"remote-fs.target"
|
|
|
|
|
"remote-fs-pre.target"
|
|
|
|
|
"swap.target"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"dev-hugepages.mount"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"dev-mqueue.mount"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"sys-fs-fuse-connections.mount"
|
|
|
|
|
"sys-kernel-config.mount"
|
|
|
|
|
"sys-kernel-debug.mount"
|
|
|
|
|
|
|
|
|
|
# Hibernate / suspend.
|
|
|
|
|
"hibernate.target"
|
|
|
|
|
"suspend.target"
|
|
|
|
|
"sleep.target"
|
2013-03-27 12:58:12 +00:00
|
|
|
|
"hybrid-sleep.target"
|
2012-07-20 20:40:50 +01:00
|
|
|
|
"systemd-hibernate.service"
|
|
|
|
|
"systemd-suspend.service"
|
2013-03-27 12:58:12 +00:00
|
|
|
|
"systemd-hybrid-sleep.service"
|
2012-07-20 20:40:50 +01:00
|
|
|
|
"systemd-shutdownd.socket"
|
|
|
|
|
"systemd-shutdownd.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
|
|
|
|
|
# Reboot stuff.
|
|
|
|
|
"reboot.target"
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"systemd-reboot.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"poweroff.target"
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"systemd-poweroff.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"halt.target"
|
2012-07-16 22:47:11 +01:00
|
|
|
|
"systemd-halt.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
"ctrl-alt-del.target"
|
|
|
|
|
"shutdown.target"
|
|
|
|
|
"umount.target"
|
|
|
|
|
"final.target"
|
2012-08-14 23:14:48 +01:00
|
|
|
|
"kexec.target"
|
2013-09-16 16:15:42 +01:00
|
|
|
|
"systemd-kexec.service"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
|
2012-06-19 22:02:54 +01:00
|
|
|
|
# Password entry.
|
|
|
|
|
"systemd-ask-password-console.path"
|
|
|
|
|
"systemd-ask-password-console.service"
|
|
|
|
|
"systemd-ask-password-wall.path"
|
|
|
|
|
"systemd-ask-password-wall.service"
|
2013-01-21 20:01:48 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
++ optionals cfg.enableEmergencyMode [
|
|
|
|
|
"emergency.target"
|
|
|
|
|
"emergency.service"
|
2012-06-02 01:15:07 +01:00
|
|
|
|
];
|
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
upstreamWants =
|
2013-03-27 12:58:12 +00:00
|
|
|
|
[ #"basic.target.wants"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
"sysinit.target.wants"
|
|
|
|
|
"sockets.target.wants"
|
|
|
|
|
"local-fs.target.wants"
|
|
|
|
|
"multi-user.target.wants"
|
|
|
|
|
"shutdown.target.wants"
|
2013-03-27 12:58:12 +00:00
|
|
|
|
"timers.target.wants"
|
2012-06-14 23:44:56 +01:00
|
|
|
|
];
|
|
|
|
|
|
2012-10-15 21:01:30 +01:00
|
|
|
|
makeJobScript = name: text:
|
|
|
|
|
let x = pkgs.writeTextFile { name = "unit-script"; executable = true; destination = "/bin/${name}"; inherit text; };
|
|
|
|
|
in "${x}/bin/${name}";
|
2012-07-19 22:41:42 +01:00
|
|
|
|
|
2012-10-09 20:14:15 +01:00
|
|
|
|
unitConfig = { name, config, ... }: {
|
|
|
|
|
config = {
|
|
|
|
|
unitConfig =
|
|
|
|
|
{ Requires = concatStringsSep " " config.requires;
|
|
|
|
|
Wants = concatStringsSep " " config.wants;
|
|
|
|
|
After = concatStringsSep " " config.after;
|
|
|
|
|
Before = concatStringsSep " " config.before;
|
2012-10-10 21:50:41 +01:00
|
|
|
|
BindsTo = concatStringsSep " " config.bindsTo;
|
2012-10-09 20:14:15 +01:00
|
|
|
|
PartOf = concatStringsSep " " config.partOf;
|
2012-10-11 22:54:43 +01:00
|
|
|
|
"X-Restart-Triggers" = toString config.restartTriggers;
|
2012-10-09 20:14:15 +01:00
|
|
|
|
} // optionalAttrs (config.description != "") {
|
|
|
|
|
Description = config.description;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-06 16:45:59 +01:00
|
|
|
|
serviceConfig = { name, config, ... }: {
|
|
|
|
|
config = {
|
|
|
|
|
# Default path for systemd services. Should be quite minimal.
|
|
|
|
|
path =
|
|
|
|
|
[ pkgs.coreutils
|
|
|
|
|
pkgs.findutils
|
|
|
|
|
pkgs.gnugrep
|
|
|
|
|
pkgs.gnused
|
|
|
|
|
systemd
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-28 12:29:53 +00:00
|
|
|
|
mountConfig = { name, config, ... }: {
|
|
|
|
|
config = {
|
|
|
|
|
mountConfig =
|
|
|
|
|
{ What = config.what;
|
|
|
|
|
Where = config.where;
|
|
|
|
|
} // optionalAttrs (config.type != "") {
|
|
|
|
|
Type = config.type;
|
|
|
|
|
} // optionalAttrs (config.options != "") {
|
|
|
|
|
Options = config.options;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2012-10-01 21:27:42 +01: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));
|
|
|
|
|
|
2012-10-01 23:58:11 +01:00
|
|
|
|
targetToUnit = name: def:
|
2013-04-19 21:28:00 +01:00
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
2012-10-01 23:58:11 +01:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
2012-06-18 20:28:31 +01:00
|
|
|
|
|
2012-10-01 23:58:11 +01:00
|
|
|
|
serviceToUnit = name: def:
|
2013-04-19 21:28:00 +01:00
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
2012-06-18 20:28:31 +01:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
2012-10-01 21:27:42 +01:00
|
|
|
|
${attrsToSection def.unitConfig}
|
2012-06-18 20:28:31 +01:00
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
Environment=PATH=${def.path}
|
2013-01-23 10:51:58 +00:00
|
|
|
|
Environment=LD_LIBRARY_PATH=
|
2012-10-30 16:27:14 +00:00
|
|
|
|
${let env = cfg.globalEnvironment // def.environment;
|
2013-02-01 12:39:47 +00:00
|
|
|
|
in concatMapStrings (n: "Environment=\"${n}=${getAttr n env}\"\n") (attrNames env)}
|
2012-08-17 18:14:42 +01:00
|
|
|
|
${optionalString (!def.restartIfChanged) "X-RestartIfChanged=false"}
|
2013-01-05 00:05:25 +00:00
|
|
|
|
${optionalString (!def.stopIfChanged) "X-StopIfChanged=false"}
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-18 20:28:31 +01:00
|
|
|
|
${optionalString (def.preStart != "") ''
|
2012-10-15 21:01:30 +01:00
|
|
|
|
ExecStartPre=${makeJobScript "${name}-pre-start" ''
|
2012-06-18 20:28:31 +01:00
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${def.preStart}
|
|
|
|
|
''}
|
|
|
|
|
''}
|
|
|
|
|
|
|
|
|
|
${optionalString (def.script != "") ''
|
2012-10-15 21:01:30 +01:00
|
|
|
|
ExecStart=${makeJobScript "${name}-start" ''
|
2012-06-18 20:28:31 +01:00
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${def.script}
|
2013-02-15 02:50:41 +00:00
|
|
|
|
''} ${def.scriptArgs}
|
2012-06-18 20:28:31 +01:00
|
|
|
|
''}
|
|
|
|
|
|
2012-10-01 21:45:49 +01:00
|
|
|
|
${optionalString (def.postStart != "") ''
|
2012-10-15 21:01:30 +01:00
|
|
|
|
ExecStartPost=${makeJobScript "${name}-post-start" ''
|
2012-10-01 21:45:49 +01:00
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${def.postStart}
|
|
|
|
|
''}
|
|
|
|
|
''}
|
|
|
|
|
|
2012-10-10 22:55:13 +01:00
|
|
|
|
${optionalString (def.postStop != "") ''
|
2012-10-15 21:01:30 +01:00
|
|
|
|
ExecStopPost=${makeJobScript "${name}-post-stop" ''
|
2012-10-10 22:55:13 +01:00
|
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
|
${def.postStop}
|
|
|
|
|
''}
|
|
|
|
|
''}
|
|
|
|
|
|
2012-10-01 21:27:42 +01:00
|
|
|
|
${attrsToSection def.serviceConfig}
|
2012-06-18 20:28:31 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-10-01 23:58:11 +01:00
|
|
|
|
socketToUnit = name: def:
|
2013-04-19 21:28:00 +01:00
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
2012-10-01 23:58:11 +01:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
|
|
|
|
|
[Socket]
|
|
|
|
|
${attrsToSection def.socketConfig}
|
2013-05-14 15:07:55 +01:00
|
|
|
|
${concatStringsSep "\n" (map (s: "ListenStream=${s}") def.listenStreams)}
|
2012-10-01 23:58:11 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-02 00:03:13 +00:00
|
|
|
|
timerToUnit = name: def:
|
2013-04-19 21:28:00 +01:00
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
2013-03-02 00:03:13 +00:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
|
${attrsToSection def.timerConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-28 12:29:53 +00:00
|
|
|
|
mountToUnit = name: def:
|
2013-04-19 21:28:00 +01:00
|
|
|
|
{ inherit (def) wantedBy requiredBy enable;
|
2012-12-28 12:29:53 +00:00
|
|
|
|
text =
|
|
|
|
|
''
|
|
|
|
|
[Unit]
|
|
|
|
|
${attrsToSection def.unitConfig}
|
|
|
|
|
|
|
|
|
|
[Mount]
|
|
|
|
|
${attrsToSection def.mountConfig}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-18 04:31:21 +01:00
|
|
|
|
nixosUnits = mapAttrsToList makeUnit cfg.units;
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-16 05:19:43 +01:00
|
|
|
|
units = pkgs.runCommand "units" { preferLocalBuild = true; }
|
2012-06-02 01:15:07 +01:00
|
|
|
|
''
|
2012-07-19 22:32:50 +01:00
|
|
|
|
mkdir -p $out
|
2012-06-02 01:15:07 +01:00
|
|
|
|
for i in ${toString upstreamUnits}; do
|
|
|
|
|
fn=${systemd}/example/systemd/system/$i
|
2012-08-10 23:56:12 +01:00
|
|
|
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
2012-06-14 23:44:56 +01:00
|
|
|
|
if [ -L $fn ]; then
|
2012-07-19 22:32:50 +01:00
|
|
|
|
cp -pd $fn $out/
|
2012-06-14 23:44:56 +01:00
|
|
|
|
else
|
2012-07-19 22:32:50 +01:00
|
|
|
|
ln -s $fn $out/
|
2012-06-14 23:44:56 +01:00
|
|
|
|
fi
|
2012-06-02 01:15:07 +01:00
|
|
|
|
done
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
for i in ${toString upstreamWants}; do
|
|
|
|
|
fn=${systemd}/example/systemd/system/$i
|
2012-08-10 23:56:12 +01:00
|
|
|
|
if ! [ -e $fn ]; then echo "missing $fn"; false; fi
|
2012-07-19 22:32:50 +01:00
|
|
|
|
x=$out/$(basename $fn)
|
2012-06-14 23:44:56 +01:00
|
|
|
|
mkdir $x
|
|
|
|
|
for i in $fn/*; do
|
|
|
|
|
y=$x/$(basename $i)
|
|
|
|
|
cp -pd $i $y
|
|
|
|
|
if ! [ -e $y ]; then rm -v $y; fi
|
|
|
|
|
done
|
|
|
|
|
done
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
for i in ${toString nixosUnits}; do
|
2012-08-02 22:26:23 +01:00
|
|
|
|
ln -s $i/* $out/
|
2012-06-02 01:15:07 +01:00
|
|
|
|
done
|
2012-06-18 04:31:21 +01:00
|
|
|
|
|
2012-08-21 16:28:47 +01:00
|
|
|
|
for i in ${toString cfg.packages}; do
|
|
|
|
|
ln -s $i/etc/systemd/system/* $out/
|
|
|
|
|
done
|
|
|
|
|
|
2012-06-18 04:31:21 +01:00
|
|
|
|
${concatStrings (mapAttrsToList (name: unit:
|
|
|
|
|
concatMapStrings (name2: ''
|
2012-07-19 22:32:50 +01:00
|
|
|
|
mkdir -p $out/${name2}.wants
|
|
|
|
|
ln -sfn ../${name} $out/${name2}.wants/
|
2012-06-18 04:31:21 +01:00
|
|
|
|
'') unit.wantedBy) cfg.units)}
|
|
|
|
|
|
2013-04-19 21:28:00 +01:00
|
|
|
|
${concatStrings (mapAttrsToList (name: unit:
|
|
|
|
|
concatMapStrings (name2: ''
|
|
|
|
|
mkdir -p $out/${name2}.requires
|
|
|
|
|
ln -sfn ../${name} $out/${name2}.requires/
|
|
|
|
|
'') unit.requiredBy) cfg.units)}
|
|
|
|
|
|
2012-07-19 22:32:50 +01:00
|
|
|
|
ln -s ${cfg.defaultUnit} $out/default.target
|
2012-07-20 23:32:24 +01:00
|
|
|
|
|
2013-01-08 17:24:06 +00:00
|
|
|
|
ln -s rescue.target $out/kbrequest.target
|
|
|
|
|
|
2013-01-24 13:55:55 +00:00
|
|
|
|
mkdir -p $out/getty.target.wants/
|
|
|
|
|
ln -s ../getty@tty1.service $out/getty.target.wants/
|
|
|
|
|
|
2012-12-27 09:04:05 +00: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/
|
2012-06-02 01:15:07 +01:00
|
|
|
|
''; # */
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-02 01:15:07 +01:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
2013-01-16 12:17:57 +00:00
|
|
|
|
systemd.package = mkOption {
|
|
|
|
|
default = pkgs.systemd;
|
|
|
|
|
type = types.package;
|
|
|
|
|
description = "The systemd package.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.units = mkOption {
|
2012-06-18 20:28:31 +01:00
|
|
|
|
description = "Definition of systemd units.";
|
2012-06-18 04:31:21 +01:00
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = {
|
|
|
|
|
text = mkOption {
|
|
|
|
|
types = types.uniq types.string;
|
|
|
|
|
description = "Text of this systemd unit.";
|
|
|
|
|
};
|
2012-10-29 20:01:36 +00:00
|
|
|
|
enable = mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
types = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
If set to false, this unit will be a symlink to
|
|
|
|
|
/dev/null. This is primarily useful to prevent specific
|
|
|
|
|
template instances (e.g. <literal>serial-getty@ttyS0</literal>)
|
|
|
|
|
from being started.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2013-04-19 21:28:00 +01:00
|
|
|
|
requiredBy = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
types = types.listOf types.string;
|
|
|
|
|
description = "Units that require (i.e. depend on and need to go down with) this unit.";
|
|
|
|
|
};
|
2012-06-18 04:31:21 +01:00
|
|
|
|
wantedBy = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
types = types.listOf types.string;
|
|
|
|
|
description = "Units that want (i.e. depend on) this unit.";
|
|
|
|
|
};
|
|
|
|
|
};
|
2012-06-18 20:28:31 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.packages = mkOption {
|
2012-08-21 16:28:47 +01:00
|
|
|
|
default = [];
|
|
|
|
|
type = types.listOf types.package;
|
|
|
|
|
description = "Packages providing systemd units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.targets = mkOption {
|
2012-10-01 23:58:11 +01:00
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2012-10-09 20:14:15 +01:00
|
|
|
|
options = [ unitOptions unitConfig ];
|
2012-10-01 23:58:11 +01:00
|
|
|
|
description = "Definition of systemd target units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.services = mkOption {
|
2012-06-18 20:28:31 +01:00
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2012-10-09 20:14:15 +01:00
|
|
|
|
options = [ serviceOptions unitConfig serviceConfig ];
|
2012-10-01 23:58:11 +01:00
|
|
|
|
description = "Definition of systemd service units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.sockets = mkOption {
|
2012-10-01 23:58:11 +01:00
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
2012-10-09 20:14:15 +01:00
|
|
|
|
options = [ socketOptions unitConfig ];
|
2012-10-01 23:58:11 +01:00
|
|
|
|
description = "Definition of systemd socket units.";
|
2012-06-14 23:44:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-03-02 00:03:13 +00:00
|
|
|
|
systemd.timers = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
type = types.attrsOf types.optionSet;
|
|
|
|
|
options = [ timerOptions unitConfig ];
|
|
|
|
|
description = "Definition of systemd timer units.";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.mounts = mkOption {
|
2012-12-28 12:29:53 +00: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-01-16 11:33:18 +00:00
|
|
|
|
systemd.defaultUnit = mkOption {
|
2012-06-18 04:31:21 +01:00
|
|
|
|
default = "multi-user.target";
|
|
|
|
|
type = types.uniq types.string;
|
|
|
|
|
description = "Default unit started when the system boots.";
|
|
|
|
|
};
|
2012-07-19 22:32:50 +01:00
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.globalEnvironment = mkOption {
|
2012-10-30 16:27:14 +00:00
|
|
|
|
type = types.attrs;
|
|
|
|
|
default = {};
|
|
|
|
|
example = { TZ = "CET"; };
|
|
|
|
|
description = ''
|
|
|
|
|
Environment variables passed to <emphasis>all</emphasis> systemd units.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-07-19 22:32:50 +01:00
|
|
|
|
services.journald.console = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.uniq types.string;
|
2012-11-02 13:10:06 +00:00
|
|
|
|
description = "If non-empty, write log messages to the specified TTY device.";
|
2012-07-19 22:32:50 +01:00
|
|
|
|
};
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-12-16 19:28:45 +00:00
|
|
|
|
services.journald.rateLimitInterval = mkOption {
|
|
|
|
|
default = "10s";
|
|
|
|
|
type = types.uniq types.string;
|
|
|
|
|
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-02-24 10:54:01 +00:00
|
|
|
|
services.logind.extraConfig = mkOption {
|
|
|
|
|
default = "";
|
|
|
|
|
type = types.uniq types.string;
|
|
|
|
|
example = "HandleLidSwitch=ignore";
|
|
|
|
|
description = ''
|
|
|
|
|
Extra config options for systemd-logind. See man logind.conf for
|
|
|
|
|
available options.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-21 20:01:48 +00:00
|
|
|
|
systemd.enableEmergencyMode = mkOption {
|
|
|
|
|
default = true;
|
|
|
|
|
type = types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether to enable emergency mode, which is an
|
|
|
|
|
<command>sulogin</command> shell started on the console if
|
|
|
|
|
mounting a filesystem fails. Since some machines (like EC2
|
|
|
|
|
instances) have no console of any kind, emergency mode doesn't
|
|
|
|
|
make sense, and it's better to continue with the boot insofar
|
|
|
|
|
as possible.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-14 23:44:56 +01:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2012-06-02 01:15:07 +01:00
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
2012-06-16 05:19:43 +01:00
|
|
|
|
system.build.units = units;
|
|
|
|
|
|
2012-06-02 01:15:07 +01:00
|
|
|
|
environment.systemPackages = [ systemd ];
|
2012-08-06 16:45:59 +01:00
|
|
|
|
|
2013-05-09 15:21:42 +01:00
|
|
|
|
environment.etc."systemd/system".source = units;
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/system.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Manager]
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
''}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
environment.etc."systemd/logind.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Login]
|
|
|
|
|
${config.services.logind.extraConfig}
|
|
|
|
|
'';
|
2012-06-14 23:44:56 +01:00
|
|
|
|
|
2013-05-09 15:25:24 +01:00
|
|
|
|
environment.etc."systemd/sleep.conf".text =
|
|
|
|
|
''
|
|
|
|
|
[Sleep]
|
|
|
|
|
'';
|
|
|
|
|
|
2013-07-19 20:18:44 +01:00
|
|
|
|
system.activationScripts.systemd = stringAfter [ "groups" ]
|
2012-11-29 17:51:44 +00:00
|
|
|
|
''
|
2013-07-20 16:07:26 +01:00
|
|
|
|
mkdir -m 0755 -p /var/lib/udev
|
|
|
|
|
mkdir -p /var/log/journal
|
|
|
|
|
chmod 0755 /var/log/journal
|
2012-11-29 17:51:44 +00:00
|
|
|
|
|
|
|
|
|
# Regenerate the hardware database /var/lib/udev/hwdb.bin
|
|
|
|
|
# whenever systemd changes.
|
|
|
|
|
if [ ! -e /var/lib/udev/prev-systemd -o "$(readlink /var/lib/udev/prev-systemd)" != ${systemd} ]; then
|
|
|
|
|
echo "regenerating udev hardware database..."
|
|
|
|
|
${systemd}/bin/udevadm hwdb --update && ln -sfn ${systemd} /var/lib/udev/prev-systemd
|
|
|
|
|
fi
|
2013-07-19 20:18:44 +01: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.
|
|
|
|
|
${pkgs.acl}/bin/setfacl -nm g:wheel:rx,d:g:wheel:rx,g:adm:rx,d:g:adm:rx /var/log/journal
|
2012-11-29 17:51:44 +00:00
|
|
|
|
'';
|
|
|
|
|
|
2012-11-01 22:32:12 +00:00
|
|
|
|
# Target for ‘charon send-keys’ to hook into.
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.targets.keys =
|
2012-11-01 22:32:12 +00:00
|
|
|
|
{ description = "Security Keys";
|
|
|
|
|
};
|
|
|
|
|
|
2013-01-16 11:33:18 +00:00
|
|
|
|
systemd.units =
|
2013-01-08 17:24:06 +00:00
|
|
|
|
mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.targets
|
2012-10-01 23:58:11 +01:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
2012-12-28 12:29:53 +00:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
2013-03-02 00:03:13 +00:00
|
|
|
|
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
|
2012-12-28 12:29:53 +00:00
|
|
|
|
// listToAttrs (map
|
2013-01-01 13:42:43 +00:00
|
|
|
|
(v: let n = escapeSystemdPath v.where;
|
2012-12-28 12:29:53 +00:00
|
|
|
|
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts);
|
2012-06-14 23:44:56 +01:00
|
|
|
|
|
2012-11-03 04:41:46 +00:00
|
|
|
|
system.requiredKernelConfig = map config.lib.kernelConfig.isEnabled [
|
|
|
|
|
"CGROUPS" "AUTOFS4_FS" "DEVTMPFS"
|
|
|
|
|
];
|
2012-11-29 17:51:44 +00:00
|
|
|
|
|
2012-11-30 15:12:04 +00:00
|
|
|
|
environment.shellAliases =
|
|
|
|
|
{ start = "systemctl start";
|
|
|
|
|
stop = "systemctl stop";
|
|
|
|
|
restart = "systemctl restart";
|
|
|
|
|
status = "systemctl status";
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-19 20:18:44 +01:00
|
|
|
|
users.extraGroups.systemd-journal.gid = config.ids.gids.systemd-journal;
|
|
|
|
|
|
2013-09-22 15:44:41 +01:00
|
|
|
|
# FIXME: This should no longer be needed with systemd >= 204.
|
|
|
|
|
systemd.services."systemd-update-utmp-reboot.service" =
|
|
|
|
|
{ description = "Update UTMP about System Reboot";
|
|
|
|
|
wantedBy = [ "sysinit.target" ];
|
|
|
|
|
unitConfig.DefaultDependencies = false;
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
|
serviceConfig.ExecStart = "${systemd}/lib/systemd/systemd-update-utmp reboot";
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-02 01:15:07 +01:00
|
|
|
|
};
|
|
|
|
|
}
|