2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-03-25 18:26:07 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-03-25 18:26:07 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2016-07-17 17:51:55 +01:00
|
|
|
xcfg = config.services.xserver;
|
|
|
|
dmcfg = xcfg.displayManager;
|
2013-09-09 09:22:08 +01:00
|
|
|
xEnv = config.systemd.services."display-manager".environment;
|
2013-03-25 18:26:07 +00:00
|
|
|
cfg = dmcfg.lightdm;
|
|
|
|
|
2018-03-04 17:29:08 +00:00
|
|
|
dmDefault = xcfg.desktopManager.default;
|
|
|
|
wmDefault = xcfg.windowManager.default;
|
|
|
|
hasDefaultUserSession = dmDefault != "none" || wmDefault != "none";
|
|
|
|
|
2018-07-20 20:36:12 +01:00
|
|
|
inherit (pkgs) lightdm writeScript writeText;
|
2013-03-25 18:26:07 +00:00
|
|
|
|
2018-08-16 13:50:41 +01:00
|
|
|
# lightdm runs with clearenv(), but we need a few things in the environment for X to startup
|
2013-03-25 18:26:07 +00:00
|
|
|
xserverWrapper = writeScript "xserver-wrapper"
|
|
|
|
''
|
2015-11-29 00:18:59 +00:00
|
|
|
#! ${pkgs.bash}/bin/bash
|
2013-09-09 09:22:08 +01:00
|
|
|
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
2015-11-29 00:18:59 +00:00
|
|
|
|
|
|
|
display=$(echo "$@" | xargs -n 1 | grep -P ^:\\d\$ | head -n 1 | sed s/^://)
|
|
|
|
if [ -z "$display" ]
|
|
|
|
then additionalArgs=":0 -logfile /var/log/X.0.log"
|
|
|
|
else additionalArgs="-logfile /var/log/X.$display.log"
|
|
|
|
fi
|
|
|
|
|
2016-12-04 13:48:47 +00:00
|
|
|
exec ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} $additionalArgs "$@"
|
2013-03-25 18:26:07 +00:00
|
|
|
'';
|
|
|
|
|
2015-03-10 01:04:40 +00:00
|
|
|
usersConf = writeText "users.conf"
|
|
|
|
''
|
|
|
|
[UserList]
|
|
|
|
minimum-uid=500
|
2015-03-10 21:35:49 +00:00
|
|
|
hidden-users=${concatStringsSep " " dmcfg.hiddenUsers}
|
2015-04-01 21:57:06 +01:00
|
|
|
hidden-shells=/run/current-system/sw/bin/nologin
|
2015-03-10 01:04:40 +00:00
|
|
|
'';
|
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
lightdmConf = writeText "lightdm.conf"
|
|
|
|
''
|
2013-04-22 20:31:29 +01:00
|
|
|
[LightDM]
|
2016-07-17 17:51:55 +01:00
|
|
|
${optionalString cfg.greeter.enable ''
|
2018-06-30 00:58:35 +01:00
|
|
|
greeter-user = ${config.users.users.lightdm.name}
|
2016-07-17 17:51:55 +01:00
|
|
|
greeters-directory = ${cfg.greeter.package}
|
|
|
|
''}
|
2018-05-02 01:31:18 +01:00
|
|
|
sessions-directory = ${dmcfg.session.desktops}/share/xsessions
|
2018-10-01 23:35:32 +01:00
|
|
|
${cfg.extraConfig}
|
2013-03-25 18:26:07 +00:00
|
|
|
|
2015-05-20 23:12:55 +01:00
|
|
|
[Seat:*]
|
2013-04-22 20:31:29 +01:00
|
|
|
xserver-command = ${xserverWrapper}
|
2018-07-24 15:52:49 +01:00
|
|
|
session-wrapper = ${dmcfg.session.wrapper}
|
2016-07-17 17:51:55 +01:00
|
|
|
${optionalString cfg.greeter.enable ''
|
|
|
|
greeter-session = ${cfg.greeter.name}
|
|
|
|
''}
|
|
|
|
${optionalString cfg.autoLogin.enable ''
|
|
|
|
autologin-user = ${cfg.autoLogin.user}
|
|
|
|
autologin-user-timeout = ${toString cfg.autoLogin.timeout}
|
2017-02-26 16:22:21 +00:00
|
|
|
autologin-session = ${defaultSessionName}
|
2016-07-17 17:51:55 +01:00
|
|
|
''}
|
2018-03-04 17:29:08 +00:00
|
|
|
${optionalString hasDefaultUserSession ''
|
|
|
|
user-session=${defaultSessionName}
|
|
|
|
''}
|
2018-06-30 08:33:45 +01:00
|
|
|
${optionalString (dmcfg.setupCommands != "") ''
|
|
|
|
display-setup-script=${pkgs.writeScript "lightdm-display-setup" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
${dmcfg.setupCommands}
|
|
|
|
''}
|
|
|
|
''}
|
2015-04-18 20:14:10 +01:00
|
|
|
${cfg.extraSeatDefaults}
|
2013-03-25 18:26:07 +00:00
|
|
|
'';
|
2016-07-17 17:51:55 +01:00
|
|
|
|
2018-03-04 17:29:08 +00:00
|
|
|
defaultSessionName = dmDefault + optionalString (wmDefault != "none") ("+" + wmDefault);
|
2013-03-25 18:26:07 +00:00
|
|
|
in
|
|
|
|
{
|
2015-11-28 09:55:46 +00:00
|
|
|
# Note: the order in which lightdm greeter modules are imported
|
|
|
|
# here determines the default: later modules (if enable) are
|
|
|
|
# preferred.
|
|
|
|
imports = [
|
|
|
|
./lightdm-greeters/gtk.nix
|
2018-04-19 04:45:06 +01:00
|
|
|
./lightdm-greeters/mini.nix
|
2018-08-12 03:13:14 +01:00
|
|
|
./lightdm-greeters/enso-os.nix
|
2018-08-20 21:31:18 +01:00
|
|
|
./lightdm-greeters/pantheon.nix
|
2015-11-28 09:55:46 +00:00
|
|
|
];
|
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
options = {
|
2015-11-28 09:55:46 +00:00
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
services.xserver.displayManager.lightdm = {
|
2015-03-10 21:55:54 +00:00
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
enable = mkOption {
|
2015-11-28 09:55:46 +00:00
|
|
|
type = types.bool;
|
2013-03-25 18:26:07 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable lightdm as the display manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-28 09:55:46 +00:00
|
|
|
greeter = {
|
2016-07-17 17:51:55 +01:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
If set to false, run lightdm in greeterless mode. This only works if autologin
|
|
|
|
is enabled and autoLogin.timeout is zero.
|
|
|
|
'';
|
|
|
|
};
|
2015-11-28 09:55:46 +00:00
|
|
|
package = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
type = types.package;
|
2015-11-28 09:55:46 +00:00
|
|
|
description = ''
|
|
|
|
The LightDM greeter to login via. The package should be a directory
|
|
|
|
containing a .desktop file matching the name in the 'name' option.
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
name = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
description = ''
|
|
|
|
The name of a .desktop file in the directory specified
|
|
|
|
in the 'package' option.
|
|
|
|
'';
|
2013-03-25 18:26:07 +00:00
|
|
|
};
|
|
|
|
};
|
2015-03-10 01:04:40 +00:00
|
|
|
|
2018-10-01 23:35:32 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
user-authority-in-system-dir = true
|
|
|
|
'';
|
|
|
|
description = "Extra lines to append to LightDM section.";
|
|
|
|
};
|
|
|
|
|
2015-03-10 22:57:46 +00:00
|
|
|
background = mkOption {
|
2016-01-31 09:52:28 +00:00
|
|
|
type = types.str;
|
2018-08-29 04:47:49 +01:00
|
|
|
default = "${pkgs.nixos-artwork.wallpapers.simple-dark-gray-bottom}/share/artwork/gnome/nix-wallpaper-simple-dark-gray_bottom.png";
|
2015-03-10 22:57:46 +00:00
|
|
|
description = ''
|
|
|
|
The background image or color to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-04-18 20:14:10 +01:00
|
|
|
extraSeatDefaults = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
greeter-show-manual-login=true
|
|
|
|
'';
|
|
|
|
description = "Extra lines to append to SeatDefaults section.";
|
|
|
|
};
|
|
|
|
|
2016-07-17 17:51:55 +01:00
|
|
|
autoLogin = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Configuration for automatic login.
|
|
|
|
'';
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2016-07-17 17:51:55 +01:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{ assertion = cfg.autoLogin.enable -> cfg.autoLogin.user != null;
|
|
|
|
message = ''
|
|
|
|
LightDM auto-login requires services.xserver.displayManager.lightdm.autoLogin.user to be set
|
|
|
|
'';
|
|
|
|
}
|
2018-07-28 14:58:07 +01:00
|
|
|
{ assertion = cfg.autoLogin.enable -> dmDefault != "none" || wmDefault != "none";
|
2016-07-17 17:51:55 +01:00
|
|
|
message = ''
|
|
|
|
LightDM auto-login requires that services.xserver.desktopManager.default and
|
2018-12-13 21:26:12 +00:00
|
|
|
services.xserver.windowManager.default are set to valid values. The current
|
2016-07-17 17:51:55 +01:00
|
|
|
default session: ${defaultSessionName} is not valid.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{ assertion = !cfg.greeter.enable -> (cfg.autoLogin.enable && cfg.autoLogin.timeout == 0);
|
|
|
|
message = ''
|
|
|
|
LightDM can only run without greeter if automatic login is enabled and the timeout for it
|
|
|
|
is set to zero.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-11-09 15:47:16 +00:00
|
|
|
# lightdm relaunches itself via just `lightdm`, so needs to be on the PATH
|
|
|
|
services.xserver.displayManager.job.execCmd = ''
|
|
|
|
export PATH=${lightdm}/sbin:$PATH
|
|
|
|
exec ${lightdm}/sbin/lightdm
|
|
|
|
'';
|
2013-03-25 18:26:07 +00:00
|
|
|
|
2015-03-10 00:59:21 +00:00
|
|
|
environment.etc."lightdm/lightdm.conf".source = lightdmConf;
|
2015-03-10 01:04:40 +00:00
|
|
|
environment.etc."lightdm/users.conf".source = usersConf;
|
2015-03-10 00:59:21 +00:00
|
|
|
|
2013-03-25 18:26:07 +00:00
|
|
|
services.dbus.enable = true;
|
|
|
|
services.dbus.packages = [ lightdm ];
|
|
|
|
|
2018-08-16 13:50:41 +01:00
|
|
|
# lightdm uses the accounts daemon to remember language/window-manager per user
|
2016-10-15 13:16:47 +01:00
|
|
|
services.accounts-daemon.enable = true;
|
|
|
|
|
2018-08-16 09:56:44 +01:00
|
|
|
# Enable the accounts daemon to find lightdm's dbus interface
|
|
|
|
environment.systemPackages = [ lightdm ];
|
|
|
|
|
2015-05-22 03:06:03 +01:00
|
|
|
security.pam.services.lightdm = {
|
|
|
|
allowNullPassword = true;
|
|
|
|
startSession = true;
|
|
|
|
};
|
|
|
|
security.pam.services.lightdm-greeter = {
|
|
|
|
allowNullPassword = true;
|
|
|
|
startSession = true;
|
|
|
|
text = ''
|
2015-11-22 20:25:11 +00:00
|
|
|
auth required pam_env.so envfile=${config.system.build.pamEnvironment}
|
2015-05-22 03:06:03 +01:00
|
|
|
auth required pam_permit.so
|
|
|
|
|
|
|
|
account required pam_permit.so
|
|
|
|
|
|
|
|
password required pam_deny.so
|
|
|
|
|
|
|
|
session required pam_env.so envfile=${config.system.build.pamEnvironment}
|
|
|
|
session required pam_unix.so
|
|
|
|
session optional ${pkgs.systemd}/lib/security/pam_systemd.so
|
|
|
|
'';
|
|
|
|
};
|
2016-07-17 17:51:55 +01:00
|
|
|
security.pam.services.lightdm-autologin.text = ''
|
|
|
|
auth requisite pam_nologin.so
|
|
|
|
auth required pam_succeed_if.so uid >= 1000 quiet
|
|
|
|
auth required pam_permit.so
|
|
|
|
|
|
|
|
account include lightdm
|
|
|
|
|
|
|
|
password include lightdm
|
|
|
|
|
|
|
|
session include lightdm
|
|
|
|
'';
|
2013-03-25 18:26:07 +00:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.lightdm = {
|
2018-09-17 10:02:21 +01:00
|
|
|
home = "/var/lib/lightdm";
|
2013-08-26 14:20:25 +01:00
|
|
|
group = "lightdm";
|
|
|
|
uid = config.ids.uids.lightdm;
|
2013-03-25 18:26:07 +00:00
|
|
|
};
|
2013-08-26 14:20:25 +01:00
|
|
|
|
2018-09-17 10:02:21 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
2018-09-19 15:54:13 +01:00
|
|
|
"d /run/lightdm 0711 lightdm lightdm 0"
|
2018-09-17 10:02:21 +01:00
|
|
|
"d /var/cache/lightdm 0711 root lightdm -"
|
|
|
|
"d /var/lib/lightdm 1770 lightdm lightdm -"
|
|
|
|
"d /var/lib/lightdm-data 1775 lightdm lightdm -"
|
|
|
|
"d /var/log/lightdm 0711 root lightdm -"
|
|
|
|
];
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups.lightdm.gid = config.ids.gids.lightdm;
|
2015-11-29 00:18:59 +00:00
|
|
|
services.xserver.tty = null; # We might start multiple X servers so let the tty increment themselves..
|
|
|
|
services.xserver.display = null; # We specify our own display (and logfile) in xserver-wrapper up there
|
2013-03-25 18:26:07 +00:00
|
|
|
};
|
|
|
|
}
|