You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gnome3.nix 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. { config, lib, pkgs, ... }:
  2. with lib;
  3. let
  4. cfg = config.services.xserver.desktopManager.gnome3;
  5. serviceCfg = config.services.gnome3;
  6. # Prioritize nautilus by default when opening directories
  7. mimeAppsList = pkgs.writeTextFile {
  8. name = "gnome-mimeapps";
  9. destination = "/share/applications/mimeapps.list";
  10. text = ''
  11. [Default Applications]
  12. inode/directory=nautilus.desktop;org.gnome.Nautilus.desktop
  13. '';
  14. };
  15. nixos-gsettings-desktop-schemas = let
  16. defaultPackages = with pkgs; [ gsettings-desktop-schemas gnome3.gnome-shell ];
  17. in
  18. pkgs.runCommand "nixos-gsettings-desktop-schemas" { preferLocalBuild = true; }
  19. ''
  20. mkdir -p $out/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas
  21. ${concatMapStrings
  22. (pkg: "cp -rf ${pkg}/share/gsettings-schemas/*/glib-2.0/schemas/*.xml $out/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas\n")
  23. (defaultPackages ++ cfg.extraGSettingsOverridePackages)}
  24. cp -f ${pkgs.gnome3.gnome-shell}/share/gsettings-schemas/*/glib-2.0/schemas/*.gschema.override $out/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas
  25. chmod -R a+w $out/share/gsettings-schemas/nixos-gsettings-overrides
  26. cat - > $out/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas/nixos-defaults.gschema.override <<- EOF
  27. [org.gnome.desktop.background]
  28. picture-uri='file://${pkgs.nixos-artwork.wallpapers.simple-dark-gray}/share/artwork/gnome/nix-wallpaper-simple-dark-gray.png'
  29. [org.gnome.desktop.screensaver]
  30. picture-uri='file://${pkgs.nixos-artwork.wallpapers.simple-dark-gray-bottom}/share/artwork/gnome/nix-wallpaper-simple-dark-gray_bottom.png'
  31. [org.gnome.shell]
  32. favorite-apps=[ 'org.gnome.Epiphany.desktop', 'org.gnome.Geary.desktop', 'org.gnome.Music.desktop', 'org.gnome.Photos.desktop', 'org.gnome.Nautilus.desktop', 'org.gnome.Software.desktop' ]
  33. ${cfg.extraGSettingsOverrides}
  34. EOF
  35. ${pkgs.glib.dev}/bin/glib-compile-schemas $out/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas/
  36. '';
  37. flashbackEnabled = cfg.flashback.enableMetacity || length cfg.flashback.customSessions > 0;
  38. in
  39. {
  40. options = {
  41. services.gnome3 = {
  42. core-os-services.enable = mkEnableOption "essential services for GNOME3";
  43. core-shell.enable = mkEnableOption "GNOME Shell services";
  44. core-utilities.enable = mkEnableOption "GNOME core utilities";
  45. games.enable = mkEnableOption "GNOME games";
  46. };
  47. services.xserver.desktopManager.gnome3 = {
  48. enable = mkOption {
  49. default = false;
  50. description = "Enable Gnome 3 desktop manager.";
  51. };
  52. sessionPath = mkOption {
  53. default = [];
  54. example = literalExample "[ pkgs.gnome3.gpaste ]";
  55. description = ''
  56. Additional list of packages to be added to the session search path.
  57. Useful for GNOME Shell extensions or GSettings-conditional autostart.
  58. Note that this should be a last resort; patching the package is preferred (see GPaste).
  59. '';
  60. apply = list: list ++ [ pkgs.gnome3.gnome-shell pkgs.gnome3.gnome-shell-extensions ];
  61. };
  62. extraGSettingsOverrides = mkOption {
  63. default = "";
  64. type = types.lines;
  65. description = "Additional gsettings overrides.";
  66. };
  67. extraGSettingsOverridePackages = mkOption {
  68. default = [];
  69. type = types.listOf types.path;
  70. description = "List of packages for which gsettings are overridden.";
  71. };
  72. debug = mkEnableOption "gnome-session debug messages";
  73. flashback = {
  74. enableMetacity = mkEnableOption "the standard GNOME Flashback session with Metacity";
  75. customSessions = mkOption {
  76. type = types.listOf (types.submodule {
  77. options = {
  78. wmName = mkOption {
  79. type = types.str;
  80. description = "The filename-compatible name of the window manager to use.";
  81. example = "xmonad";
  82. };
  83. wmLabel = mkOption {
  84. type = types.str;
  85. description = "The pretty name of the window manager to use.";
  86. example = "XMonad";
  87. };
  88. wmCommand = mkOption {
  89. type = types.str;
  90. description = "The executable of the window manager to use.";
  91. example = "\${pkgs.haskellPackages.xmonad}/bin/xmonad";
  92. };
  93. };
  94. });
  95. default = [];
  96. description = "Other GNOME Flashback sessions to enable.";
  97. };
  98. };
  99. };
  100. environment.gnome3.excludePackages = mkOption {
  101. default = [];
  102. example = literalExample "[ pkgs.gnome3.totem ]";
  103. type = types.listOf types.package;
  104. description = "Which packages gnome should exclude from the default environment";
  105. };
  106. };
  107. config = mkMerge [
  108. (mkIf (cfg.enable || flashbackEnabled) {
  109. services.gnome3.core-os-services.enable = true;
  110. services.gnome3.core-shell.enable = true;
  111. services.gnome3.core-utilities.enable = mkDefault true;
  112. services.xserver.displayManager.extraSessionFilePackages = [ pkgs.gnome3.gnome-session ];
  113. environment.extraInit = ''
  114. ${concatMapStrings (p: ''
  115. if [ -d "${p}/share/gsettings-schemas/${p.name}" ]; then
  116. export XDG_DATA_DIRS=$XDG_DATA_DIRS''${XDG_DATA_DIRS:+:}${p}/share/gsettings-schemas/${p.name}
  117. fi
  118. if [ -d "${p}/lib/girepository-1.0" ]; then
  119. export GI_TYPELIB_PATH=$GI_TYPELIB_PATH''${GI_TYPELIB_PATH:+:}${p}/lib/girepository-1.0
  120. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}${p}/lib
  121. fi
  122. '') cfg.sessionPath}
  123. '';
  124. environment.systemPackages = cfg.sessionPath;
  125. environment.sessionVariables.GNOME_SESSION_DEBUG = mkIf cfg.debug "1";
  126. # Override GSettings schemas
  127. environment.sessionVariables.NIX_GSETTINGS_OVERRIDES_DIR = "${nixos-gsettings-desktop-schemas}/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas";
  128. # If gnome3 is installed, build vim for gtk3 too.
  129. nixpkgs.config.vim.gui = "gtk3";
  130. })
  131. (mkIf flashbackEnabled {
  132. services.xserver.displayManager.extraSessionFilePackages = map
  133. (wm: pkgs.gnome3.gnome-flashback.mkSessionForWm {
  134. inherit (wm) wmName wmLabel wmCommand;
  135. }) (optional cfg.flashback.enableMetacity {
  136. wmName = "metacity";
  137. wmLabel = "Metacity";
  138. wmCommand = "${pkgs.gnome3.metacity}/bin/metacity";
  139. } ++ cfg.flashback.customSessions);
  140. security.pam.services.gnome-screensaver = {
  141. enableGnomeKeyring = true;
  142. };
  143. services.dbus.packages = [
  144. pkgs.gnome3.gnome-screensaver
  145. ];
  146. })
  147. (mkIf serviceCfg.core-os-services.enable {
  148. hardware.bluetooth.enable = mkDefault true;
  149. hardware.pulseaudio.enable = mkDefault true;
  150. programs.dconf.enable = true;
  151. security.polkit.enable = true;
  152. services.accounts-daemon.enable = true;
  153. services.dleyna-renderer.enable = mkDefault true;
  154. services.dleyna-server.enable = mkDefault true;
  155. services.gnome3.at-spi2-core.enable = true;
  156. services.gnome3.evolution-data-server.enable = true;
  157. services.gnome3.gnome-keyring.enable = true;
  158. services.gnome3.gnome-online-accounts.enable = mkDefault true;
  159. services.gnome3.gnome-online-miners.enable = true;
  160. services.gnome3.tracker-miners.enable = mkDefault true;
  161. services.gnome3.tracker.enable = mkDefault true;
  162. services.hardware.bolt.enable = mkDefault true;
  163. services.packagekit.enable = mkDefault true;
  164. services.udisks2.enable = true;
  165. services.upower.enable = config.powerManagement.enable;
  166. services.xserver.libinput.enable = mkDefault true; # for controlling touchpad settings via gnome control center
  167. xdg.portal.enable = true;
  168. xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
  169. networking.networkmanager.enable = mkDefault true;
  170. services.xserver.updateDbusEnvironment = true;
  171. # Needed for themes and backgrounds
  172. environment.pathsToLink = [
  173. "/share" # TODO: https://github.com/NixOS/nixpkgs/issues/47173
  174. ];
  175. })
  176. (mkIf serviceCfg.core-shell.enable {
  177. services.colord.enable = mkDefault true;
  178. services.gnome3.chrome-gnome-shell.enable = mkDefault true;
  179. services.gnome3.glib-networking.enable = true;
  180. services.gnome3.gnome-initial-setup.enable = mkDefault true;
  181. services.gnome3.gnome-remote-desktop.enable = mkDefault true;
  182. services.gnome3.gnome-settings-daemon.enable = true;
  183. services.gnome3.gnome-user-share.enable = mkDefault true;
  184. services.gnome3.rygel.enable = mkDefault true;
  185. services.gvfs.enable = true;
  186. services.system-config-printer.enable = (mkIf config.services.printing.enable (mkDefault true));
  187. services.telepathy.enable = mkDefault true;
  188. systemd.packages = with pkgs.gnome3; [ vino gnome-session ];
  189. services.avahi.enable = mkDefault true;
  190. xdg.portal.extraPortals = [ pkgs.gnome3.gnome-shell ];
  191. services.geoclue2.enable = mkDefault true;
  192. services.geoclue2.enableDemoAgent = false; # GNOME has its own geoclue agent
  193. services.geoclue2.appConfig.gnome-datetime-panel = {
  194. isAllowed = true;
  195. isSystem = true;
  196. };
  197. services.geoclue2.appConfig.gnome-color-panel = {
  198. isAllowed = true;
  199. isSystem = true;
  200. };
  201. services.geoclue2.appConfig."org.gnome.Shell" = {
  202. isAllowed = true;
  203. isSystem = true;
  204. };
  205. fonts.fonts = with pkgs; [
  206. cantarell-fonts
  207. dejavu_fonts
  208. source-code-pro # Default monospace font in 3.32
  209. source-sans-pro
  210. ];
  211. # Adapt from https://gitlab.gnome.org/GNOME/gnome-build-meta/blob/gnome-3-32/elements/core/meta-gnome-core-shell.bst
  212. environment.systemPackages = with pkgs.gnome3; [
  213. adwaita-icon-theme
  214. gnome-backgrounds
  215. gnome-bluetooth
  216. gnome-color-manager
  217. gnome-control-center
  218. gnome-getting-started-docs
  219. gnome-shell
  220. gnome-shell-extensions
  221. gnome-themes-extra
  222. gnome-user-docs
  223. pkgs.orca
  224. pkgs.glib # for gsettings
  225. pkgs.gnome-menus
  226. pkgs.gtk3.out # for gtk-launch
  227. pkgs.hicolor-icon-theme
  228. pkgs.shared-mime-info # for update-mime-database
  229. pkgs.xdg-user-dirs # Update user dirs as described in http://freedesktop.org/wiki/Software/xdg-user-dirs/
  230. vino
  231. ];
  232. })
  233. # Adapt from https://gitlab.gnome.org/GNOME/gnome-build-meta/blob/gnome-3-32/elements/core/meta-gnome-core-utilities.bst
  234. (mkIf serviceCfg.core-utilities.enable {
  235. environment.systemPackages = (with pkgs.gnome3; removePackagesByName [
  236. baobab
  237. cheese
  238. eog
  239. epiphany
  240. geary
  241. gedit
  242. gnome-calculator
  243. gnome-calendar
  244. gnome-characters
  245. gnome-clocks
  246. gnome-contacts
  247. gnome-font-viewer
  248. gnome-logs
  249. gnome-maps
  250. gnome-music
  251. gnome-photos
  252. gnome-screenshot
  253. gnome-software
  254. gnome-system-monitor
  255. gnome-weather
  256. nautilus
  257. simple-scan
  258. totem
  259. yelp
  260. # Unsure if sensible for NixOS
  261. /* gnome-boxes */
  262. ] config.environment.gnome3.excludePackages);
  263. # Enable default programs
  264. programs.evince.enable = mkDefault true;
  265. programs.file-roller.enable = mkDefault true;
  266. programs.gnome-disks.enable = mkDefault true;
  267. programs.gnome-terminal.enable = mkDefault true;
  268. programs.seahorse.enable = mkDefault true;
  269. services.gnome3.sushi.enable = mkDefault true;
  270. # Let nautilus find extensions
  271. # TODO: Create nautilus-with-extensions package
  272. environment.sessionVariables.NAUTILUS_EXTENSION_DIR = "${config.system.path}/lib/nautilus/extensions-3.0";
  273. # Override default mimeapps for nautilus
  274. environment.sessionVariables.XDG_DATA_DIRS = [ "${mimeAppsList}/share" ];
  275. environment.pathsToLink = [
  276. "/share/nautilus-python/extensions"
  277. ];
  278. })
  279. (mkIf serviceCfg.games.enable {
  280. environment.systemPackages = (with pkgs.gnome3; removePackagesByName [
  281. aisleriot atomix five-or-more four-in-a-row gnome-chess gnome-klotski
  282. gnome-mahjongg gnome-mines gnome-nibbles gnome-robots gnome-sudoku
  283. gnome-taquin gnome-tetravex hitori iagno lightsoff quadrapassel
  284. swell-foop tali
  285. ] config.environment.gnome3.excludePackages);
  286. })
  287. ];
  288. }