NixOS configuration

NixOS configuration is a flake output type which describes a NixOS operating system for a specific system.

NixOS modules is a different flake output type which is useful for organizing and reusing NixOS settings. NixOS configurations can import NixOS modules, but cannot import other NixOS configurations. It is therefore recommended to generally use NixOS modules, and use NixOS configurations to declare a specific system configuration, while relying on imports of NixOS modules, see Imports.

If you wish to build e.g. a cloud server image or embedded server image, check out NixOS generate output.

How to create a NixOS configuration

Step 1 - Create your flake

Create a flake by signing in to MyNixOS, and then navigate to the create flake page.

On the flake create screen, enter an appropriate name, then click "create".

You should now see the name of your flake in the flake selector to the upper right on your screen.

Step 2 - Create a NixOS configuration output

  • Navigate to the flake outputs screen by clicking the flake selector to the top right of the screen, then select "Outputs" to the left on the flake screen.
  • From the flake outputs screen, select "Add output" → "NixOS configuration".
  • In the "NixOS configuration" dialog, select a name and your target system, then click "Create".
    In this example, we use nixos as the name and x86_64-linux as the system.

Your NixOS configuration should now be shown as an output in the flake output screen.

Step 3 - Configure the NixOS configuration output

As part of our configuration, we will add the following settings to the NixOS configuration:

  • Set users.users.<name>.isNormalUser to true for the key nixos.
    This will enable a user account with username nixos.
  • Set users.users.<name>.password to nixos for the key nixos.
    This will set the password for the nixos user to nixos.
  • Add the sl package to the configuration.
    This will make the sl tool available as a system package in our configuration.

Step 4 - Test the NixOS configuration

If you are using NixOS, the NixOS configuration can be tested as below - otherwise, see Release and Install.

  1. Navigate to the flake versions screen (Click the flake selector, then select "Versions").
  2. Click "Release" to create a version of your flake (Learn about releases)
    When the release is ready, a new version entry appears in the listing on the flake versions page.
  3. Copy the "Latest" flake URL from the flake versions screen.
  4. Run nixos-rebuild build-vm --flake <latest-flake-url>#nixos with the URL and #nixos fragment.
  5. Run ./result/bin/run-nixos-vm
  6. Log in with username nixos and password nixos.

Congratulations! You are now running a NixOS operating system defined as a flake.

To celebrate, run the sl command.