summary refs log tree commit diff
path: root/nixos/modules/services/x11/display-managers/kdm.nix
blob: 9b937ff7ee18ec95f2bdf0fe095ca8a34145ed6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{ config, lib, pkgs, ... }:

with lib;

let

  dmcfg = config.services.xserver.displayManager;
  cfg = dmcfg.kdm;

  inherit (pkgs.kde4) kdebase_workspace;

  defaultConfig =
    ''
      [Shutdown]
      HaltCmd=${config.systemd.package}/sbin/shutdown -h now
      RebootCmd=${config.systemd.package}/sbin/shutdown -r now
      ${optionalString (config.system.boot.loader.id == "grub") ''
        BootManager=${if config.boot.loader.grub.version == 2 then "Grub2" else "Grub"}
      ''}

      [X-*-Core]
      Xrdb=${pkgs.xorg.xrdb}/bin/xrdb
      SessionsDirs=${dmcfg.session.desktops}
      Session=${dmcfg.session.script}
      FailsafeClient=${pkgs.xterm}/bin/xterm

      [X-:*-Core]
      ServerCmd=${dmcfg.xserverBin} ${dmcfg.xserverArgs}
      # KDM calls `rm' somewhere to clean up some temporary directory.
      SystemPath=${pkgs.coreutils}/bin
      # The default timeout (15) is too short in a heavily loaded boot process.
      ServerTimeout=60
      # Needed to prevent the X server from dying on logout and not coming back:
      TerminateServer=true
      ${optionalString (cfg.setupScript != "")
      ''
        Setup=${cfg.setupScript}
      ''} 

      [X-*-Greeter]
      HiddenUsers=root,${concatStringsSep "," dmcfg.hiddenUsers}
      PluginsLogin=${kdebase_workspace}/lib/kde4/kgreet_classic.so
      ${optionalString (cfg.themeDirectory != null)
      ''
        UseTheme=true
        Theme=${cfg.themeDirectory}
      ''
      }

      ${optionalString (cfg.enableXDMCP)
      ''
        [Xdmcp]
        Enable=true
      ''}
    '';

  kdmrc = pkgs.stdenv.mkDerivation {
    name = "kdmrc";
    config = defaultConfig + cfg.extraConfig;
    preferLocalBuild = true;
    buildCommand =
      ''
        echo "$config" > $out

        # The default kdmrc would add "-nolisten tcp", and we already
        # have that managed by nixos. Hence the grep.
        cat ${kdebase_workspace}/share/config/kdm/kdmrc | grep -v nolisten >> $out
      '';
  };

in

{

  ###### interface

  options = {

    services.xserver.displayManager.kdm = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to enable the KDE display manager.
        '';
      };

      enableXDMCP = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to enable XDMCP, which allows remote logins.
        '';
      };

      themeDirectory = mkOption {
        type = types.nullOr types.str;
        default = null;
        description = ''
          The path to a KDM theme directory. This theme
          will be used by the KDM greeter.
        '';
      };

      setupScript = mkOption {
        type = types.lines;
        default = "";
        description = ''
          The path to a KDM setup script. This script is run as root just
          before KDM starts. Can be used for setting up
          monitors with xrandr, for example.
        '';
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = ''
          Options appended to <filename>kdmrc</filename>, the
          configuration file of KDM.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf cfg.enable {

    services.xserver.displayManager.slim.enable = false;

    services.xserver.displayManager.job =
      { execCmd =
          ''
            mkdir -m 0755 -p /var/lib/kdm
            chown kdm /var/lib/kdm
            ${(optionalString (config.system.boot.loader.id == "grub" && config.system.build.grub != null) "PATH=${config.system.build.grub}/sbin:$PATH ") +
              "KDEDIRS=/run/current-system/sw exec ${kdebase_workspace}/bin/kdm -config ${kdmrc} -nodaemon"}
          '';
        logsXsession = true;
      };

    security.pam.services.kde = { allowNullPassword = true; startSession = true; };

    users.extraUsers = singleton
      { name = "kdm";
        uid = config.ids.uids.kdm;
        description = "KDM user";
      };

    environment.systemPackages =
      [ pkgs.kde4.kde_wallpapers ]; # contains kdm's default background

  };

}