A Basic Desktop

# configuration.nix

{ pkgs, ... }: {
  imports = [
    ./hardware-configuration.nix
  ];

  boot.loader = {
    systemd-boot.enable = true;
    efi.canTouchEfiVariables = true;
  };

  networking = {
    # it's recommended to disable DHCP globally and enable it seperately for
    # each interface
    useDHCP = false;

    interfaces.enp1s0.useDHCP = true;
  };

  services = {
    openssh.enable = true;

    xserver = {
      enable = true;

      desktopManager.gnome3.enable = true;

      # NixOS's default display manager is LightDM. however, GDM fits better
      # with GNOME
      displayManager.gdm.enable = true;
    };
  };

  users = {
    # disallows users and groups from being modified outside of the system 
    # configuration, which is useful if you only ever want to configure users
    # inside your `configuration.nix`
    mutableUsers = false;

    users.raccoon = {
      # regular interactive user with a home directory etc.
      isNormalUser = true;

      # can use `sudo`
      extraGroups = [ "wheel" ];

      # you can generate a hashed password for this option with
      # `mkpasswd -m sha-512`
      hashedPassword = "/*snip*/";

      # note the `with pkgs;` so you don't have to type `pkgs.vim` etc. for
      # each package
      packages = with pkgs; [ vim ];
    };
  };

  system.stateVersion = "20.09";
}

This configuration is based on the default generated one, with a few simple additions. It will give you

  • the systemd-boot bootloader,
  • a user named raccoon with vim in their environment and the permission to use sudo,
  • DHCP for enp1s0,
  • an ssh service,
  • and a GNOME 3 desktop.

Note that I've omitted the contents of hardware-configuration.nix. This file includes some important hardware-dependent configuration such as necessary filesystem mounts and kernel modules. Apart from being created automatically, it is not treated specially; you could specify all of those things yourself, too.