NixOS Installation Guide: Difference between revisions

imported>Ixxie
m Ixxie moved page Installation guide to NixOS Installation Guide: Name consistency.
imported>Ixxie
No edit summary
Line 9: Line 9:




== Hybrid image ==
=== Hybrid image ===
{{Note|This section applies to NixOS 14.11. For NixOS 14.04, please refer to [[#Using Unetbootin]].}}
{{Note|This section applies to NixOS 14.11. For NixOS 14.04, please refer to [[#Using Unetbootin]].}}


Line 53: Line 53:
-->
-->


== UEFI note ==
=== UEFI note ===


The below is for BIOS installation. For UEFI installation see [http://nixos.org/nixos/manual/#sec-uefi-installation the manual].
The below is for BIOS installation. For UEFI installation see [http://nixos.org/nixos/manual/#sec-uefi-installation the manual].


== Using Unetbootin ==
=== Using Unetbootin ===


It is possible to install NixOS from a USB stick, rather than from a CD.  This is useful if you want to install NixOS on a machine that doesn't have a CD-ROM drive (such as most netbooks), or if you don't want to waste a blank CD.  Here is how to do it:
It is possible to install NixOS from a USB stick, rather than from a CD.  This is useful if you want to install NixOS on a machine that doesn't have a CD-ROM drive (such as most netbooks), or if you don't want to waste a blank CD.  Here is how to do it:
Line 238: Line 238:
See [[Install NixOS on Online.Net]].
See [[Install NixOS on Online.Net]].


==== <your vps provider here> ====
== Installing from Linux ==
You already have a running linux with GRUB on your primary partition and you don't want to waste a CD-R?
Right. We also assume that you have a spare partition where to install NixOS ready.
 
To simplify, we will be using these abbreviations:
 
;/dev/sda1  : your boot partition, containing already working grub
 
;/dev/sda2  : your linux root partition, containing your currently working OS  (/dev/sda1 and /dev/sda2 *can* be the same partition!)
 
;/dev/sda3  : your spare partition to where you will install NixOS
 
;/boot      : the boot directory, where grub is installed
 
;~/inst    : directory where the ISO is (loop) mounted
 
The following sections outline two installation methods. Choose the one that suits you best.
 
== Installing through a chroot ==
In this section we will install NixOS by unpacking the ISO and then chrooting into its contents to start the final install.
 
=== Preparations ===
Get a NixOS ISO and unpack the squashfs filesystem containing the nix store. A tool from squashfs-tools is required, so install that package first.
 
The following commands create two directories in your home directory, one for the ISO mountpoint and one for the host system. Then the ISO is downloaded (substitute as you please), mounted and the nix store extracted.
<syntaxhighlight lang="console">
# cd ~
# mkdir -p inst host/nix
# wget https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1449.2e983f14f6/nixos-minimal-17.03.1449.2e983f14f6-x86_64-linux.iso
# modprobe loop
# mount -o loop nixos-minimal-17.03.1449.2e983f14f6-x86_64-linux.iso inst
# unsquashfs -d host/nix/store inst/nix-store.squashfs '*'
</syntaxhighlight>
 
To have a working network connection, copy /etc/resolv.conf to host/nix/etc. For a working chroot, you also need to bind /dev, /proc and /sys directories to the target system.
<syntaxhighlight lang="console">
# cd host
# mkdir -p etc dev proc sys
# cp /etc/resolv.conf etc
# for fn in dev proc sys; do mount --bind /$fn $fn; done
</syntaxhighlight>
 
==== Circumventing regular init sequence ====
 
To properly chroot into the host system you must locate the packages named nixos and bash. The following commands may prove helpful:
<syntaxhighlight lang="console">
# INIT=$(find . -type f -path '*nixos*/init')
# echo $INIT
./nix/store/abwlkvzyjd2i39b1l1wfv7v9ilx88fwi-nixos-0.1pre34067-34077/init
# BASH=$(find . -type f -path '*/bin/bash' | tail -n 1)
# echo $BASH
./nix/store/bmgq2jrn6719r6j55gs4rzfp0azcbazy-bash-4.2-p24/bin/bash
</syntaxhighlight>
 
'''Replace further mentions of these files with your own results! Note the missing prefix in some uses.'''
 
Next we have to edit the target system init script to start a bash session instead of systemd. As that is the last thing the script does, adding an interactive program does not pose a problem.
<syntaxhighlight lang="console">
# sed -i "s,exec systemd,exec /$BASH," $INIT
</syntaxhighlight>
=== Starting the install ===
Now we are able to chroot into the NixOS system used for installation. ''You may get several warnings and errors, but you can safely ignore them unless they are fatal.'' If you're installing from Arch, you may need to remove the mount call that tries to make / private in the same init script.
<syntaxhighlight lang="console">
# chroot . /$INIT
</syntaxhighlight>
'''Further commands to be executed in the chrooted environment will be prefixed with "# (chroot)"'''.
 
The next steps are the same as with classical installation methods. Create a suitable NixOS [http://nixos.org/nixos/manual/#ch-configuration configuration] and start the build.
<syntaxhighlight lang="console">
# (chroot) mount /dev/sda3 /mnt
# (chroot) nixos-generate-config --root /mnt
# (chroot) nano /etc/nixos/configuration.nix
</syntaxhighlight>
 
Before executing nixos-install you might want to run nixos-checkout to obtain the most recent version of packages to be installed into your NixOS system. You might need to copy /etc/resolv.conf from the host to the target system.
<syntaxhighlight lang="console">
# (chroot) nixos-checkout
# (chroot) nixos-install
</syntaxhighlight>
 
Now your system should be set up. Be sure to change the root password to be able to login and double check that /mnt/boot/grub/menu.lst is present and looks sensible.
<syntaxhighlight lang="console">
# (chroot) passwd
</syntaxhighlight>
 
Finally, if you instructed nix not to overwrite your existing boot loader, manually copy the menu.lst entries into your existing system's GRUB menu.lst.
 
Once you're done tweaking, exit the chroot (exit or ctrl-d will) and reboot. With any luck, you will have new choices in the GRUB menu to choose from.
 
== Running the LiveCD installer from disk ==
In this section we will install NixOS by transfering the installer from the ISO to a bootable partition and then running it.
 
'''WARNING'''
 
This approach relies on merging the LiveCD image with the contents of your working partition, so several limitations apply:
* the target partition needs to have enough free space for both the working partition (/dev/sda2) and the uncompressed nix store from the LiveCD
* /etc will be merged, so your current settings can interfere with the final installation steps
 
=== Unpacking the ISO image ===
<syntaxhighlight lang="console">
# wget https://d3g5gsiof5omrk.cloudfront.net/nixos/17.03/nixos-17.03.1449.2e983f14f6/nixos-minimal-17.03.1449.2e983f14f6-x86_64-linux.iso # get the latest iso (URL might change!)
# modprobe loop
# mount -o loop nixos-minimal-17.03.1449.2e983f14f6-x86_64-linux.iso ~/inst
# # mount /dev/sda1 # mount the /boot partition if you have it
# cp ~/inst/boot/bzImage /boot/nixos-livecd-bzImage
# cp ~/inst/boot/initrd /boot/nixos-livecd-initrd
# cp ~/inst/nix-store.squashfs /nix-store.squashfs
</syntaxhighlight>
 
=== Modifying your bootloader's config ===
 
Look at some_dir/boot/grub/grub.cfg. This is Grub-2 main config file of the ISO.
Locate the NixOS menuentry section:
 
<pre>
menuentry "NixOS Installer / Rescue" {
  linux /boot/bzImage init=/nix/store/p5n72ay1c1wx4wry90zabr8jnljpdzgx-nixos-0.2pre4601_1def5ba-48a4e91/init root=LABEL=NIXOS_0.2pre4601_1def5ba-48a4e91
  initrd /boot/initrd
}
</pre>
 
The goal is to tell your bootloader to boot /nixos-livecd-bzImage with correct
init argument.
 
==== Grub < 2 ====
 
To setup grub-1, edit your /boot/grub/menu.lst (or equivalent). Add following
lines to the config:
<pre>
title NixOS LiveCD
kernel /nixos-livecd-bzImage init=/nix/store/p5n72ay1c1wx4wry90zabr8jnljpdzgx-nixos-0.2pre4601_1def5ba-48a4e91/init root=/dev/sda2 splash=verbose vga=0x317
initrd /nixos-livecd-initrd
</pre>
 
Note, that hash should match with what you have seen in some_dir/grub/grub.cfg
 
Go to the reboot section
 
==== GRUB 2 ====
 
A grub entry for ubuntu might look like this:
 
<pre>
menuentry "NixOS Installer / Rescue" {
  linux /nixos-livecd-bzImage init=/nix/store/p5n72ay1c1wx4wry90zabr8jnljpdzgx-nixos-0.2pre4601_1def5ba-48a4e91/init root=/dev/sda2
  initrd /nixos-lived-initrd
}
</pre>
 
==== Other bootloaders ====
 
Should also work. Please add instructions here.
 
=== Booting into LiveCD ===
 
Reboot. Select "NixOS LiveCD" from the bootloader menu. If everything is OK, you
will see Login prompt asking you to login as root with empty password.
''DO NOT TRUST IT BLINDLY.
You probably have your /etc mounted from /dev/sda2 so
it contains your old passwd (as well as LiveCD stuff merged into by the means of
UnionFS). So if empty password is not working, try your old root password.
 
Thats it. Now follow the manual (Alt-F8), mount /dev/sda3 as /mnt, do
nixos-option and so on.


== Special hardware ==
== Special hardware ==