summary refs log tree commit diff
path: root/nixos/modules/services/x11/desktop-managers/kde4.nix
blob: 25ae75592c9d13b2d22c7fa472d65d36f7385ffe (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{ config, lib, pkgs, ... }:

with lib;

let

  xcfg = config.services.xserver;
  cfg = xcfg.desktopManager.kde4;
  xorg = pkgs.xorg;
  kde_workspace = config.services.xserver.desktopManager.kde4.kdeWorkspacePackage;

  # Disable Nepomuk and Strigi by default.  As of KDE 4.7, they don't
  # really work very well (e.g. searching files often fails to find
  # files), segfault sometimes and consume significant resources.
  # They can be re-enabled in the KDE System Settings under "Desktop
  # Search".
  disableNepomuk = pkgs.writeTextFile
    { name = "nepomuk-config";
      destination = "/share/config/nepomukserverrc";
      text =
        ''
          [Basic Settings]
          Start Nepomuk=false

          [Service-nepomukstrigiservice]
          autostart=false
        '';
    };

  phononBackends = {
    gstreamer = [
      pkgs.phonon-backend-gstreamer
      pkgs.gst_all.gstPluginsBase
      pkgs.gst_all.gstPluginsGood
      pkgs.gst_all.gstPluginsUgly
      pkgs.gst_all.gstPluginsBad
      pkgs.gst_all.gstFfmpeg # for mp3 playback
      pkgs.gst_all.gstreamer # needed?
    ];

    vlc = [pkgs.phonon-backend-vlc];
  };

  phononBackendPackages = flip concatMap cfg.phononBackends
    (name: attrByPath [name] (throw "unknown phonon backend `${name}'") phononBackends);

in

{
  options = {

    services.xserver.desktopManager.kde4 = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Enable the KDE 4 desktop environment.";
      };

      phononBackends = mkOption {
        type = types.listOf types.str;
        default = ["gstreamer"];
        example = ["gstreamer" "vlc"];
        description = "Which phonon multimedia backend kde should use";
      };

      kdeWorkspacePackage = mkOption {
        internal = true;
        default = pkgs.kde4.kde_workspace;
        defaultText = "pkgs.kde4.kde_workspace";
        type = types.package;
        description = "Custom kde-workspace, used for NixOS rebranding.";
      };

      enablePIM = mkOption {
        type = types.bool;
        default = true;
        description = "Whether to enable PIM support. Note that enabling this pulls in Akonadi and MariaDB as dependencies.";
      };

      enableNepomuk = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable Nepomuk (deprecated).";
      };
    };
  };


  config = mkIf (xcfg.enable && cfg.enable) {

    # If KDE 4 is enabled, make it the default desktop manager (unless
    # overridden by the user's configuration).
    # !!! doesn't work yet ("Multiple definitions. Only one is allowed
    # for this option.")
    # services.xserver.desktopManager.default = mkOverride 900 "kde4";

    services.xserver.desktopManager.session = singleton
      { name = "kde4";
        bgSupport = true;
        start =
          ''
            # The KDE icon cache is supposed to update itself
            # automatically, but it uses the timestamp on the icon
            # theme directory as a trigger.  Since in Nix the
            # timestamp is always the same, this doesn't work.  So as
            # a workaround, nuke the icon cache on login.  This isn't
            # perfect, since it may require logging out after
            # installing new applications to update the cache.
            # See http://lists-archives.org/kde-devel/26175-what-when-will-icon-cache-refresh.html
            rm -fv $HOME/.kde/cache-*/icon-cache.kcache

            # Qt writes a weird ‘libraryPath’ line to
            # ~/.config/Trolltech.conf that causes the KDE plugin
            # paths of previous KDE invocations to be searched.
            # Obviously using mismatching KDE libraries is potentially
            # disastrous, so here we nuke references to the Nix store
            # in Trolltech.conf.  A better solution would be to stop
            # Qt from doing this wackiness in the first place.
            if [ -e $HOME/.config/Trolltech.conf ]; then
                sed -e '/nix\\store\|nix\/store/ d' -i $HOME/.config/Trolltech.conf
            fi

            # Load PulseAudio module for routing support.
            # See http://colin.guthr.ie/2009/10/so-how-does-the-kde-pulseaudio-support-work-anyway/
            ${optionalString config.hardware.pulseaudio.enable ''
              ${getBin config.hardware.pulseaudio.package}/bin/pactl load-module module-device-manager "do_routing=1"
            ''}

            # Start KDE.
            exec ${kde_workspace}/bin/startkde
          '';
      };

    security.wrappers.kcheckpass.source = "${kde_workspace}/lib/kde4/libexec/kcheckpass";

    environment.systemPackages =
        [ pkgs.kde4.kdelibs

          pkgs.kde4.kde_baseapps # Splitted kdebase
          kde_workspace
          pkgs.kde4.kde_runtime
          pkgs.kde4.konsole
          pkgs.kde4.kate

          pkgs.kde4.kde_wallpapers # contains kdm's default background
          pkgs.kde4.oxygen_icons

          # Starts KDE's Polkit authentication agent.
          pkgs.kde4.polkit_kde_agent

          # Miscellaneous runtime dependencies.
          pkgs.kde4.qt4 # needed for qdbus
          pkgs.shared_mime_info
          xorg.xmessage # so that startkde can show error messages
          xorg.xset # used by startkde, non-essential
          xorg.xauth # used by kdesu
        ]
      ++ optionals cfg.enablePIM
        [ pkgs.kde4.kdepim_runtime
          pkgs.kde4.akonadi
          pkgs.mysql # used by akonadi
        ]
      ++ (if cfg.enableNepomuk then
        [ pkgs.shared_desktop_ontologies # used by nepomuk
          pkgs.strigi # used by nepomuk
          pkgs.virtuoso # to enable Nepomuk to find Virtuoso
        ] else
        [ disableNepomuk ])
      ++ optional config.hardware.pulseaudio.enable pkgs.kde4.kmix  # Perhaps this should always be enabled
      ++ optional config.hardware.bluetooth.enable pkgs.kde4.bluedevil
      ++ optional config.networking.networkmanager.enable pkgs.kde4.plasma-nm
      ++ phononBackendPackages;

    environment.pathsToLink = [ "/share" ];

    environment.profileRelativeEnvVars = mkIf (elem "gstreamer" cfg.phononBackends) {
      GST_PLUGIN_SYSTEM_PATH = [ "/lib/gstreamer-0.10" ];
    };

    environment.etc = singleton
      { source = "${pkgs.xkeyboard_config}/etc/X11/xkb";
        target = "X11/xkb";
      };

    # Enable helpful DBus services.
    services.udisks2.enable = true;
    services.upower.enable = config.powerManagement.enable;

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

  };

}