nixos: systemd: split off logind into separate module
This commit is contained in:
@@ -1166,6 +1166,7 @@
|
|||||||
./system/boot/stage-1.nix
|
./system/boot/stage-1.nix
|
||||||
./system/boot/stage-2.nix
|
./system/boot/stage-2.nix
|
||||||
./system/boot/systemd.nix
|
./system/boot/systemd.nix
|
||||||
|
./system/boot/systemd/logind.nix
|
||||||
./system/boot/systemd/nspawn.nix
|
./system/boot/systemd/nspawn.nix
|
||||||
./system/boot/timesyncd.nix
|
./system/boot/timesyncd.nix
|
||||||
./system/boot/tmp.nix
|
./system/boot/tmp.nix
|
||||||
|
|||||||
@@ -80,16 +80,6 @@ let
|
|||||||
"printer.target"
|
"printer.target"
|
||||||
"smartcard.target"
|
"smartcard.target"
|
||||||
|
|
||||||
# Login stuff.
|
|
||||||
"systemd-logind.service"
|
|
||||||
"autovt@.service"
|
|
||||||
"systemd-user-sessions.service"
|
|
||||||
"dbus-org.freedesktop.import1.service"
|
|
||||||
"dbus-org.freedesktop.machine1.service"
|
|
||||||
"dbus-org.freedesktop.login1.service"
|
|
||||||
"user@.service"
|
|
||||||
"user-runtime-dir@.service"
|
|
||||||
|
|
||||||
# Journal.
|
# Journal.
|
||||||
"systemd-journald.socket"
|
"systemd-journald.socket"
|
||||||
"systemd-journald@.socket"
|
"systemd-journald@.socket"
|
||||||
@@ -227,11 +217,6 @@ let
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
logindHandlerType = types.enum [
|
|
||||||
"ignore" "poweroff" "reboot" "halt" "kexec" "suspend"
|
|
||||||
"hibernate" "hybrid-sleep" "suspend-then-hibernate" "lock"
|
|
||||||
];
|
|
||||||
|
|
||||||
proxy_env = config.networking.proxy.envVars;
|
proxy_env = config.networking.proxy.envVars;
|
||||||
|
|
||||||
in
|
in
|
||||||
@@ -487,69 +472,6 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
services.logind.extraConfig = mkOption {
|
|
||||||
default = "";
|
|
||||||
type = types.lines;
|
|
||||||
example = "IdleAction=lock";
|
|
||||||
description = ''
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
services.logind.lidSwitchExternalPower = mkOption {
|
|
||||||
default = config.services.logind.lidSwitch;
|
|
||||||
defaultText = literalExpression "services.logind.lidSwitch";
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.sleep.extraConfig = mkOption {
|
systemd.sleep.extraConfig = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
@@ -837,15 +759,6 @@ in
|
|||||||
${config.systemd.coredump.extraConfig}
|
${config.systemd.coredump.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
"systemd/logind.conf".text = ''
|
|
||||||
[Login]
|
|
||||||
KillUserProcesses=${if config.services.logind.killUserProcesses then "yes" else "no"}
|
|
||||||
HandleLidSwitch=${config.services.logind.lidSwitch}
|
|
||||||
HandleLidSwitchDocked=${config.services.logind.lidSwitchDocked}
|
|
||||||
HandleLidSwitchExternalPower=${config.services.logind.lidSwitchExternalPower}
|
|
||||||
${config.services.logind.extraConfig}
|
|
||||||
'';
|
|
||||||
|
|
||||||
"systemd/sleep.conf".text = ''
|
"systemd/sleep.conf".text = ''
|
||||||
[Sleep]
|
[Sleep]
|
||||||
${config.systemd.sleep.extraConfig}
|
${config.systemd.sleep.extraConfig}
|
||||||
@@ -1002,16 +915,6 @@ in
|
|||||||
systemd.services.systemd-update-utmp.restartIfChanged = false;
|
systemd.services.systemd-update-utmp.restartIfChanged = false;
|
||||||
systemd.services.systemd-user-sessions.restartIfChanged = false; # Restart kills all active sessions.
|
systemd.services.systemd-user-sessions.restartIfChanged = false; # Restart kills all active sessions.
|
||||||
systemd.services.systemd-udev-settle.restartIfChanged = false; # Causes long delays in nixos-rebuild
|
systemd.services.systemd-udev-settle.restartIfChanged = false; # Causes long delays in nixos-rebuild
|
||||||
# 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;
|
|
||||||
systemd.services.systemd-logind.stopIfChanged = false;
|
|
||||||
# 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;
|
|
||||||
systemd.services.systemd-journald.restartTriggers = [ config.environment.etc."systemd/journald.conf".source ];
|
systemd.services.systemd-journald.restartTriggers = [ config.environment.etc."systemd/journald.conf".source ];
|
||||||
systemd.services.systemd-journald.stopIfChanged = false;
|
systemd.services.systemd-journald.stopIfChanged = false;
|
||||||
systemd.services."systemd-journald@".restartTriggers = [ config.environment.etc."systemd/journald.conf".source ];
|
systemd.services."systemd-journald@".restartTriggers = [ config.environment.etc."systemd/journald.conf".source ];
|
||||||
|
|||||||
113
nixos/modules/system/boot/systemd/logind.nix
Normal file
113
nixos/modules/system/boot/systemd/logind.nix
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
{ config, lib, pkgs, utils, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
logindHandlerType = types.enum [
|
||||||
|
"ignore" "poweroff" "reboot" "halt" "kexec" "suspend"
|
||||||
|
"hibernate" "hybrid-sleep" "suspend-then-hibernate" "lock"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
services.logind.extraConfig = mkOption {
|
||||||
|
default = "";
|
||||||
|
type = types.lines;
|
||||||
|
example = "IdleAction=lock";
|
||||||
|
description = ''
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
services.logind.lidSwitchExternalPower = mkOption {
|
||||||
|
default = config.services.logind.lidSwitch;
|
||||||
|
defaultText = literalExpression "services.logind.lidSwitch";
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
systemd.additionalUpstreamSystemUnits = [
|
||||||
|
# Login stuff.
|
||||||
|
"systemd-logind.service"
|
||||||
|
"autovt@.service"
|
||||||
|
"systemd-user-sessions.service"
|
||||||
|
"dbus-org.freedesktop.import1.service"
|
||||||
|
"dbus-org.freedesktop.machine1.service"
|
||||||
|
"dbus-org.freedesktop.login1.service"
|
||||||
|
"user@.service"
|
||||||
|
"user-runtime-dir@.service"
|
||||||
|
];
|
||||||
|
|
||||||
|
environment.etc = {
|
||||||
|
"systemd/logind.conf".text = ''
|
||||||
|
[Login]
|
||||||
|
KillUserProcesses=${if config.services.logind.killUserProcesses then "yes" else "no"}
|
||||||
|
HandleLidSwitch=${config.services.logind.lidSwitch}
|
||||||
|
HandleLidSwitchDocked=${config.services.logind.lidSwitchDocked}
|
||||||
|
HandleLidSwitchExternalPower=${config.services.logind.lidSwitchExternalPower}
|
||||||
|
${config.services.logind.extraConfig}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# 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;
|
||||||
|
systemd.services.systemd-logind.stopIfChanged = false;
|
||||||
|
|
||||||
|
# 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;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user