Home Explore Blog CI



nixpkgs

1st chunk of `nixos/doc/manual/configuration/x-windows.chapter.md`
f7e2b26896cc764e5276a484acda5364e4315114ba2b11e00000000100000fa0
# X Window System {#sec-x11}

The X Window System (X11) provides the basis of NixOS' graphical user
interface. It can be enabled as follows:

```nix
{
  services.xserver.enable = true;
}
```

The X server will automatically detect and use the appropriate video
driver from a set of X.org drivers (such as `vesa` and `intel`). You can
also specify a driver manually, e.g.

```nix
{
  services.xserver.videoDrivers = [ "r128" ];
}
```

to enable X.org's `xf86-video-r128` driver.

You also need to enable at least one desktop or window manager.
Otherwise, you can only log into a plain undecorated `xterm` window.
Thus you should pick one or more of the following lines:

```nix
{
  services.xserver.desktopManager.plasma5.enable = true;
  services.xserver.desktopManager.xfce.enable = true;
  services.desktopManager.gnome.enable = true;
  services.xserver.desktopManager.mate.enable = true;
  services.xserver.windowManager.xmonad.enable = true;
  services.xserver.windowManager.twm.enable = true;
  services.xserver.windowManager.icewm.enable = true;
  services.xserver.windowManager.i3.enable = true;
  services.xserver.windowManager.herbstluftwm.enable = true;
}
```

NixOS's default *display manager* (the program that provides a graphical
login prompt and manages the X server) is LightDM. You can select an
alternative one by picking one of the following lines:

```nix
{
  services.displayManager.sddm.enable = true;
  services.displayManager.gdm.enable = true;
}
```

You can set the keyboard layout (and optionally the layout variant):

```nix
{
  services.xserver.xkb.layout = "de";
  services.xserver.xkb.variant = "neo";
}
```

The X server is started automatically at boot time. If you don't want
this to happen, you can set:

```nix
{
  services.xserver.autorun = false;
}
```

The X server can then be started manually:

```ShellSession
# systemctl start display-manager.service
```

On 64-bit systems, if you want OpenGL for 32-bit programs such as in
Wine, you should also set the following:

```nix
{
  hardware.graphics.enable32Bit = true;
}
```

## Auto-login {#sec-x11-auto-login}

The x11 login screen can be skipped entirely, automatically logging you
into your window manager and desktop environment when you boot your
computer.

This is especially helpful if you have disk encryption enabled. Since
you already have to provide a password to decrypt your disk, entering a
second password to login can be redundant.

To enable auto-login, you need to define your default window manager and
desktop environment. If you wanted no desktop environment and i3 as your
your window manager, you'd define:

```nix
{
  services.displayManager.defaultSession = "none+i3";
}
```

Every display manager in NixOS supports auto-login, here is an example
using lightdm for a user `alice`:

```nix
{
  services.xserver.displayManager.lightdm.enable = true;
  services.displayManager.autoLogin.enable = true;
  services.displayManager.autoLogin.user = "alice";
}
```

## Running X without a display manager  {#sec-x11-startx}

It is possible to avoid a display manager entirely and starting the X server
manually from a virtual terminal. Add to your configuration:
```nix
{
  services.xserver.displayManager.startx = {
    enable = true;
    generateScript = true;
  };
}
```
then you can start the X server with the `startx` command.

The second option will generate a base `xinitrc` script that will run your
window manager and set up the systemd user session.
You can extend the script using the
[extraCommands](#opt-services.xserver.displayManager.startx.extraCommands)
option, for example:
```nix
{
  services.xserver.displayManager.startx = {
    generateScript = true;
    extraCommands = ''
      xrdb -load .Xresources
      xsetroot -solid '#666661'
      xsetroot -cursor_name left_ptr
    '';
  };
}
```
or, alternatively, you can write your own from scratch in `~/.xinitrc`.

In this case, remember you're responsible for starting the window manager, for
example:
```shell
sxhkd &

Title: X Window System Configuration in NixOS
Summary
This section describes how to configure the X Window System (X11) in NixOS, including enabling it, specifying video drivers, choosing a desktop or window manager, selecting a display manager, setting the keyboard layout, and enabling 32-bit OpenGL support. It also covers how to enable auto-login, and how to start X without a display manager using `startx`.