summary refs log tree commit diff
path: root/nixos/modules/services/x11/display-managers/slim.nix
blob: 4e411c8ceb0be8bd1c43044553ddd2be16e6b361 (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
{ config, lib, pkgs, ... }:

with lib;

let

  dmcfg = config.services.xserver.displayManager;

  cfg = dmcfg.slim;

  slimConfig = pkgs.writeText "slim.cfg"
    ''
      xauth_path ${dmcfg.xauthBin}
      default_xserver ${dmcfg.xserverBin}
      xserver_arguments ${toString dmcfg.xserverArgs}
      sessiondir ${dmcfg.session.desktops}/share/xsessions
      login_cmd exec ${pkgs.runtimeShell} ${dmcfg.session.wrapper} "%session"
      halt_cmd ${config.systemd.package}/sbin/shutdown -h now
      reboot_cmd ${config.systemd.package}/sbin/shutdown -r now
      logfile /dev/stderr
      ${optionalString (cfg.defaultUser != null) ("default_user " + cfg.defaultUser)}
      ${optionalString (cfg.defaultUser != null) ("focus_password yes")}
      ${optionalString cfg.autoLogin "auto_login yes"}
      ${optionalString (cfg.consoleCmd != null) "console_cmd ${cfg.consoleCmd}"}
      ${cfg.extraConfig}
    '';

  # Unpack the SLiM theme, or use the default.
  slimThemesDir =
    let
      unpackedTheme = pkgs.runCommand "slim-theme" {}
        ''
          mkdir -p $out
          cd $out
          unpackFile ${cfg.theme}
          ln -s * default
        '';
    in if cfg.theme == null then "${pkgs.slim}/share/slim/themes" else unpackedTheme;

in

{

  ###### interface

  options = {

    services.xserver.displayManager.slim = {

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

      theme = mkOption {
        type = types.nullOr types.path;
        default = pkgs.fetchurl {
          url = "https://github.com/jagajaga/nixos-slim-theme/archive/2.0.tar.gz";
          sha256 = "0lldizhigx7bjhxkipii87y432hlf5wdvamnfxrryf9z7zkfypc8";
        };
        defaultText = ''pkgs.fetchurl {
          url = "https://github.com/jagajaga/nixos-slim-theme/archive/2.0.tar.gz";
          sha256 = "0lldizhigx7bjhxkipii87y432hlf5wdvamnfxrryf9z7zkfypc8";
        }'';
        example = literalExample ''
          pkgs.fetchurl {
            url = "mirror://sourceforge/slim.berlios/slim-wave.tar.gz";
            sha256 = "0ndr419i5myzcylvxb89m9grl2xyq6fbnyc3lkd711mzlmnnfxdy";
          }
        '';
        description = ''
          The theme for the SLiM login manager.  If not specified, SLiM's
          default theme is used.  See <link
          xlink:href='http://slim.berlios.de/themes01.php'/> for a
          collection of themes. TODO: berlios shut down.
        '';
      };

      defaultUser = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "login";
        description = ''
          The default user to load. If you put a username here you
          get it automatically loaded into the username field, and
          the focus is placed on the password.
        '';
      };

      autoLogin = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Automatically log in as the default user.
        '';
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        description = ''
          Extra configuration options for SLiM login manager. Do not
          add options that can be configured directly.
        '';
      };

      consoleCmd = mkOption {
        type = types.nullOr types.str;
        default = ''
          ${pkgs.xterm}/bin/xterm -C -fg white -bg black +sb -T "Console login" -e ${pkgs.shadow}/bin/login
        '';
        defaultText = ''
          ''${pkgs.xterm}/bin/xterm -C -fg white -bg black +sb -T "Console login" -e ''${pkgs.shadow}/bin/login
        '';
        description = ''
          The command to run when "console" is given as the username.
        '';
      };
    };

  };


  ###### implementation

  config = mkIf cfg.enable {

    services.xserver.displayManager.job =
      { environment =
          { SLIM_CFGFILE = slimConfig;
            SLIM_THEMESDIR = slimThemesDir;
          };
        execCmd = "exec ${pkgs.slim}/bin/slim";
      };

    services.xserver.displayManager.sessionCommands =
      ''
        # Export the config/themes for slimlock.
        export SLIM_THEMESDIR=${slimThemesDir}
      '';

    # Allow null passwords so that the user can login as root on the
    # installation CD.
    security.pam.services.slim = { allowNullPassword = true; startSession = true; };

    # Allow slimlock to work.
    security.pam.services.slimlock = {};

    environment.systemPackages = [ pkgs.slim ];

  };

}