Installing from another Linux distribution
Because Nix (the package manager) & Nixpkgs (the Nix packages collection) can both be installed on any (most?) Linux distributions, they can be used to install NixOS in various creative ways. You can, for instance:
-
Install NixOS on another partition, from your existing Linux distribution (without the use of a USB or optical device!)
-
Install NixOS on your hard drive from the Live CD of any Linux distribution.
The steps for these are the same:
-
Install the Nix package manager:
Short version:
$ curl -L https://nixos.org/nix/install | sh $ . $HOME/.nix-profile/etc/profile.d/nix.sh # …or open a fresh shellMore details in the Nix manual
-
Switch to the NixOS channel:
If you've just installed Nix on a non-NixOS distribution, you will be on the
nixpkgschannel by default.$ nix-channel --list nixpkgs https://channels.nixos.org/nixpkgs-unstableAs that channel gets released without running the NixOS tests, it will be safer to use the
nixos-*channels instead:$ nix-channel --add https://channels.nixos.org/nixos-<version> nixpkgsWhere
<version>corresponds to the latest version available on channels.nixos.org.You must run
$ nix-channel --updatefor the channel change to take effect. -
Install the NixOS installation tools:
You'll need
nixos-generate-configandnixos-install, but this also makes some man pages andnixos-enteravailable, just in case you want to chroot into your NixOS partition. NixOS installs these by default, but you don't have NixOS yet..$ nix-env -f '<nixpkgs>' -iA nixos-install-tools -
Prepare your target partition:
At this point it is time to prepare your target partition. Please refer to the partitioning, file-system creation, and mounting steps of Installing NixOS
-
Generate your NixOS configuration:
$ sudo `which nixos-generate-config` --root /mntYou'll probably want to edit the configuration files. Refer to the
nixos-generate-configstep in Installing NixOS for more information.Consider setting up the NixOS bootloader to give you the ability to boot on your existing Linux partition. For instance, if you're using GRUB and your existing distribution is running Ubuntu, you may want to add something like this to your
configuration.nix:{ boot.loader.grub.extraEntries = '' menuentry "Ubuntu" { search --set=ubuntu --fs-uuid 3cc3e652-0c1f-4800-8451-033754f68e6e configfile "($ubuntu)/boot/grub/grub.cfg" } ''; }(You can find the appropriate UUID for your partition in
/dev/disk/by-uuid) -
Create the
nixbldgroup and user on your original distribution:$ sudo groupadd -g 30000 nixbld $ sudo useradd -u 30000 -g nixbld -G nixbld nixbld -
Download/build/install NixOS:
Warning
Once you complete this step, you might no longer be able to boot on existing systems without the help of a rescue USB drive or similar.
Note
On some distributions there are separate PATHS for programs intended only for root. In order for the installation to succeed, you might have to use
PATH="$PATH:/usr/sbin:/sbin"in the following command.$ sudo PATH="$PATH" `which nixos-install` --root /mntAgain, please refer to the
nixos-installstep in Installing NixOS for more information.That should be it for installation to another partition!
-
Optionally, you may want to clean up your non-NixOS distribution:
$ sudo userdel nixbld $ sudo groupdel nixbldIf you do not wish to keep the Nix package manager installed either, run something like
sudo rm -rv ~/.nix-* /nixand remove the line that the Nix installer added to your~/.profile.