NixOS no-desktop configuration?

Hello,

I’m curious if anyone has a no desktop configuration setup. I’ve seen this happen on my NVIDIA laptop when I remove all of the graphics drivers or a driver fails to load, eg it just boots into a terminal instead of Gnome/XFCE/etc. but curious if there’s a “correct” way to do this?

The correct way to configure a headless/TTY only system would just be to not configure a desktop environment. For example, i have a module that configures users, networking, console keymap and timezone which i then import for typical headless servers but also serves as the base configuration for all my desktop machines.

What’s confusing me is that when I do lib.mkForce false for all of my desktop settings it errors :slightly_frowning_face:

I’ll double check that I didn’t miss anything, maybe that’s it

Here’s the block:

  specialisation = {
    no-desktop.configuration = {
      system.nixos.tags = [ "no-desktop" ];
      services.displayManager.defaultSession = "none";
      hardware.graphics.enable = lib.mkForce false;
      services.xserver.enable = lib.mkForce false;
      services.xserver.displayManager = {
        gdm.enable = lib.mkForce false;
        autoLogin = {
          enable = false;
          user = user.name;
        };
      };
      services.xserver.desktopManager.gnome.enable = lib.mkForce false;
      xdg.portal.enable = lib.mkForce false;
    };
  };

and here’s the error:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixos-system-dev-one-24.11.20240709.feb2849'
         whose name attribute is located at /nix/store/xr9wjzx0cdnwkmhzz74h8lphgn5jmyv3-source/pkgs/stdenv/generic/make-derivation.nix:332:7

       … while evaluating attribute 'buildCommand' of derivation 'nixos-system-dev-one-24.11.20240709.feb2849'

         at /nix/store/xr9wjzx0cdnwkmhzz74h8lphgn5jmyv3-source/nixos/modules/system/activation/top-level.nix:53:5:

           52|     passAsFile = [ "extraDependencies" ];
           53|     buildCommand = systemBuilder;
             |     ^
           54|

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `specialisation.no-desktop.configuration.hardware.graphics.package' is used but not defined.

If I remove the hardware.graphics.enable = lib.mkForce false; line it builds, but when I boot into it, it just hangs after the power management services start

Hi, firstly are you on nixos-unstable or nixos-24.05? hardware.graphics is only available on unstable.

yep! I’m on unstable :slightly_smiling_face:

Specialisation includes main system configuration by default. Could you check if you have any graphics-related configuration in the main system, including importing 3rd party modules like swayfx or hyprland?

I do have hardware.graphics.enable = true; by default, which is why I’m trying to force it false here, but that’s all. I left the decision of which third party module to use up to the system config that imports this module. So to put it another way, I have a configuration.nix file for a specific laptop which includes the following imports:

imports = [
  ./hardware-configuration.nix
  ../../nixos/laptop-configuration.nix # this one has the specialization in it
  ../../nixos/configuration.nix
];

Have you added other config in the system configuration.nix related to graphics, such as GNOME or KDE?

Yes, the ones that import the specialisation config

So like this:
configuration.nix

{ pkgs, lib ... }:
{
imports = [
  ./hardware-configuration.nix
  ../../nixos/laptop-configuration.nix # this one has the specialization in it
  ../../nixos/configuration.nix
];
# enable Gnome or Hyprland here, and in home-manager
}

What exactly have you configured in configuration.nix?

This is all i have in there aside from environment.systemPackages:

  # Enable the X11 windowing system.
  services.xserver = {
    # Enable the GNOME Desktop Environment.
    displayManager.gdm.enable = true;
    desktopManager.gnome.enable = true;
  };
  services.displayManager = {
    # Enable automatic login for the user.
    autoLogin.enable = lib.mkForce true;
    autoLogin.user = user.name;
  };
  # Workaround for GNOME autologin
  systemd.services = {
    "getty@tty1".enable = false;
    "autovt@tty1".enable = false;
  };

  # Extra GPU settings
  boot.initrd.kernelModules = gpu_drivers;
  services.xserver.videoDrivers = gpu_drivers;

Here’s what I have in nixos/configuration.nix in imports:

  # Enable the X11 windowing system.
  services.xserver = {
    enable = true;
    desktopManager = {
      xterm.enable = false;
    };

    # Configure keymap in X11
    xkb = {
      layout = "us";
      variant = "";
    };
  };

  # Enable GPU.
  hardware.graphics.enable = true;

  # Enable automatic login for the user.
  services.displayManager.autoLogin = {
    enable = false;
    user = user.name;
  };