2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-03-25 19:26:07 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-03-25 19:26:07 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2016-07-17 18:51:55 +02:00
|
|
|
xcfg = config.services.xserver;
|
|
|
|
dmcfg = xcfg.displayManager;
|
2013-09-09 10:22:08 +02:00
|
|
|
xEnv = config.systemd.services."display-manager".environment;
|
2013-03-25 19:26:07 +01:00
|
|
|
cfg = dmcfg.lightdm;
|
|
|
|
|
2018-03-04 18:29:08 +01:00
|
|
|
dmDefault = xcfg.desktopManager.default;
|
|
|
|
wmDefault = xcfg.windowManager.default;
|
|
|
|
hasDefaultUserSession = dmDefault != "none" || wmDefault != "none";
|
|
|
|
|
2018-07-20 21:36:12 +02:00
|
|
|
inherit (pkgs) lightdm writeScript writeText;
|
2013-03-25 19:26:07 +01:00
|
|
|
|
|
|
|
# lightdm runs with clearenv(), but we need a few things in the enviornment for X to startup
|
|
|
|
xserverWrapper = writeScript "xserver-wrapper"
|
|
|
|
''
|
2015-11-29 01:18:59 +01:00
|
|
|
#! ${pkgs.bash}/bin/bash
|
2013-09-09 10:22:08 +02:00
|
|
|
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
2015-11-29 01:18:59 +01: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 14:48:47 +01:00
|
|
|
exec ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} $additionalArgs "$@"
|
2013-03-25 19:26:07 +01:00
|
|
|
'';
|
|
|
|
|
2015-03-10 02:04:40 +01:00
|
|
|
usersConf = writeText "users.conf"
|
|
|
|
''
|
|
|
|
[UserList]
|
|
|
|
minimum-uid=500
|
2015-03-10 22:35:49 +01:00
|
|
|
hidden-users=${concatStringsSep " " dmcfg.hiddenUsers}
|
2015-04-01 22:57:06 +02:00
|
|
|
hidden-shells=/run/current-system/sw/bin/nologin
|
2015-03-10 02:04:40 +01:00
|
|
|
'';
|
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
lightdmConf = writeText "lightdm.conf"
|
|
|
|
''
|
2013-04-22 21:31:29 +02:00
|
|
|
[LightDM]
|
2016-07-17 18:51:55 +02:00
|
|
|
${optionalString cfg.greeter.enable ''
|
2018-06-30 01:58:35 +02:00
|
|
|
greeter-user = ${config.users.users.lightdm.name}
|
2016-07-17 18:51:55 +02:00
|
|
|
greeters-directory = ${cfg.greeter.package}
|
|
|
|
''}
|
2014-01-31 12:11:04 +01:00
|
|
|
sessions-directory = ${dmcfg.session.desktops}
|
2013-03-25 19:26:07 +01:00
|
|
|
|
2015-05-21 00:12:55 +02:00
|
|
|
[Seat:*]
|
2013-04-22 21:31:29 +02:00
|
|
|
xserver-command = ${xserverWrapper}
|
|
|
|
session-wrapper = ${dmcfg.session.script}
|
2016-07-17 18:51:55 +02: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 17:22:21 +01:00
|
|
|
autologin-session = ${defaultSessionName}
|
2016-07-17 18:51:55 +02:00
|
|
|
''}
|
2018-03-04 18:29:08 +01:00
|
|
|
${optionalString hasDefaultUserSession ''
|
|
|
|
user-session=${defaultSessionName}
|
|
|
|
''}
|
2015-04-18 21:14:10 +02:00
|
|
|
${cfg.extraSeatDefaults}
|
2013-03-25 19:26:07 +01:00
|
|
|
'';
|
2016-07-17 18:51:55 +02:00
|
|
|
|
2018-03-04 18:29:08 +01:00
|
|
|
defaultSessionName = dmDefault + optionalString (wmDefault != "none") ("+" + wmDefault);
|
2013-03-25 19:26:07 +01:00
|
|
|
in
|
|
|
|
{
|
2015-11-28 10:55:46 +01: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 05:45:06 +02:00
|
|
|
./lightdm-greeters/mini.nix
|
2015-11-28 10:55:46 +01:00
|
|
|
];
|
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
options = {
|
2015-11-28 10:55:46 +01:00
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
services.xserver.displayManager.lightdm = {
|
2015-03-10 22:55:54 +01:00
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
enable = mkOption {
|
2015-11-28 10:55:46 +01:00
|
|
|
type = types.bool;
|
2013-03-25 19:26:07 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable lightdm as the display manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-11-28 10:55:46 +01:00
|
|
|
greeter = {
|
2016-07-17 18:51:55 +02: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 10:55:46 +01:00
|
|
|
package = mkOption {
|
2016-01-17 19:34:55 +01:00
|
|
|
type = types.package;
|
2015-11-28 10:55:46 +01: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 19:26:07 +01:00
|
|
|
};
|
|
|
|
};
|
2015-03-10 02:04:40 +01:00
|
|
|
|
2015-03-10 23:57:46 +01:00
|
|
|
background = mkOption {
|
2016-01-31 10:52:28 +01:00
|
|
|
type = types.str;
|
2017-06-07 23:00:58 +02:00
|
|
|
default = "${pkgs.nixos-artwork.wallpapers.gnome-dark}/share/artwork/gnome/Gnome_Dark.png";
|
2015-03-10 23:57:46 +01:00
|
|
|
description = ''
|
|
|
|
The background image or color to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-04-18 21:14:10 +02:00
|
|
|
extraSeatDefaults = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
greeter-show-manual-login=true
|
|
|
|
'';
|
|
|
|
description = "Extra lines to append to SeatDefaults section.";
|
|
|
|
};
|
|
|
|
|
2016-07-17 18:51:55 +02: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 19:26:07 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2016-07-17 18:51:55 +02:00
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{ assertion = cfg.autoLogin.enable -> cfg.autoLogin.user != null;
|
|
|
|
message = ''
|
|
|
|
LightDM auto-login requires services.xserver.displayManager.lightdm.autoLogin.user to be set
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{ assertion = cfg.autoLogin.enable -> elem defaultSessionName dmcfg.session.names;
|
|
|
|
message = ''
|
|
|
|
LightDM auto-login requires that services.xserver.desktopManager.default and
|
|
|
|
services.xserver.windowMananger.default are set to valid values. The current
|
|
|
|
default session: ${defaultSessionName} is not valid.
|
|
|
|
'';
|
|
|
|
}
|
2018-03-04 18:29:08 +01:00
|
|
|
{ assertion = hasDefaultUserSession -> elem defaultSessionName dmcfg.session.names;
|
|
|
|
message = ''
|
|
|
|
services.xserver.desktopManager.default and
|
|
|
|
services.xserver.windowMananger.default are not set to valid
|
|
|
|
values. The current default session: ${defaultSessionName}
|
|
|
|
is not valid.
|
|
|
|
'';
|
|
|
|
}
|
2016-07-17 18:51:55 +02:00
|
|
|
{ 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.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2013-10-15 17:22:30 +02:00
|
|
|
services.xserver.displayManager.slim.enable = false;
|
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
services.xserver.displayManager.job = {
|
2017-09-15 00:08:16 +02:00
|
|
|
logToFile = true;
|
2013-03-25 19:26:07 +01:00
|
|
|
|
|
|
|
# lightdm relaunches itself via just `lightdm`, so needs to be on the PATH
|
2013-10-28 01:14:16 +01:00
|
|
|
execCmd = ''
|
2013-03-25 19:26:07 +01:00
|
|
|
export PATH=${lightdm}/sbin:$PATH
|
2015-03-10 01:59:21 +01:00
|
|
|
exec ${lightdm}/sbin/lightdm --log-dir=/var/log --run-dir=/run
|
2013-03-25 19:26:07 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-03-10 01:59:21 +01:00
|
|
|
environment.etc."lightdm/lightdm.conf".source = lightdmConf;
|
2015-03-10 02:04:40 +01:00
|
|
|
environment.etc."lightdm/users.conf".source = usersConf;
|
2015-03-10 01:59:21 +01:00
|
|
|
|
2013-03-25 19:26:07 +01:00
|
|
|
services.dbus.enable = true;
|
|
|
|
services.dbus.packages = [ lightdm ];
|
|
|
|
|
2016-10-15 14:16:47 +02:00
|
|
|
# lightdm uses the accounts daemon to rember language/window-manager per user
|
|
|
|
services.accounts-daemon.enable = true;
|
|
|
|
|
2015-05-22 04:06:03 +02:00
|
|
|
security.pam.services.lightdm = {
|
|
|
|
allowNullPassword = true;
|
|
|
|
startSession = true;
|
|
|
|
};
|
|
|
|
security.pam.services.lightdm-greeter = {
|
|
|
|
allowNullPassword = true;
|
|
|
|
startSession = true;
|
|
|
|
text = ''
|
2015-11-22 21:25:11 +01:00
|
|
|
auth required pam_env.so envfile=${config.system.build.pamEnvironment}
|
2015-05-22 04:06:03 +02: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 18:51:55 +02: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 19:26:07 +01:00
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.lightdm = {
|
2013-03-25 19:26:07 +01:00
|
|
|
createHome = true;
|
2015-03-10 22:55:54 +01:00
|
|
|
home = "/var/lib/lightdm-data";
|
2013-08-26 15:20:25 +02:00
|
|
|
group = "lightdm";
|
|
|
|
uid = config.ids.uids.lightdm;
|
2013-03-25 19:26:07 +01:00
|
|
|
};
|
2013-08-26 15:20:25 +02:00
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups.lightdm.gid = config.ids.gids.lightdm;
|
2015-11-29 01:18:59 +01: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 19:26:07 +01:00
|
|
|
};
|
|
|
|
}
|