Installation
Building the installation CD Instead of building an installation CD, you could just download one from . If you want (or need) to build it yourself: Make sure that you have a very recent pre-release version of Nix installed (). The NixOS Nix expressions frequently use bleeding-edge features. If you get any kind of expression evaluation error, try to upgrade your Nix. Optional but strongly recommended (and currently required for building the x86_64 ISO): subscribe/pull from the Nixpkgs channel to speed up building, i.e., $ nix-channel --add http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable $ nix-channel --update Check out NixOS from as nixos. If you don’t already have Nixpkgs checkout, Check out Nixpkgs from as nixpkgs. In the directory nixos, make a symbolic link pkgs to the pkgs directory of the Nixpkgs tree, e.g., $ ln -s nixpkgs/pkgs nixos/ Build the ISO image: $ nix-build configuration/rescue-cd.nix -A rescueCD If everything goes well, you’ll end up with an ISO image in ./result/iso/nixos-version-platform.iso that you can burn onto a CD or attach to a virtual CD-ROM drive in your favourite virtual machine software.
Installation Boot from the CD. The CD contains a basic NixOS installation. (It also contain Memtest86+, useful if you want to test new hardware.) When it’s finished booting, it should have detected most of your hardware and brought up networking (check ifconfig). Networking is necessary for the installer, since it will download lots of stuff (such as source tarballs or Nixpkgs channel binaries). It’s best if you have a DHCP server on your network. Otherwise configure manually. The NixOS manual is available on virtual console 7 (press Alt+F7 to access). Login as root, empty password. The NixOS installer doesn’t do any partitioning or formatting yet, so you need to that yourself. Use the following commands: For partitioning: fdisk. For initialising Ext2/Ext3 partitions: mke2fs. Ext3 is recommended; use the to create a journalled file system. It is also recommended that you assign a unique symbolic label to the file system using the option . This will make the file system configuration independent from device changes. For creating swap partitions: mkswap. Again it’s recommended to assign a label to the swap partition: . For creating LVM volumes, the LVM commands, e.g., $ pvcreate /dev/sda1 /dev/sdb1 $ vgcreate MyVolGroup /dev/sda1 /dev/sdb1 $ lvcreate --size 2G --name bigdisk MyVolGroup $ lvcreate --size 1G --name smalldisk MyVolGroup Possibly you’ll need to do initctl start lvm after this (TODO: check whether this is needed). For creating software RAID devices: mdadm. Mount the target file system on /mnt. The installation is declarative; you need to write a description of the configuration that you want to be built and activated. The configuration is specified in a Nix expression and must be stored on the target file system in /mnt/etc/nixos/configuration.nix. See /etc/nixos/nixos/doc/config-examples for example machine configurations. You can copy and edit one of those (e.g., copy /etc/nixos/nixos/doc/config-examples/basic.nix to /mnt/etc/nixos/configuration.nix). See for a list of the available configuration options. The text editors nano and vim are available. In particular you need to specify a root file system in and the target device for the Grub boot loader in . The command nixos-hardware-scan can generate an initial configuration file for you, i.e., $ mkdir -p /mnt/etc/nixos $ nixos-hardware-scan > /mnt/etc/nixos/configuration.nix It tries to figure out the modules necessary for mounting the root device, as well as various other hardware characteristics. However, it doesn’t try to figure out the option yet. More examples of NixOS configurations for some actual machines can be found at . It is very important that you specify in the option all kernel modules that are necessary for mounting the root file system, otherwise the installed system will not be able to boot. (If this happens, boot from CD again, mount the target file system on /mnt, fix /mnt/etc/nixos/configuration.nix and rerun nixos-install.) nixos-hardware-scan should figure out the required modules in most cases. If your machine has a limited amount of memory, you may want to activate swap devices now (swapon device). The installer (or rather, the build actions that it may spawn) may need quite a bit of RAM, depending on your configuration. Optionally, you can run $ nixos-checkout to make the installer use the latest NixOS/Nixpkgs sources from the Subversion repository, rather than the sources on CD. Do the installation: $ nixos-install Cross fingers. If everything went well: $ reboot You should now be able to boot into the installed NixOS. The Grub boot menu shows a list of available configurations (initially just one). Every time you change the NixOS configuration (see ), a new item appears in the menu. This allows you to go back easily to another configuration if something goes wrong. You should log in and change the root password with passwd. You’ll probably want to create some user accounts as well, which can be done with useradd: $ useradd -c 'Eelco Dolstra' -m eelco $ passwd eelco You may also want to install some software. For instance, $ nix-env -qa \* shows what packages are available, and $ nix-env -i w3m install the w3m browser. shows a typical sequence of commands for installing NixOS on an empty hard drive (here /dev/sda). shows a corresponding configuration Nix expression. Commands for installing NixOS on <filename>/dev/sda</filename> $ fdisk /dev/sda (or whatever device you want to install on) $ mke2fs -j -L nixos /dev/sda1 (idem) $ mkswap -L swap /dev/sda2 (idem) $ mount LABEL=nixos /mnt $ mkdir -p /mnt/etc/nixos $ nixos-hardware-scan > /mnt/etc/nixos/configuration.nix $ nano /mnt/etc/nixos/configuration.nix (in particular, set the fileSystems and swapDevices options) $ nixos-install $ reboot NixOS configuration { boot = { initrd = { extraKernelModules = [ "ata_piix" ]; }; grubDevice = "/dev/sda"; }; fileSystems = [ { mountPoint = "/"; label = "nixos"; } ]; swapDevices = [ { label = "swap"; } ]; services = { sshd = { enable = true; }; }; }
Changing the configuration The file /etc/nixos/configuration.nix contains the current configuration of your machine. Whenever you’ve changed something to that file, or to the NixOS/Nixpkgs sources in /etc/nixos/nixos and /etc/nixos/nixpkgs, respectively, you should do $ nixos-rebuild switch to build the new configuration, make it the default configuration for booting, and try to effect the configuration in the running system (e.g., by restarting system services). You can also do $ nixos-rebuild test to build the configuration and switch the running system to it, but without making it the boot default. So if (say) the configuration locks up your machine, you can just reboot to get back to a working configuration. There is also $ nixos-rebuild boot to build the configuration and make it the boot default, but not switch to it now (so it will only take effect after the next reboot). Finally, you can do $ nixos-rebuild build to build the configuration but nothing more. This is useful to see whether everything compiles cleanly.
Keeping NixOS up to date The currently best way to keep your NixOS installation up to date is to track the NixOS Subversion repository. You should replace the static NixOS/Nixpkgs sources installed in /etc/nixos with a Subversion checkout. The program nixos-checkout does that for you (and it also installs Subversion into your current profile). To build the latest and greatest, do $ svn up /etc/nixos/nixos $ svn up /etc/nixos/nixpkgs $ nixos-rebuild switch (Or instead of switch, use any of the alternatives shown in .)