Using NixOS Specialisations to Try Out Different Desktop Environments

Posted on October 6, 2022 by Richard Goulter
Tags:

Recently, Tweag’s blog featured a post on NixOS specialisations.

It allows for having an additional boot entry in grub which loads a slightly different configuration. – This makes it very convenient to try slightly different NixOS configurations.

As the blogpost above shows, this can be used for different desktop environments.

I ran into some problems with conflicting attributes, and wasn’t previously aware of how to set the priority. (e.g. as discussed in this discourse post).

e.g. I’d wanted to try out the Pantheon desktop environment, which comes out of Elementary OS and looks very nice. – But, if you try to enable both services.xserver.desktopManager.gnome and services.xserver.desktopManager.pantheon, you get an error like:

error: The option `environment.sessionVariables.NIX_GSETTINGS_OVERRIDES_DIR' has conflicting definition values:

Not knowing about overriding attribute priorities, my first attempt at solving this problem was using specialisations to separate the conflicting config options: 8df3…/modules/desktops.nix.

Knowing the above about overriding attribute priorites, it makes sense that it’s possible to use Gnome in the ‘parent’ config, and to disable Gnome in the specialisations, with:

services.xserver.desktopManager.gnome.enable = lib.mkDefault true;

e.g. c3f0…./modules/desktops.nix.

{ config, lib, pkgs, ... }:

{
  services = {
    xserver = {
      desktopManager.gnome.enable = lib.mkDefault true;
      displayManager.gdm.enable = lib.mkDefault true;

      enable = true;

      layout = "us";
    };
  };

  specialisation = {
    gnome.configuration = {
      services.xserver = {
        desktopManager.gnome.enable = true;
        displayManager.gdm.enable = true;
      };
      system.nixos.tags = [ "gnome" ];
    };
    pantheon.configuration = {
      services.xserver = {
        # Pantheon conflicts with gnome
        desktopManager = {
          gnome.enable = false;
          pantheon.enable = true;
        };
        # Pantheon requires lightdm
        displayManager = {
          gdm.enable = false;
          lightdm.enable = true;
        };
      };
      system.nixos.tags = [ "pantheon" ];
    };
    xfce.configuration = {
      networking.networkmanager.enable = true;
      services.xserver = {
        desktopManager = {
          gnome.enable = false;
          xfce.enable = true;
        };
        displayManager = {
          gdm.enable = false;
        };
      };
      system.nixos.tags = [ "gnome" ];
    };
  };
}

Newer post Older post