1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 xcfg = config.services.xserver; 8 cfg = xcfg.desktopManager.kde4; 9 xorg = pkgs.xorg; 10 kde_workspace = config.services.xserver.desktopManager.kde4.kdeWorkspacePackage; 11 12 # Disable Nepomuk and Strigi by default. As of KDE 4.7, they don't 13 # really work very well (e.g. searching files often fails to find 14 # files), segfault sometimes and consume significant resources. 15 # They can be re-enabled in the KDE System Settings under "Desktop 16 # Search". 17 nepomukConfig = pkgs.writeTextFile 18 { name = "nepomuk-config"; 19 destination = "/share/config/nepomukserverrc"; 20 text = 21 '' 22 [Basic Settings] 23 Start Nepomuk=false 24 25 [Service-nepomukstrigiservice] 26 autostart=false 27 ''; 28 }; 29 30 phononBackends = { 31 gstreamer = [ 32 pkgs.phonon-backend-gstreamer 33 pkgs.gst_all.gstPluginsBase 34 pkgs.gst_all.gstPluginsGood 35 pkgs.gst_all.gstPluginsUgly 36 pkgs.gst_all.gstPluginsBad 37 pkgs.gst_all.gstFfmpeg # for mp3 playback 38 pkgs.gst_all.gstreamer # needed? 39 ]; 40 41 vlc = [pkgs.phonon-backend-vlc]; 42 }; 43 44 phononBackendPackages = flip concatMap cfg.phononBackends 45 (name: attrByPath [name] (throw "unknown phonon backend `${name}'") phononBackends); 46 47in 48 49{ 50 options = { 51 52 services.xserver.desktopManager.kde4 = { 53 enable = mkOption { 54 type = types.bool; 55 default = false; 56 description = "Enable the KDE 4 desktop environment."; 57 }; 58 59 phononBackends = mkOption { 60 type = types.listOf types.str; 61 default = ["gstreamer"]; 62 example = ["gstreamer" "vlc"]; 63 description = "Which phonon multimedia backend kde should use"; 64 }; 65 66 kdeWorkspacePackage = mkOption { 67 internal = true; 68 default = pkgs.kde4.kde_workspace; 69 defaultText = "pkgs.kde4.kde_workspace"; 70 type = types.package; 71 description = "Custom kde-workspace, used for NixOS rebranding."; 72 }; 73 }; 74 }; 75 76 77 config = mkIf (xcfg.enable && cfg.enable) { 78 79 # If KDE 4 is enabled, make it the default desktop manager (unless 80 # overridden by the user's configuration). 81 # !!! doesn't work yet ("Multiple definitions. Only one is allowed 82 # for this option.") 83 # services.xserver.desktopManager.default = mkOverride 900 "kde4"; 84 85 services.xserver.desktopManager.session = singleton 86 { name = "kde4"; 87 bgSupport = true; 88 start = 89 '' 90 # The KDE icon cache is supposed to update itself 91 # automatically, but it uses the timestamp on the icon 92 # theme directory as a trigger. Since in Nix the 93 # timestamp is always the same, this doesn't work. So as 94 # a workaround, nuke the icon cache on login. This isn't 95 # perfect, since it may require logging out after 96 # installing new applications to update the cache. 97 # See http://lists-archives.org/kde-devel/26175-what-when-will-icon-cache-refresh.html 98 rm -fv $HOME/.kde/cache-*/icon-cache.kcache 99 100 # Qt writes a weird libraryPath line to 101 # ~/.config/Trolltech.conf that causes the KDE plugin 102 # paths of previous KDE invocations to be searched. 103 # Obviously using mismatching KDE libraries is potentially 104 # disastrous, so here we nuke references to the Nix store 105 # in Trolltech.conf. A better solution would be to stop 106 # Qt from doing this wackiness in the first place. 107 if [ -e $HOME/.config/Trolltech.conf ]; then 108 sed -e '/nix\\store\|nix\/store/ d' -i $HOME/.config/Trolltech.conf 109 fi 110 111 # Load PulseAudio module for routing support. 112 # See http://colin.guthr.ie/2009/10/so-how-does-the-kde-pulseaudio-support-work-anyway/ 113 ${optionalString config.hardware.pulseaudio.enable '' 114 ${getBin config.hardware.pulseaudio.package}/bin/pactl load-module module-device-manager "do_routing=1" 115 ''} 116 117 # Start KDE. 118 exec ${kde_workspace}/bin/startkde 119 ''; 120 }; 121 122 security.setuidOwners = singleton 123 { program = "kcheckpass"; 124 source = "${kde_workspace}/lib/kde4/libexec/kcheckpass"; 125 owner = "root"; 126 group = "root"; 127 setuid = true; 128 }; 129 130 environment.systemPackages = 131 [ pkgs.kde4.kdelibs 132 133 pkgs.kde4.kde_baseapps # Splitted kdebase 134 kde_workspace 135 pkgs.kde4.kde_runtime 136 pkgs.kde4.konsole 137 pkgs.kde4.kate 138 139 pkgs.kde4.kde_wallpapers # contains kdm's default background 140 pkgs.kde4.oxygen_icons 141 pkgs.virtuoso # to enable Nepomuk to find Virtuoso 142 143 # Starts KDE's Polkit authentication agent. 144 pkgs.kde4.polkit_kde_agent 145 146 # Miscellaneous runtime dependencies. 147 pkgs.kde4.qt4 # needed for qdbus 148 pkgs.shared_mime_info 149 xorg.xmessage # so that startkde can show error messages 150 xorg.xset # used by startkde, non-essential 151 xorg.xauth # used by kdesu 152 pkgs.shared_desktop_ontologies # used by nepomuk 153 pkgs.strigi # used by nepomuk 154 pkgs.kde4.akonadi 155 pkgs.mysql # used by akonadi 156 pkgs.kde4.kdepim_runtime 157 ] 158 ++ lib.optional config.hardware.pulseaudio.enable pkgs.kde4.kmix # Perhaps this should always be enabled 159 ++ lib.optional config.hardware.bluetooth.enable pkgs.kde4.bluedevil 160 ++ lib.optional config.networking.networkmanager.enable pkgs.kde4.plasma-nm 161 ++ [ nepomukConfig ] ++ phononBackendPackages; 162 163 environment.pathsToLink = [ "/share" ]; 164 165 environment.profileRelativeEnvVars = mkIf (lib.elem "gstreamer" cfg.phononBackends) { 166 GST_PLUGIN_SYSTEM_PATH = [ "/lib/gstreamer-0.10" ]; 167 }; 168 169 environment.etc = singleton 170 { source = "${pkgs.xkeyboard_config}/etc/X11/xkb"; 171 target = "X11/xkb"; 172 }; 173 174 # Enable helpful DBus services. 175 services.udisks2.enable = true; 176 services.upower.enable = config.powerManagement.enable; 177 178 security.pam.services.kde = { allowNullPassword = true; }; 179 180 }; 181 182}