2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
xcfg = config.services.xserver;
|
2024-04-21 15:54:59 +00:00
|
|
|
dmcfg = config.services.displayManager;
|
|
|
|
cfg = config.services.displayManager.sddm;
|
2020-04-24 23:36:52 +00:00
|
|
|
xEnv = config.systemd.services.display-manager.environment;
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
sddm = cfg.package.override (old: {
|
2024-02-29 20:09:43 +00:00
|
|
|
withWayland = cfg.wayland.enable;
|
2024-04-21 15:54:59 +00:00
|
|
|
extraPackages = old.extraPackages or [ ] ++ cfg.extraPackages;
|
2024-02-29 20:09:43 +00:00
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
iniFmt = pkgs.formats.ini { };
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
inherit (lib)
|
|
|
|
concatMapStrings concatStringsSep getExe
|
|
|
|
attrNames getAttr optionalAttrs optionalString
|
|
|
|
mkRemovedOptionModule mkRenamedOptionModule mkIf mkEnableOption mkOption mkPackageOption types
|
|
|
|
;
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
xserverWrapper = pkgs.writeShellScript "xserver-wrapper" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
${concatMapStrings (n: "export ${n}=\"${getAttr n xEnv}\"\n") (attrNames xEnv)}
|
2024-04-21 15:54:59 +00:00
|
|
|
exec systemd-cat -t xserver-wrapper ${xcfg.displayManager.xserverBin} ${toString xcfg.displayManager.xserverArgs} "$@"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
Xsetup = pkgs.writeShellScript "Xsetup" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
${cfg.setupScript}
|
2024-04-21 15:54:59 +00:00
|
|
|
${xcfg.displayManager.setupCommands}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
Xstop = pkgs.writeShellScript "Xstop" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
${cfg.stopScript}
|
|
|
|
'';
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
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
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
# Implementation is done via pkgs/applications/display-managers/sddm/sddm-default-session.patch
|
2024-04-21 15:54:59 +00:00
|
|
|
DefaultSession = optionalString (config.services.displayManager.defaultSession != null) "${config.services.displayManager.defaultSession}.desktop";
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
DisplayServer = if cfg.wayland.enable then "wayland" else "x11";
|
2024-04-21 15:54:59 +00:00
|
|
|
} // optionalAttrs (cfg.wayland.compositor == "kwin") {
|
|
|
|
GreeterEnvironment = concatStringsSep " " [
|
|
|
|
"LANG=C.UTF-8"
|
|
|
|
"QT_WAYLAND_SHELL_INTEGRATION=layer-shell"
|
|
|
|
];
|
|
|
|
InputMethod = ""; # needed if we are using --inputmethod with kwin
|
2020-12-29 15:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Theme = {
|
|
|
|
Current = cfg.theme;
|
|
|
|
ThemeDir = "/run/current-system/sw/share/sddm/themes";
|
|
|
|
FacesDir = "/run/current-system/sw/share/sddm/faces";
|
2024-04-21 15:54:59 +00:00
|
|
|
} // optionalAttrs (cfg.theme == "breeze") {
|
|
|
|
CursorTheme = "breeze_cursors";
|
|
|
|
CursorSize = 24;
|
2020-12-29 15:07:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Users = {
|
|
|
|
MaximumUid = config.ids.uids.nixbld;
|
|
|
|
HideUsers = concatStringsSep "," dmcfg.hiddenUsers;
|
|
|
|
HideShells = "/run/current-system/sw/bin/nologin";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
Wayland = {
|
|
|
|
EnableHiDPI = cfg.enableHidpi;
|
|
|
|
SessionDir = "${dmcfg.sessionData.desktops}/share/wayland-sessions";
|
|
|
|
CompositorCommand = lib.optionalString cfg.wayland.enable cfg.wayland.compositorCommand;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // optionalAttrs xcfg.enable {
|
|
|
|
X11 = {
|
2020-12-29 15:07:52 +00:00
|
|
|
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;
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
} // optionalAttrs dmcfg.autoLogin.enable {
|
2020-12-29 15:07:52 +00:00
|
|
|
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";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
compositorCmds = {
|
|
|
|
kwin = concatStringsSep " " [
|
|
|
|
"${lib.getBin pkgs.kdePackages.kwin}/bin/kwin_wayland"
|
|
|
|
"--no-global-shortcuts"
|
|
|
|
"--no-kactivities"
|
|
|
|
"--no-lockscreen"
|
|
|
|
"--locale1"
|
|
|
|
];
|
|
|
|
# This is basically the upstream default, but with Weston referenced by full path
|
|
|
|
# and the configuration generated from NixOS options.
|
|
|
|
weston =
|
|
|
|
let
|
|
|
|
westonIni = (pkgs.formats.ini { }).generate "weston.ini" {
|
|
|
|
libinput = {
|
2024-05-15 15:35:15 +00:00
|
|
|
enable-tap = config.services.libinput.mouse.tapping;
|
|
|
|
left-handed = config.services.libinput.mouse.leftHanded;
|
2024-04-21 15:54:59 +00:00
|
|
|
};
|
|
|
|
keyboard = {
|
|
|
|
keymap_model = xcfg.xkb.model;
|
|
|
|
keymap_layout = xcfg.xkb.layout;
|
|
|
|
keymap_variant = xcfg.xkb.variant;
|
|
|
|
keymap_options = xcfg.xkb.options;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
"${getExe pkgs.weston} --shell=kiosk -c ${westonIni}";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
imports = [
|
2024-04-21 15:54:59 +00:00
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "minimumUid" ] [ "services" "displayManager" "sddm" "autoLogin" "minimumUid" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoLogin" "relogin" ] [ "services" "displayManager" "sddm" "autoLogin" "relogin" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "autoNumlock" ] [ "services" "displayManager" "sddm" "autoNumlock" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "enable" ] [ "services" "displayManager" "sddm" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "enableHidpi" ] [ "services" "displayManager" "sddm" "enableHidpi" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "extraPackages" ] [ "services" "displayManager" "sddm" "extraPackages" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "package" ] [ "services" "displayManager" "sddm" "package" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "settings" ] [ "services" "displayManager" "sddm" "settings" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "setupScript" ] [ "services" "displayManager" "sddm" "setupScript" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "stopScript" ] [ "services" "displayManager" "sddm" "stopScript" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "theme" ] [ "services" "displayManager" "sddm" "theme" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "xserver" "displayManager" "sddm" "wayland" "enable" ] [ "services" "displayManager" "sddm" "wayland" "enable" ])
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
(mkRemovedOptionModule
|
2024-04-21 15:54:59 +00:00
|
|
|
[ "services" "displayManager" "sddm" "themes" ]
|
|
|
|
"Set the option `services.displayManager.sddm.package' instead.")
|
2020-12-29 15:07:52 +00:00
|
|
|
(mkRenamedOptionModule
|
2024-04-21 15:54:59 +00:00
|
|
|
[ "services" "displayManager" "sddm" "autoLogin" "enable" ]
|
|
|
|
[ "services" "displayManager" "autoLogin" "enable" ])
|
2020-12-29 15:07:52 +00:00
|
|
|
(mkRenamedOptionModule
|
2024-04-21 15:54:59 +00:00
|
|
|
[ "services" "displayManager" "sddm" "autoLogin" "user" ]
|
|
|
|
[ "services" "displayManager" "autoLogin" "user" ])
|
2020-12-29 15:07:52 +00:00
|
|
|
(mkRemovedOptionModule
|
2024-04-21 15:54:59 +00:00
|
|
|
[ "services" "displayManager" "sddm" "extraConfig" ]
|
|
|
|
"Set the option `services.displayManager.sddm.settings' instead.")
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
services.displayManager.sddm = {
|
2020-04-24 23:36:52 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable sddm as the display manager.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
package = mkPackageOption pkgs [ "plasma5Packages" "sddm" ] { };
|
2024-01-13 08:15:51 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
enableHidpi = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable automatic HiDPI mode.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-12-29 15:07:52 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = iniFmt.type;
|
|
|
|
default = { };
|
2021-10-06 13:57:05 +00:00
|
|
|
example = {
|
|
|
|
Autologin = {
|
|
|
|
User = "john";
|
|
|
|
Session = "plasma.desktop";
|
|
|
|
};
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2022-12-28 21:21:41 +00:00
|
|
|
Extra settings merged in and overwriting defaults in sddm.conf.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
theme = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Greeter theme to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2024-04-21 15:54:59 +00:00
|
|
|
default = [ ];
|
2024-02-29 20:09:43 +00:00
|
|
|
defaultText = "[]";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2024-02-29 20:09:43 +00:00
|
|
|
Extra Qt plugins / QML libraries to add to the environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
autoNumlock = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
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
|
|
|
|
'';
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A script to execute when starting the display server. DEPRECATED, please
|
2022-08-12 12:06:08 +00:00
|
|
|
use {option}`services.xserver.displayManager.setupCommands`.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
stopScript = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
A script to execute when stopping the display server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
# Configuration for automatic login specific to SDDM
|
2020-12-29 15:07:52 +00:00
|
|
|
autoLogin = {
|
|
|
|
relogin = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-12-29 15:07:52 +00:00
|
|
|
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;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-12-29 15:07:52 +00:00
|
|
|
Minimum user ID for auto-login user.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2023-10-09 19:29:22 +00:00
|
|
|
|
|
|
|
# Experimental Wayland support
|
|
|
|
wayland = {
|
|
|
|
enable = mkEnableOption "experimental Wayland support";
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
compositor = mkOption {
|
|
|
|
description = "The compositor to use: ${lib.concatStringsSep ", " (builtins.attrNames compositorCmds)}";
|
|
|
|
type = types.enum (builtins.attrNames compositorCmds);
|
|
|
|
default = "weston";
|
|
|
|
};
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
compositorCommand = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
internal = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
default = compositorCmds.${cfg.wayland.compositor};
|
|
|
|
description = "Command used to start the selected compositor";
|
2023-10-09 19:29:22 +00:00
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = [
|
2020-12-29 15:07:52 +00:00
|
|
|
{
|
2024-04-21 15:54:59 +00:00
|
|
|
assertion = xcfg.enable || cfg.wayland.enable;
|
2020-04-24 23:36:52 +00:00
|
|
|
message = ''
|
2024-04-21 15:54:59 +00:00
|
|
|
SDDM requires either services.xserver.enable or services.displayManager.sddm.wayland.enable to be true
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
}
|
2020-12-29 15:07:52 +00:00
|
|
|
{
|
2024-04-21 15:54:59 +00:00
|
|
|
assertion = config.services.displayManager.autoLogin.enable -> autoLoginSessionName != null;
|
2020-04-24 23:36:52 +00:00
|
|
|
message = ''
|
2024-04-21 15:54:59 +00:00
|
|
|
SDDM auto-login requires that services.displayManager.defaultSession is set.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
services.displayManager = {
|
|
|
|
enable = true;
|
|
|
|
execCmd = "exec /run/current-system/sw/bin/sddm";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
security.pam.services = {
|
2023-03-04 12:14:45 +00:00
|
|
|
sddm.text = ''
|
|
|
|
auth substack login
|
|
|
|
account include login
|
|
|
|
password substack login
|
|
|
|
session include login
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
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
|
2021-08-22 07:53:02 +00:00
|
|
|
session required pam_env.so conffile=/etc/pam/environment readenv=0
|
2022-05-18 14:49:53 +00:00
|
|
|
session optional ${config.systemd.package}/lib/security/pam_systemd.so
|
2020-04-24 23:36:52 +00:00
|
|
|
session optional pam_keyinit.so force revoke
|
|
|
|
session optional pam_permit.so
|
|
|
|
'';
|
|
|
|
|
|
|
|
sddm-autologin.text = ''
|
|
|
|
auth requisite pam_nologin.so
|
2020-12-29 15:07:52 +00:00
|
|
|
auth required pam_succeed_if.so uid >= ${toString cfg.autoLogin.minimumUid} quiet
|
2020-04-24 23:36:52 +00:00
|
|
|
auth required pam_permit.so
|
|
|
|
|
|
|
|
account include sddm
|
|
|
|
|
|
|
|
password include sddm
|
|
|
|
|
|
|
|
session include sddm
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.sddm = {
|
|
|
|
createHome = true;
|
|
|
|
home = "/var/lib/sddm";
|
|
|
|
group = "sddm";
|
|
|
|
uid = config.ids.uids.sddm;
|
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
environment = {
|
|
|
|
etc."sddm.conf".source = cfgFile;
|
|
|
|
pathsToLink = [
|
|
|
|
"/share/sddm"
|
|
|
|
];
|
|
|
|
systemPackages = [ sddm ];
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
users.groups.sddm.gid = config.ids.gids.sddm;
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
services = {
|
|
|
|
dbus.packages = [ sddm ];
|
|
|
|
xserver = {
|
|
|
|
# To enable user switching, allow sddm to allocate TTYs/displays dynamically.
|
|
|
|
tty = null;
|
|
|
|
display = null;
|
|
|
|
};
|
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
systemd = {
|
|
|
|
tmpfiles.packages = [ sddm ];
|
|
|
|
|
|
|
|
# We're not using the upstream unit, so copy these: https://github.com/sddm/sddm/blob/develop/services/sddm.service.in
|
|
|
|
services.display-manager = {
|
|
|
|
after = [
|
|
|
|
"systemd-user-sessions.service"
|
|
|
|
"getty@tty7.service"
|
|
|
|
"plymouth-quit.service"
|
|
|
|
"systemd-logind.service"
|
|
|
|
];
|
|
|
|
conflicts = [
|
|
|
|
"getty@tty7.service"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|