MyNixOS website logo

Install

Install Nix with existing system

If you wish to install Nix with an existing operating system, in order to use e.g. the Nix development shell feature, you may use the following convenience script to install Nix.

For further information regarding multi-user (daemon) vs single-user installation (no-daemon), as well as other installation details, consult the Nix manual.

The install-nix script is a small wrapper to the Nix installation which ensures that you have the flakes feature enabled, as well as the keep-derivations and keep-outputs settings enabled, for convenience with development environments.

Install for Linux

Install for macOS

Install for WSL2

Verify Nix installation

To verify your Nix installation, try running:

On success, the output should read "Hello, world!".

Install direnv + nix-direnv

The direnv + nix-direnv combination is a powerful feature that enables the use of .envrc files with Nix flakes. This allows you to automatically enter e.g. a development shell environment when going into your project folder.

After installing Nix, install direnv + nix-direnv using:

Install Nix development shell

The Nix development shell is a powerful tool to create dedicated and reproducible software environments, such as to describe the environment needed to build a program or a website on your computer.

When creating flake configurations with MyNixOS, releases are used to create distinct versions of flakes. Each version contains the generated Nix code describing your configuration, and the flake lockfile describing the exact input versions your configuration depends on. These versions can be unpacked and added to a different source control for your project, however the flake loader is an alternative added for convenience.

The flake loader is a convenience flake which forwards the outputs of your MyNixOS flake, and includes a .envrc file for your flake, such that entering the folder of the flake loader will load the default development environment if you have direnv and nix-direnv installed. It can either be downloaded using the "Download loader" button on the "Meta" flake tab after releasing a flake, or by running:

The flake loader can be added as part of your project source control. If used with Git, remember to stage the flake loader files before running Nix commands. Remember to run nix flake update each time you wish to use a new release of your flake from MyNixOS.

Follow the Nix development shell guide for further information.

Install NixOS as operating system

The following is a minimal guide on how to install NixOS as your operating system using a flake created with MyNixOS:

  1. Install NixOS on your machine by following chapter 1 and chapter 2 in the official NixOS manual.
  2. Create a flake by signing in to MyNixOS, and then using the create flake page.
  3. Navigate to your flake outputs by clicking the "flake selector" button to the upper right, then select "Outputs" to the left of your screen.
  4. Create a "NixOS configuration" output with your desired name, preferably matching your hostname, and the system type which matches your hardware.
  5. Assign your desired system NixOS settings, either directly to the NixOS configuration output, or by creating NixOS module outputs which you then import into the NixOS configuration output (see Options / Packages / Imports).
  6. Ensure that the necessary settings from your /etc/nixos/configuration.nix configuration are added to your flake, see Options.
  7. Create a release of your flake configuration.
  8. From the flake versions screen of your flake, copy the URL using the "Latest" version button.
  9. From your machine, run sudo nixos-rebuild build --flake <latest-flake-url>
    This will attempt to build the new flake configuration. Do not continue if this does not succeed.
  10. From your machine, run sudo nixos-rebuild test --flake <latest-flake-url>
    This will activate the flake configuration on your machine, without changing your boot configuration. Do not continue if this does not succeed. If it fails, restart your machine if necessary to get back to a working state.
  11. When you have a working configuration, run sudo nixos-rebuild switch --flake <latest-flake-url>
    This will switch your current configuration and update your boot configuration to the given flake.

When new versions of your flake are released, re-run commands from step 9-11 to update to the new version.

Only perform these steps if you are prepared to lose any current data on your computer.

If you are experimenting with NixOS for the first time, it is recommended to first try setting up a virtual machine using NixOS generate.

Run virtual machine within NixOS

If you are already running NixOS, you can run flakes with a NixOS configuration output in a virtual machine via QEMU. This can be a convenient way to test out configurations quickly.

Assuming a flake mynixos/vm-test-os with a NixOS configuration output nixos, run the following from your terminal within NixOS:

This will boot a QEMU virtual machine with your NixOS configuration.