3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/x11/display-managers/sddm.nix

288 lines
8.5 KiB
Nix
Raw Normal View History

2015-03-02 17:58:35 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
xcfg = config.services.xserver;
dmcfg = xcfg.displayManager;
cfg = dmcfg.sddm;
2019-08-13 22:52:01 +01:00
xEnv = config.systemd.services.display-manager.environment;
2015-03-02 17:58:35 +00:00
2020-12-16 13:33:40 +00:00
sddm = pkgs.libsForQt5.sddm;
2015-12-11 12:58:04 +00:00
iniFmt = pkgs.formats.ini { };
xserverWrapper = pkgs.writeShellScript "xserver-wrapper" ''
2015-03-02 17:58:35 +00:00
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
exec systemd-cat -t xserver-wrapper ${dmcfg.xserverBin} ${toString dmcfg.xserverArgs} "$@"
2015-03-02 17:58:35 +00:00
'';
Xsetup = pkgs.writeShellScript "Xsetup" ''
${cfg.setupScript}
nixos/xserver: Implement configuration of NVIDIA Optimus via PRIME This adds configuration options which automate the configuration of NVIDIA Optimus using PRIME. This allows using the NVIDIA proprietary driver on Optimus laptops, in order to render using the NVIDIA GPU while outputting to displays connected only to the integrated Intel GPU. It also adds an option for enabling kernel modesetting for the NVIDIA driver (via a kernel command line flag); this is particularly useful together with Optimus/PRIME because it fixes tearing on PRIME-connected screens. The user still needs to enable the Optimus/PRIME feature and specify the bus IDs of the Intel and NVIDIA GPUs, but this is still much easier for users and more reliable. The implementation handles both the X configuration file as well as getting display managers to run certain necessary `xrandr` commands just after X has started. Configuration of commands run after X startup is done using a new configuration option `services.xserver.displayManager.setupCommands`. Support for this option is implemented for LightDM, GDM and SDDM; all of these have been tested with this feature including logging into a Plasma session. Note: support of `setupCommands` for GDM is implemented by making GDM run the session executable via a wrapper; the wrapper will run the `setupCommands` before execing. This seemed like the simplest and most reliable approach, and solves running these commands both for GDM's X server and user X servers (GDM starts separate X servers for itself and user sessions). An alternative approach would be with autostart files but that seems harder to set up and less reliable. Note that some simple features for X configuration file generation (in `xserver.nix`) are added which are used in the implementation: - `services.xserver.extraConfig`: Allows adding arbitrary new sections. This is used to add the Device section for the Intel GPU. - `deviceSection` and `screenSection` within `services.xserver.drivers`. This allows the nvidia configuration module to add additional contents into the `Device` and `Screen` sections of the "nvidia" driver, and not into such sections for other drivers that may be enabled.
2018-06-30 08:33:45 +01:00
${dmcfg.setupCommands}
'';
Xstop = pkgs.writeShellScript "Xstop" ''
${cfg.stopScript}
'';
defaultConfig = {
General = {
HaltCommand = "/run/current-system/systemd/bin/systemctl poweroff";
RebootCommand = "/run/current-system/systemd/bin/systemctl reboot";
Numlock = if cfg.autoNumlock then "on" else "none"; # on, off none
};
Theme = {
Current = cfg.theme;
ThemeDir = "/run/current-system/sw/share/sddm/themes";
FacesDir = "/run/current-system/sw/share/sddm/faces";
};
Users = {
MaximumUid = config.ids.uids.nixbld;
HideUsers = concatStringsSep "," dmcfg.hiddenUsers;
HideShells = "/run/current-system/sw/bin/nologin";
};
2015-03-02 17:58:35 +00:00
X11 = {
MinimumVT = if xcfg.tty != null then xcfg.tty else 7;
ServerPath = toString xserverWrapper;
XephyrPath = "${pkgs.xorg.xorgserver.out}/bin/Xephyr";
SessionCommand = toString dmcfg.sessionData.wrapper;
SessionDir = "${dmcfg.sessionData.desktops}/share/xsessions";
XauthPath = "${pkgs.xorg.xauth}/bin/xauth";
DisplayCommand = toString Xsetup;
DisplayStopCommand = toString Xstop;
EnableHiDPI = cfg.enableHidpi;
};
Wayland = {
EnableHiDPI = cfg.enableHidpi;
SessionDir = "${dmcfg.sessionData.desktops}/share/wayland-sessions";
};
} // lib.optionalAttrs dmcfg.autoLogin.enable {
Autologin = {
User = dmcfg.autoLogin.user;
Session = autoLoginSessionName;
Relogin = cfg.autoLogin.relogin;
};
};
cfgFile =
iniFmt.generate "sddm.conf" (lib.recursiveUpdate defaultConfig cfg.settings);
autoLoginSessionName =
"${dmcfg.sessionData.autologinSession}.desktop";
2015-03-02 17:58:35 +00:00
in
{
imports = [
(mkRemovedOptionModule
[ "services" "xserver" "displayManager" "sddm" "themes" ]
"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" ])
(mkRemovedOptionModule
[ "services" "xserver" "displayManager" "sddm" "extraConfig" ]
"Set the option `services.xserver.displayManager.sddm.settings' instead.")
];
2015-03-02 17:58:35 +00:00
options = {
services.xserver.displayManager.sddm = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable sddm as the display manager.
'';
};
2018-05-16 05:15:29 +01:00
enableHidpi = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable automatic HiDPI mode.
'';
};
settings = mkOption {
type = iniFmt.type;
default = { };
2015-10-17 18:11:22 +01:00
example = ''
{
Autologin = {
User = "john";
Session = "plasma.desktop";
};
}
2015-10-17 18:11:22 +01:00
'';
description = ''
Extra settings merged in and overwritting defaults in sddm.conf.
2015-10-17 18:11:22 +01:00
'';
};
2015-03-02 17:58:35 +00:00
theme = mkOption {
type = types.str;
2016-09-16 09:13:45 +01:00
default = "";
2015-03-02 17:58:35 +00:00
description = ''
Greeter theme to use.
'';
};
autoNumlock = mkOption {
type = types.bool;
default = false;
description = ''
Enable numlock at login.
'';
};
setupScript = mkOption {
type = types.str;
default = "";
example = ''
# workaround for using NVIDIA Optimus without Bumblebee
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
'';
description = ''
nixos/xserver: Implement configuration of NVIDIA Optimus via PRIME This adds configuration options which automate the configuration of NVIDIA Optimus using PRIME. This allows using the NVIDIA proprietary driver on Optimus laptops, in order to render using the NVIDIA GPU while outputting to displays connected only to the integrated Intel GPU. It also adds an option for enabling kernel modesetting for the NVIDIA driver (via a kernel command line flag); this is particularly useful together with Optimus/PRIME because it fixes tearing on PRIME-connected screens. The user still needs to enable the Optimus/PRIME feature and specify the bus IDs of the Intel and NVIDIA GPUs, but this is still much easier for users and more reliable. The implementation handles both the X configuration file as well as getting display managers to run certain necessary `xrandr` commands just after X has started. Configuration of commands run after X startup is done using a new configuration option `services.xserver.displayManager.setupCommands`. Support for this option is implemented for LightDM, GDM and SDDM; all of these have been tested with this feature including logging into a Plasma session. Note: support of `setupCommands` for GDM is implemented by making GDM run the session executable via a wrapper; the wrapper will run the `setupCommands` before execing. This seemed like the simplest and most reliable approach, and solves running these commands both for GDM's X server and user X servers (GDM starts separate X servers for itself and user sessions). An alternative approach would be with autostart files but that seems harder to set up and less reliable. Note that some simple features for X configuration file generation (in `xserver.nix`) are added which are used in the implementation: - `services.xserver.extraConfig`: Allows adding arbitrary new sections. This is used to add the Device section for the Intel GPU. - `deviceSection` and `screenSection` within `services.xserver.drivers`. This allows the nvidia configuration module to add additional contents into the `Device` and `Screen` sections of the "nvidia" driver, and not into such sections for other drivers that may be enabled.
2018-06-30 08:33:45 +01:00
A script to execute when starting the display server. DEPRECATED, please
use <option>services.xserver.displayManager.setupCommands</option>.
'';
};
stopScript = mkOption {
type = types.str;
default = "";
description = ''
A script to execute when stopping the display server.
'';
};
# Configuration for automatic login specific to SDDM
autoLogin = {
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.
'';
};
minimumUid = mkOption {
type = types.ints.u16;
default = 1000;
description = ''
Minimum user ID for auto-login user.
'';
};
};
2015-03-02 17:58:35 +00:00
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = xcfg.enable;
message = ''
SDDM requires services.xserver.enable to be true
'';
}
{
assertion = dmcfg.autoLogin.enable -> autoLoginSessionName != null;
message = ''
SDDM auto-login requires that services.xserver.displayManager.defaultSession is set.
2015-12-12 17:33:39 +00:00
'';
}
];
2015-03-02 17:58:35 +00:00
services.xserver.displayManager.job = {
environment = {
# Load themes from system environment
QT_PLUGIN_PATH = "/run/current-system/sw/" + pkgs.qt5.qtbase.qtPluginPrefix;
QML2_IMPORT_PATH = "/run/current-system/sw/" + pkgs.qt5.qtbase.qtQmlPrefix;
};
execCmd = "exec /run/current-system/sw/bin/sddm";
2015-03-02 17:58:35 +00:00
};
security.pam.services = {
sddm = {
allowNullPassword = true;
startSession = true;
};
sddm-greeter.text = ''
auth required pam_succeed_if.so audit quiet_success user = sddm
auth optional pam_permit.so
account required pam_succeed_if.so audit quiet_success user = sddm
account sufficient pam_unix.so
password required pam_deny.so
session required pam_succeed_if.so audit quiet_success user = sddm
session required pam_env.so conffile=${config.system.build.pamEnvironment} readenv=0
2015-03-02 17:58:35 +00:00
session optional ${pkgs.systemd}/lib/security/pam_systemd.so
session optional pam_keyinit.so force revoke
session optional pam_permit.so
'';
sddm-autologin.text = ''
auth requisite pam_nologin.so
auth required pam_succeed_if.so uid >= ${toString cfg.autoLogin.minimumUid} quiet
auth required pam_permit.so
account include sddm
password include sddm
session include sddm
'';
2015-03-02 17:58:35 +00:00
};
users.users.sddm = {
2015-03-02 17:58:35 +00:00
createHome = true;
home = "/var/lib/sddm";
group = "sddm";
uid = config.ids.uids.sddm;
};
environment.etc."sddm.conf".source = cfgFile;
environment.pathsToLink = [
"/share/sddm"
];
2015-03-02 17:58:35 +00:00
users.groups.sddm.gid = config.ids.gids.sddm;
2015-03-02 17:58:35 +00:00
environment.systemPackages = [ sddm ];
services.dbus.packages = [ sddm ];
# To enable user switching, allow sddm to allocate TTYs/displays dynamically.
services.xserver.tty = null;
services.xserver.display = null;
2018-07-09 07:51:05 +01:00
systemd.tmpfiles.rules = [
# Prior to Qt 5.9.2, there is a QML cache invalidation bug which sometimes
# strikes new Plasma 5 releases. If the QML cache is not invalidated, SDDM
# will segfault without explanation. We really tore our hair out for awhile
# before finding the bug:
# https://bugreports.qt.io/browse/QTBUG-62302
# We work around the problem by deleting the QML cache before startup.
# This was supposedly fixed in Qt 5.9.2 however it has been reported with
# 5.10 and 5.11 as well. The initial workaround was to delete the directory
# in the Xsetup script but that doesn't do anything.
# Instead we use tmpfiles.d to ensure it gets wiped.
# This causes a small but perceptible delay when SDDM starts.
"e ${config.users.users.sddm.home}/.cache - - - 0"
];
2015-03-02 17:58:35 +00:00
};
}