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.
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-outputs settings enabled, for convenience with development environments.
To verify your Nix installation, try running:
On success, the output should read "Hello, world!".
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
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
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.
The following is a minimal guide on how to install NixOS as your operating system using a flake created with MyNixOS:
/etc/nixos/configuration.nixconfiguration are added to your flake, see Options.
sudo nixos-rebuild build --flake <latest-flake-url>
sudo nixos-rebuild test --flake <latest-flake-url>
sudo nixos-rebuild switch --flake <latest-flake-url>
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.
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.