Merge pull request #85065 from worldofpeace/autologin-unified

nixos/displayManager: make autoLogin options independent of DM type
This commit is contained in:
worldofpeace 2020-07-10 00:04:41 -04:00 committed by GitHub
commit 747fb48c72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 145 additions and 155 deletions

View file

@ -9,7 +9,6 @@
This profile just enables a <systemitem class="username">demo</systemitem> This profile just enables a <systemitem class="username">demo</systemitem>
user, with password <literal>demo</literal>, uid <literal>1000</literal>, user, with password <literal>demo</literal>, uid <literal>1000</literal>,
<systemitem class="groupname">wheel</systemitem> group and <systemitem class="groupname">wheel</systemitem> group and
<link linkend="opt-services.xserver.displayManager.sddm.autoLogin"> autologin <link linkend="opt-services.xserver.displayManager.autoLogin">autologin in the SDDM display manager</link>.
in the SDDM display manager</link>.
</para> </para>
</section> </section>

View file

@ -90,10 +90,9 @@
using lightdm for a user <literal>alice</literal>: using lightdm for a user <literal>alice</literal>:
<programlisting> <programlisting>
<xref linkend="opt-services.xserver.displayManager.lightdm.enable"/> = true; <xref linkend="opt-services.xserver.displayManager.lightdm.enable"/> = true;
<xref linkend="opt-services.xserver.displayManager.lightdm.autoLogin.enable"/> = true; <xref linkend="opt-services.xserver.displayManager.autoLogin.enable"/> = true;
<xref linkend="opt-services.xserver.displayManager.lightdm.autoLogin.user"/> = "alice"; <xref linkend="opt-services.xserver.displayManager.autoLogin.user"/> = "alice";
</programlisting> </programlisting>
The options are named identically for all other display managers.
</para> </para>
</simplesect> </simplesect>
<simplesect xml:id="sec-x11--graphics-cards-intel"> <simplesect xml:id="sec-x11--graphics-cards-intel">

View file

@ -792,7 +792,7 @@ users.users.me =
The <option>services.xserver.displayManager.auto</option> module has been removed. The <option>services.xserver.displayManager.auto</option> module has been removed.
It was only intended for use in internal NixOS tests, and gave the false impression It was only intended for use in internal NixOS tests, and gave the false impression
of it being a special display manager when it's actually LightDM. of it being a special display manager when it's actually LightDM.
Please use the <xref linkend="opt-services.xserver.displayManager.lightdm.autoLogin"/> options instead, Please use the <option>services.xserver.displayManager.lightdm.autoLogin</option> options instead,
or any other display manager in NixOS as they all support auto-login. If you used this module specifically or any other display manager in NixOS as they all support auto-login. If you used this module specifically
because it permitted root auto-login you can override the lightdm-autologin pam module like: because it permitted root auto-login you can override the lightdm-autologin pam module like:
<programlisting> <programlisting>

View file

@ -519,6 +519,12 @@ systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www" ];
automatically if <literal>stateVersion</literal> is 20.09 or higher. automatically if <literal>stateVersion</literal> is 20.09 or higher.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
We now have a unified <xref linkend="opt-services.xserver.displayManager.autoLogin"/> option interface
to be used for every display-manager in NixOS.
</para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>

View file

@ -11,15 +11,17 @@ with lib;
services.xserver.desktopManager.gnome3.enable = true; services.xserver.desktopManager.gnome3.enable = true;
services.xserver.displayManager.gdm = { services.xserver.displayManager = {
enable = true; gdm = {
# autoSuspend makes the machine automatically suspend after inactivity. enable = true;
# It's possible someone could/try to ssh'd into the machine and obviously # autoSuspend makes the machine automatically suspend after inactivity.
# have issues because it's inactive. # It's possible someone could/try to ssh'd into the machine and obviously
# See: # have issues because it's inactive.
# * https://github.com/NixOS/nixpkgs/pull/63790 # See:
# * https://gitlab.gnome.org/GNOME/gnome-control-center/issues/22 # * https://github.com/NixOS/nixpkgs/pull/63790
autoSuspend = false; # * https://gitlab.gnome.org/GNOME/gnome-control-center/issues/22
autoSuspend = false;
};
autoLogin = { autoLogin = {
enable = true; enable = true;
user = "nixos"; user = "nixos";

View file

@ -16,8 +16,8 @@ with lib;
}; };
# Automatically login as nixos. # Automatically login as nixos.
displayManager.sddm = { displayManager = {
enable = true; sddm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = "nixos"; user = "nixos";

View file

@ -11,9 +11,11 @@
uid = 1000; uid = 1000;
}; };
services.xserver.displayManager.sddm.autoLogin = { services.xserver.displayManager = {
enable = true; autoLogin = {
relogin = true; enable = true;
user = "demo"; user = "demo";
};
sddm.autoLogin.relogin = true;
}; };
} }

View file

@ -39,7 +39,7 @@ with lib;
The services.xserver.displayManager.auto module has been removed The services.xserver.displayManager.auto module has been removed
because it was only intended for use in internal NixOS tests, and gave the because it was only intended for use in internal NixOS tests, and gave the
false impression of it being a special display manager when it's actually false impression of it being a special display manager when it's actually
LightDM. Please use the services.xserver.displayManager.lightdm.autoLogin options LightDM. Please use the services.xserver.displayManager.autoLogin options
instead, or any other display manager in NixOS as they all support auto-login. instead, or any other display manager in NixOS as they all support auto-login.
'') '')
(mkRemovedOptionModule [ "services" "dnscrypt-proxy" ] "Use services.dnscrypt-proxy2 instead") (mkRemovedOptionModule [ "services" "dnscrypt-proxy" ] "Use services.dnscrypt-proxy2 instead")

View file

@ -332,12 +332,45 @@ in
}; };
# Configuration for automatic login. Common for all DM.
autoLogin = mkOption {
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = cfg.displayManager.autoLogin.user != null;
description = ''
Automatically log in as <option>autoLogin.user</option>.
'';
};
user = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
User to be used for the automatic login.
'';
};
};
};
default = {};
description = ''
Auto login configuration attrset.
'';
};
}; };
}; };
config = { config = {
assertions = [ assertions = [
{ assertion = cfg.displayManager.autoLogin.enable -> cfg.displayManager.autoLogin.user != null;
message = ''
services.xserver.displayManager.autoLogin.enable requires services.xserver.displayManager.autoLogin.user to be set
'';
}
{ {
assertion = cfg.desktopManager.default != null || cfg.windowManager.default != null -> cfg.displayManager.defaultSession == defaultSessionFromLegacyOptions; assertion = cfg.desktopManager.default != null || cfg.windowManager.default != null -> cfg.displayManager.defaultSession == defaultSessionFromLegacyOptions;
message = "You cannot use both services.xserver.displayManager.defaultSession option and legacy options (services.xserver.desktopManager.default and services.xserver.windowManager.default)."; message = "You cannot use both services.xserver.displayManager.defaultSession option and legacy options (services.xserver.desktopManager.default and services.xserver.windowManager.default).";

View file

@ -37,6 +37,22 @@ let
in in
{ {
imports = [
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "gdm" "autoLogin" "enable" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"enable"
])
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "gdm" "autoLogin" "user" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"user"
])
];
meta = { meta = {
maintainers = teams.gnome.members; maintainers = teams.gnome.members;
@ -56,40 +72,13 @@ in
debugging messages in GDM debugging messages in GDM
''; '';
autoLogin = mkOption { # Auto login options specific to GDM
default = {}; autoLogin.delay = mkOption {
type = types.int;
default = 0;
description = '' description = ''
Auto login configuration attrset. Seconds of inactivity after which the autologin will be performed.
''; '';
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Automatically log in as the sepecified <option>autoLogin.user</option>.
'';
};
user = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
User to be used for the autologin.
'';
};
delay = mkOption {
type = types.int;
default = 0;
description = ''
Seconds of inactivity after which the autologin will be performed.
'';
};
};
};
}; };
wayland = mkOption { wayland = mkOption {
@ -128,12 +117,6 @@ in
config = mkIf cfg.gdm.enable { config = mkIf cfg.gdm.enable {
assertions = [
{ assertion = cfg.gdm.autoLogin.enable -> cfg.gdm.autoLogin.user != null;
message = "GDM auto-login requires services.xserver.displayManager.gdm.autoLogin.user to be set";
}
];
services.xserver.displayManager.lightdm.enable = false; services.xserver.displayManager.lightdm.enable = false;
users.users.gdm = users.users.gdm =
@ -287,14 +270,14 @@ in
environment.etc."gdm/custom.conf".text = '' environment.etc."gdm/custom.conf".text = ''
[daemon] [daemon]
WaylandEnable=${if cfg.gdm.wayland then "true" else "false"} WaylandEnable=${if cfg.gdm.wayland then "true" else "false"}
${optionalString cfg.gdm.autoLogin.enable ( ${optionalString cfg.autoLogin.enable (
if cfg.gdm.autoLogin.delay > 0 then '' if cfg.gdm.autoLogin.delay > 0 then ''
TimedLoginEnable=true TimedLoginEnable=true
TimedLogin=${cfg.gdm.autoLogin.user} TimedLogin=${cfg.autoLogin.user}
TimedLoginDelay=${toString cfg.gdm.autoLogin.delay} TimedLoginDelay=${toString cfg.gdm.autoLogin.delay}
'' else '' '' else ''
AutomaticLoginEnable=true AutomaticLoginEnable=true
AutomaticLogin=${cfg.gdm.autoLogin.user} AutomaticLogin=${cfg.autoLogin.user}
'') '')
} }

View file

@ -53,8 +53,8 @@ let
${optionalString cfg.greeter.enable '' ${optionalString cfg.greeter.enable ''
greeter-session = ${cfg.greeter.name} greeter-session = ${cfg.greeter.name}
''} ''}
${optionalString cfg.autoLogin.enable '' ${optionalString dmcfg.autoLogin.enable ''
autologin-user = ${cfg.autoLogin.user} autologin-user = ${dmcfg.autoLogin.user}
autologin-user-timeout = ${toString cfg.autoLogin.timeout} autologin-user-timeout = ${toString cfg.autoLogin.timeout}
autologin-session = ${sessionData.autologinSession} autologin-session = ${sessionData.autologinSession}
''} ''}
@ -82,6 +82,20 @@ in
./lightdm-greeters/enso-os.nix ./lightdm-greeters/enso-os.nix
./lightdm-greeters/pantheon.nix ./lightdm-greeters/pantheon.nix
./lightdm-greeters/tiny.nix ./lightdm-greeters/tiny.nix
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "lightdm" "autoLogin" "enable" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"enable"
])
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "lightdm" "autoLogin" "user" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"user"
])
]; ];
options = { options = {
@ -149,39 +163,13 @@ in
description = "Extra lines to append to SeatDefaults section."; description = "Extra lines to append to SeatDefaults section.";
}; };
autoLogin = mkOption { # Configuration for automatic login specific to LightDM
default = {}; autoLogin.timeout = mkOption {
type = types.int;
default = 0;
description = '' description = ''
Configuration for automatic login. Show the greeter for this many seconds before automatic login occurs.
''; '';
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Automatically log in as the specified <option>autoLogin.user</option>.
'';
};
user = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
User to be used for the automatic login.
'';
};
timeout = mkOption {
type = types.int;
default = 0;
description = ''
Show the greeter for this many seconds before automatic login occurs.
'';
};
};
};
}; };
}; };
@ -195,17 +183,12 @@ in
LightDM requires services.xserver.enable to be true LightDM requires services.xserver.enable to be true
''; '';
} }
{ assertion = cfg.autoLogin.enable -> cfg.autoLogin.user != null; { assertion = dmcfg.autoLogin.enable -> sessionData.autologinSession != null;
message = ''
LightDM auto-login requires services.xserver.displayManager.lightdm.autoLogin.user to be set
'';
}
{ assertion = cfg.autoLogin.enable -> sessionData.autologinSession != null;
message = '' message = ''
LightDM auto-login requires that services.xserver.displayManager.defaultSession is set. LightDM auto-login requires that services.xserver.displayManager.defaultSession is set.
''; '';
} }
{ assertion = !cfg.greeter.enable -> (cfg.autoLogin.enable && cfg.autoLogin.timeout == 0); { assertion = !cfg.greeter.enable -> (dmcfg.autoLogin.enable && cfg.autoLogin.timeout == 0);
message = '' message = ''
LightDM can only run without greeter if automatic login is enabled and the timeout for it LightDM can only run without greeter if automatic login is enabled and the timeout for it
is set to zero. is set to zero.
@ -218,7 +201,7 @@ in
# Set default session in session chooser to a specified values basically ignore session history. # Set default session in session chooser to a specified values basically ignore session history.
# Auto-login is already covered by a config value. # Auto-login is already covered by a config value.
services.xserver.displayManager.job.preStart = optionalString (!cfg.autoLogin.enable && dmcfg.defaultSession != null) '' services.xserver.displayManager.job.preStart = optionalString (!dmcfg.autoLogin.enable && dmcfg.defaultSession != null) ''
${setSessionScript}/bin/set-session ${dmcfg.defaultSession} ${setSessionScript}/bin/set-session ${dmcfg.defaultSession}
''; '';

View file

@ -61,9 +61,9 @@ let
EnableHidpi=${if cfg.enableHidpi then "true" else "false"} EnableHidpi=${if cfg.enableHidpi then "true" else "false"}
SessionDir=${dmcfg.sessionData.desktops}/share/wayland-sessions SessionDir=${dmcfg.sessionData.desktops}/share/wayland-sessions
${optionalString cfg.autoLogin.enable '' ${optionalString dmcfg.autoLogin.enable ''
[Autologin] [Autologin]
User=${cfg.autoLogin.user} User=${dmcfg.autoLogin.user}
Session=${autoLoginSessionName}.desktop Session=${autoLoginSessionName}.desktop
Relogin=${boolToString cfg.autoLogin.relogin} Relogin=${boolToString cfg.autoLogin.relogin}
''} ''}
@ -78,6 +78,20 @@ in
imports = [ imports = [
(mkRemovedOptionModule [ "services" "xserver" "displayManager" "sddm" "themes" ] (mkRemovedOptionModule [ "services" "xserver" "displayManager" "sddm" "themes" ]
"Set the option `services.xserver.displayManager.sddm.package' instead.") "Set the option `services.xserver.displayManager.sddm.package' instead.")
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "enable" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"enable"
])
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "user" ] [
"services"
"xserver"
"displayManager"
"autoLogin"
"user"
])
]; ];
options = { options = {
@ -153,40 +167,14 @@ in
''; '';
}; };
autoLogin = mkOption { # Configuration for automatic login specific to SDDM
default = {}; autoLogin.relogin = mkOption {
type = types.bool;
default = false;
description = '' description = ''
Configuration for automatic login. If true automatic login will kick in again on session exit (logout), otherwise it
will only log in automatically when the display-manager is started.
''; '';
type = types.submodule {
options = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Automatically log in as <option>autoLogin.user</option>.
'';
};
user = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
User to be used for the automatic login.
'';
};
relogin = mkOption {
type = types.bool;
default = false;
description = ''
If true automatic login will kick in again on session exit (logout), otherwise it
will only log in automatically when the display-manager is started.
'';
};
};
};
}; };
}; };
@ -201,12 +189,7 @@ in
SDDM requires services.xserver.enable to be true SDDM requires services.xserver.enable to be true
''; '';
} }
{ assertion = cfg.autoLogin.enable -> cfg.autoLogin.user != null; { assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
message = ''
SDDM auto-login requires services.xserver.displayManager.sddm.autoLogin.user to be set
'';
}
{ assertion = cfg.autoLogin.enable -> autoLoginSessionName != null;
message = '' message = ''
SDDM auto-login requires that services.xserver.displayManager.defaultSession is set. SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
''; '';

View file

@ -41,8 +41,8 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.xserver.displayManager.lightdm = { services.xserver.displayManager = {
enable = true; lightdm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = cfg.user; user = cfg.user;

View file

@ -12,8 +12,8 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : {
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.gdm = { services.xserver.displayManager = {
enable = true; gdm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = user.name; user = user.name;

View file

@ -11,8 +11,8 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : {
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.gdm = { services.xserver.displayManager = {
enable = true; gdm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = "alice"; user = "alice";

View file

@ -14,7 +14,7 @@ import ./make-test-python.nix ({ pkgs, ...} :
services.xserver.displayManager.sddm.enable = true; services.xserver.displayManager.sddm.enable = true;
services.xserver.displayManager.defaultSession = "plasma5"; services.xserver.displayManager.defaultSession = "plasma5";
services.xserver.desktopManager.plasma5.enable = true; services.xserver.desktopManager.plasma5.enable = true;
services.xserver.displayManager.sddm.autoLogin = { services.xserver.displayManager.autoLogin = {
enable = true; enable = true;
user = "alice"; user = "alice";
}; };

View file

@ -44,8 +44,8 @@ let
machine = { ... }: { machine = { ... }: {
imports = [ ./common/user-account.nix ]; imports = [ ./common/user-account.nix ];
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.sddm = { services.xserver.displayManager = {
enable = true; sddm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = "alice"; user = "alice";

View file

@ -11,8 +11,8 @@ import ./make-test-python.nix ({ pkgs, ...} : {
services.xserver.enable = true; services.xserver.enable = true;
services.xserver.displayManager.lightdm = { services.xserver.displayManager = {
enable = true; lightdm.enable = true;
autoLogin = { autoLogin = {
enable = true; enable = true;
user = "alice"; user = "alice";