|
|
(54 intermediate revisions by 25 users not shown) |
Line 1: |
Line 1: |
| This guide describes various ways of installing NixOS. The [https://nixos.org/nixos/manual/index.html#ch-installation official manual] should cover most usual use-cases. | | <languages/> |
| | <translate> |
| | <!--T:1--> |
| | This guide serves as a companion guide for the [https://nixos.org/nixos/manual/index.html#ch-installation official manual]. It describes installation of [[NixOS]] as a complete operating system. For instructions on installing [[Nix]] within an existing operating system, refer to the [[Nix Installation Guide]]. |
|
| |
|
| == Installing from USB ==
| | <!--T:2--> |
| | In addition to covering the steps from the official manual, it provides known good instructions for common use cases. When there is a discrepancy between the manual and this guide, the supported case is the one described in the manual. |
|
| |
|
| Since NixOS 14.11 the installer ISO is hybrid. This means it is bootable on both CD and USB drives. It also boots on EFI systems, like most modern motherboards and Mac* systems. Please read the [[#Hybrid image]] section on how to burn the ISO.
| | == Installation target == <!--T:4--> |
|
| |
|
| For NixOS 14.04 and earlier, please read [[#Using Unetbootin]] and the other sections below.
| | <!--T:5--> |
| | NixOS can be installed on an increasing variety of hardware: |
|
| |
|
| === Hybrid image ===
| | <!--T:6--> |
| {{Note|This section applies to NixOS 14.11. For NixOS 14.04, please refer to [[#Using Unetbootin]].}}
| | * regular (Intel or AMD) desktop computers, laptops or physically accessible servers, covered on this page |
| | * SBCs (like the Raspberry Pis) and other ARM boards, see [[NixOS on ARM]] |
| | * cloud and remote servers, see [[NixOS friendly hosters]] |
|
| |
|
| First, download a [http://nixos.org/nixos/download.html NixOS ISO image] or [[Creating a Nix OS live CD|create a custom ISO]]. Then plug in a USB stick large enough to accomodate the image. Then follow the platform instructions:
| | == Installation method == <!--T:7--> |
|
| |
|
| On Linux:
| | <!--T:8--> |
| # Find the right device with <code>fdisk -l</code>, let's say <code>/dev/sdb</code>.
| | NixOS, as with most Linux-based operating systems, can be installed in different ways. |
| # Burn with: <code>cp nixos-xxx.iso /dev/sdb</code>
| |
| {{Note|do not use /dev/sdb1 or partitions of the disk, use the whole disk /dev/sdb.}}
| |
|
| |
|
| On OS X:
| | <!--T:9--> |
| # Find the right device with <code>diskutil list</code>, let's say <code>disk<b>2</b></code>. | | # The classic way, booting from the installation media. (Described below.) |
| # Unmount with <code>diskutil unmountDisk disk<b>2</b></code>.
| | # [[Installing from Linux|Booting the media from an existing Linux installation]] |
| # Burn with: <code>sudo dd if=<b>path_to_nixos.iso</b> of=/dev/<b>r</b>disk<b>2</b> bs=64k</code>
| |
| # Note the use of rdisk instead of disk, this makes a large speed difference. You can check the write speed with <code>iostat 2</code> in another terminal. | |
|
| |
|
| You could use Disk Utility to write the image but then you'd need to convert it first to a compatible format somehow.
| | == Making the installation media == <!--T:10--> |
|
| |
|
| On Windows:
| | <!--T:11--> |
| # Download [http://sourceforge.net/projects/usbwriter/ USBwriter].
| | Since NixOS 14.11 the installer ISO is hybrid. This means it is bootable on both CD and USB drives. It also boots on EFI systems, like most modern motherboards and apple systems. The following instructions will assume the standard way of copying the image to a USB drive. When using a CD or DVD, the usual methods to burn to disk should work with the iso. |
| # Start USBwriter.
| |
| # Choose the downloaded ISO as 'Source'
| |
| # Choose the USB drive as 'Target'
| |
| # Click 'Write'
| |
| # When USBwriter has finished writing, safely unplug the USB drive.
| |
|
| |
|
| This should suffice to boot the installer. Otherwise look for other alternatives below.
| | === "Burning" to USB drive === <!--T:12--> |
|
| |
|
| === UEFI note ===
| | <!--T:13--> |
| | First, download a [https://nixos.org/download.html#nixos-iso NixOS ISO image] or [[Creating a NixOS live CD|create a custom ISO]]. Then plug in a USB stick large enough to accommodate the image. Then follow the platform instructions: |
|
| |
|
| The below is for BIOS installation. For UEFI installation see [http://nixos.org/nixos/manual/#sec-uefi-installation the manual].
| | ==== From Linux ==== <!--T:14--> |
|
| |
|
| === Using Unetbootin ===
| | <!--T:15--> |
| | # Find the right device with <code>lsblk</code> or <code>fdisk -l</code>. Replace <code><i>/dev/sdX</i></code> with the proper device in the following steps. |
| | # Copy to device: <code>cp nixos-xxx.iso <em>/dev/sdX</em></code> |
|
| |
|
| 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:
| | <!--T:16--> |
| | {{note|do not use /dev/sdX1 or partitions of the disk, use the whole disk /dev/sdX.}} |
|
| |
|
| <ol> | | <!--T:17--> |
| | Writing the disk image with <code>dd if=nixos.iso of=/dev/sdX bs=4M status=progress conv=fdatasync</code> also works. |
|
| |
|
| <li>Download a [http://nixos.org/nixos/download.html NixOS ISO image] or [[#Build a custom installation image]].</li> | | ==== From macOS ==== <!--T:18--> |
|
| |
|
| <li>Obtain a USB stick formatted with the VFAT/FAT32 filesystem with enough free disk space to hold the contents of the ISO image. {{Note|It's not necessary to erase the USB stick.}}</li> | | <!--T:19--> |
| | # Find the right device with <code>diskutil list</code>, let's say <code><i>diskX</i></code>. |
| | # Unmount with <code>diskutil unmountDisk <i>diskX</i></code>. |
| | # Burn with: <code>sudo dd if=<b>path_to_nixos.iso</b> of=/dev/<i>diskX</i></code> |
|
| |
|
| <li>Install [http://unetbootin.sourceforge.net/ UNetbootin], a tool that allows you to create a bootable USB stick from an ISO image. UNetbootin runs on both Linux and Windows. If you already have Nix/NixOS, you can install it by running <tt>nix-env -i unetbootin</tt>. [http://en.wikipedia.org/wiki/List_of_tools_to_create_Live_USB_systems Other tools] may also work.</li> | | <!--T:20--> |
| | {{tip|Using <code>rdiskX</code> instead of <code>diskX</code> can makes a large speed difference. You can check the write speed with <code>iostat 2</code> in another terminal.}} |
|
| |
|
| <li>Insert the USB stick, start UNetbootin, select the ISO file and target USB drive, and press Ok. This copies the contents of the ISO to the USB stick and installs the GRUB boot loader.</li> | | ==== From Windows ==== <!--T:21--> |
|
| |
|
| <li>You should now be able to boot NixOS from the USB stick, and perform the installation as usual.</li> | | <!--T:22--> |
| | # Download [http://sourceforge.net/projects/usbwriter/ USBwriter]. |
| | # Start USBwriter. |
| | # Choose the downloaded ISO as 'Source' |
| | # Choose the USB drive as 'Target' |
| | # Click 'Write' |
| | # When USBwriter has finished writing, safely unplug the USB drive. |
|
| |
|
| </ol> | | === Alternative installation media instructions === <!--T:23--> |
|
| |
|
| {{Note|For EFI support you may need to change the label of the FAT filesystem. You can do this on Linux with mlabel, and on OS X with diskutil: `sudo diskutil rename OLDNAME NIXOS_ISO`.}}
| | <!--T:24--> |
| | The previous methods are the supported methods of making the USB installation media. |
|
| |
|
| === Using syslinux ===
| | <!--T:25--> |
| | Those methods are also documented, they can allow using the USB drive to boot multiple distributions. This is not supported, your mileage may vary. |
|
| |
|
| ==== Using syslinux.cfg ====
| | <!--T:26--> |
| | * [[NixOS_Installation_Guide/Unetbootin|Using Unetbootin]] |
| | * [[NixOS_Installation_Guide/Manual USB Creation|Manual USB Creation]] |
| | * [[NixOS_Installation_Guide/multibootusb|multibootusb]] |
|
| |
|
| If you have trouble booting from a USB drive or sdcard with Unetbootin (I just got a blinking cursor instead of a bootloader on an Asus eee 1000) the procedure described on http://knoppix.net/wiki/Bootable_USB_Key should work. After preparing the sdcard with mkdiskimage and syslinux you can mount it and copy all the content from the NixOS iso:
| | <!--T:27--> |
| | == Booting the installation media == |
| | {{expansion|Troubleshooting steps, and details are lacking.}} |
|
| |
|
| <syntaxhighlight lang="console"> | | <!--T:28--> |
| $ mount -o loop ~/Downloads/nixos-graphical-0.1pre27337-i686-linux.iso /media/iso
| | The installation media is hybrid and is capable of booting in both legacy BIOS mode and [[UEFI]] mode. |
| $ rsync -av --progress /media/iso/ /media/sd-card/
| |
| </syntaxhighlight>
| |
|
| |
|
| The syslinux.cfg needs to be created manually, but the details can easily be derived from the grub.cfg on the NixOS install cd.
| | <!--T:29--> |
| | Whatever mode is used to boot the installation media, your motherboard or computer's configuration may need to be changed to allow booting from a Optical Disk Drive (for CD/DVD) or an external USB drive. |
|
| |
|
| I specified the root device by UUID, to get the UUID:
| | === Legacy bios boot === <!--T:30--> |
|
| |
|
| <pre> | | <!--T:31--> |
| blkid /dev/mmcblk0p1
| | This is the only boot possible on machines lacking EFI/UEFI. |
| </pre>
| |
|
| |
|
| The relevant section from the live cd: /media/sd-card/boot/grub/grub.cfg
| | === UEFI boot === <!--T:32--> |
|
| |
|
| <pre> | | <!--T:33--> |
| menuentry "NixOS Installer / Rescue" {
| | The EFI bootloader of the installation media is not signed and is not using a signed shim to boot. This means that Secure Boot will need to be disabled to boot. |
| linux /boot/bzImage init=/nix/store/r7xhnzymi1ll49r4glf1dwr5y1alx0bl-system/init root=LABEL=NIXOS_INSTALL_CD_0.1pre27337 splash=verbose vga=0x317
| |
| initrd /boot/initrd
| |
| }
| |
| </pre>
| |
|
| |
|
| can be used in the syslinux config file: /media/sd-card/syslinux.cfg (you should just need to update the init path and the root UUID / LABEL or device path)
| | == Connecting to the internet == <!--T:34--> |
|
| |
|
| <pre> | | <!--T:35--> |
| DEFAULT linux
| | The installation will '''definitely''' need a working internet connection. It is possible to install without one, but the available set of packages is limited. |
| LABEL linux
| |
| SAY Now booting the kernel from SYSLINUX...
| |
| KERNEL /boot/bzImage
| |
| APPEND init=/nix/store/r7xhnzymi1ll49r4glf1dwr5y1alx0bl-system/init root=UUID=509C-63E2 ro initrd=/boot/initrd splash=verbose
| |
| </pre>
| |
|
| |
|
| '''Note''': in place of using mkdiskimage, you can simply format your SDCard as a fat32 system and install syslinux on it:
| | === Wired === <!--T:36--> |
|
| |
|
| <pre> | | <!--T:37--> |
| mkdosfs -F32 /dev/mmcblk0p1
| | For network interfaces supported by the kernel, DHCP resolution should already have happened once the shell is available. |
| syslinux -s /dev/mmcblk0p1
| |
| </pre>
| |
|
| |
|
| === Using Command-line Tools === | | ==Tethered (Internet Sharing)== <!--T:38--> |
|
| |
|
| <ol> | | <!--T:39--> |
| <li>Download the ISO image from http://nixos.org/nixos/download.html.</li>
| | If you can not connect to the internet via cable or wifi, you may use smartphone's tethering capability to share internet. Depending on your smartphones capabilities, only stock kernel drivers may be required which can help providing a working network connection. |
|
| |
|
| <li>Prepare your USB stick. If it isn't yet partitioned to your liking, create a bootable partition on <code>/dev/sdb1</code>: | | === Wireless === <!--T:40--> |
|
| |
|
| <pre> | | <!--T:41--> |
| fdisk /dev/sdb
| | [[NetworkManager]] is installed on the graphical ISO, meaning that it is possible to use <code>nmtui</code> on the command line to connect to a network. |
| </pre> | |
|
| |
|
| And format it with:
| | <!--T:42--> |
| | Using the "Applications" tab at top |
| | left or the launcher bar at bottom, choose a terminal application and from there launch <code>nmtui</code>. This will allow you to 'activate' a (wireless) connection - your local SSIDs should be visible in the list, else you can add a new connection. When the wireless connection is active and you have tested it, it is likely the install app which launched on startup has not detected the new connection. Close down the install app, and reopen it from the launcher bar at the bottom of the screen. This should then find the new connection and proceed. |
|
| |
|
| <pre> | | <!--T:43--> |
| mkdosfs /dev/sdb1
| | On the minimal ISO, or if you are more familiar with [[wpa_supplicant]] then you can also run <code>wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf</code>, then enter your password and <code>systemctl restart wpa_supplicant</code>. |
| </pre> | |
|
| |
|
| Add ext2 partitions if you like. If you want both 32-bit and 64-bit NixOS, you need at least two partitions. You can directly use the entire disk without partition if that's what you like. Once you have your VFAT (dosfs) block device, you should give it a label, within a 11-character limit, e.g.:
| | == Partitioning == <!--T:44--> |
|
| |
|
| <pre> | | <!--T:45--> |
| dosfslabel /dev/sdb1 NIXBOOT
| | To partition the persistent storage run <code>sudo fdisk /dev/diskX</code> and follow instructions for MBR or (U)EFI. To determine which mode you are booted into, run: |
| </pre>
| |
| </li> | |
|
| |
|
| <li>Mount the bootable USB partition with: | | <syntaxhighlight lang="console"> |
| | $ [ -d /sys/firmware/efi/efivars ] && echo "UEFI" || echo "Legacy" |
| | </syntaxhighlight> |
|
| |
|
| <pre>
| |
| mkdir -p /media/NIXBOOT
| |
| mount /dev/sdb1 /media/NIXBOOT
| |
| </pre>
| |
| </li>
| |
|
| |
|
| <li>Mount the ISO image with:
| | A very simple example setup is given here. |
|
| |
|
| <pre> | | === Legacy Boot (MBR) === <!--T:46--> |
| mkdir -p /media/iso
| |
| mount -o loop ~/Downloads/nixos-graphical-0.2pre4463_5e88e9b-c877f45-x86_64-linux.iso /media/iso
| |
| </pre>
| |
| </li>
| |
|
| |
|
| <li>Copy the contents of the NixOS ISO (<code>/media/iso</code>) to your USB stick (<code>/media/NIXBOOT</code>) with: | | <!--T:47--> |
| | * o (dos disk label) |
| | * n new |
| | * p primary (4 primary in total) |
| | * 1 (partition number [1/4]) |
| | * 2048 first sector (alignment for performance) |
| | * +500M last sector (boot sector size) |
| | * rm signature (Y), if ex. => warning of overwriting existing system, could use wipefs |
| | * n |
| | * p |
| | * 2 |
| | * default (fill up partition) |
| | * default (fill up partition) |
| | * w (write) |
|
| |
|
| <pre> | | === UEFI === <!--T:48--> |
| rsync -av --progress /media/iso/ /media/NIXBOOT/
| |
| </pre>
| |
| </li>
| |
|
| |
|
| <li>Install a complete and recent GRUB to the USB stick with: | | <!--T:49--> |
| | * g (gpt disk label) |
| | * n |
| | * 1 (partition number [1/128]) |
| | * 2048 first sector |
| | * +500M last sector (boot sector size) |
| | * t |
| | * 1 (EFI System) |
| | * n |
| | * 2 |
| | * default (fill up partition) |
| | * default (fill up partition) |
| | * w (write) |
|
| |
|
| <pre> | | === Format partitions === <!--T:50--> |
| grub-install /dev/sdb --root-directory=/media/NIXBOOT/
| |
| </pre>
| |
| </li>
| |
|
| |
|
| <li>Edit the file <code>/media/NIXBOOT/boot/grub/grub.cfg</code>. Start from an existing grub.cfg, say from your hard drive or from another working bootable USB stick (e.g., from GRML.org). Then, merge in the entry for NixOS from <code>/media/iso/boot/grub/grub.cfg</code>, modifying the LABEL to be that of your VFAT partition: | | <!--T:51--> |
| | The example below uses the [[ext4]] filesystem format. If you wish to use other filesystem formats such as [[Btrfs]] or [[ZFS]]: |
|
| |
|
| <pre>
| | * [[Bcachefs#NixOS installation on bcachefs]] |
| menuentry "NixOS Installer / Rescue" {
| | * [[Btrfs#Installation of NixOS on btrfs]] |
| linux /boot/bzImage init=/nix/store/p94ckcksmhj90cr868cpcajrqgzwy57w-nixos-0.2pre4463_5e88e9b-c877f45/init root=LABEL=NIXBOOT
| | * [[LVM#Basic Setup]] |
| initrd /boot/initrd
| | * [[ZFS#Simple NixOS ZFS on root installation]] |
| }
| |
| </pre>
| |
| </li>
| |
|
| |
|
| <li>To share your USB stick with other distributions (e.g., GRML, or both 32- and 64- bit NixOS), you can move NixOS's bzImage and initrd to different location (e.g., <code>/boot/nix32/</code> and <code>/boot/nix64/</code>), and you appropriately edit the entries in your grub.cfg. If you have both nix32 and nix64, only one can have its <code>nix-store.squashfs</code> in the root of any given partition. That's where you can use a second partition, for the second one. For instance, copy the contents of your 64-bit NixOS to the first partition, with label <code>NIX64</code>, and copy the nix-store.squashfs of your 32-bit NixOS to the second partition with label <code>NIX32</code> (and create an empty nix/store). Copy the 32-bit kernel and initrd to <code>/boot/nix32/</code> on the bootable partition, and edit the grub.cfg of the bootable partition accordingly.</li>
| | This is useful for having multiple setups and makes partitions easier to handle<syntaxhighlight lang="console"> |
| | | $ lsblk # lists current system block devices |
| <li>There you go: you have a bootable NixOS USB drive, possibly allowing you to boot NixOS 64-bit, NixOS 32-bit, GRML 64-bit, GRML 32-bit, FreeBSD, FreeDOS, boot-sector-tetris, etc. Just you convince your BIOS to let you boot off it.</li>
| | # mkfs.fat -F 32 -n boot /dev/sdX1 |
| </ol>
| | # mkfs.ext4 /dev/sdX2 -L nixos |
| | | # mount /dev/disk/by-label/nixos /mnt |
| == Build a custom installation image ==
| | # mkdir -p /mnt/boot |
| | | # mount /dev/disk/by-label/boot /mnt/boot |
| NixOS provides an easy way to build a custom variant of the installation image. This might be useful to embed your own ssh key or enable additional features like zfs support. It allows to specify a custom <code>configuration.nix</code> which is used to build the image
| | </syntaxhighlight> |
| This is explained in [[Creating a NixOS live CD]].
| |
| | |
| == Installing on VPS & Cloud Providers ==
| |
| | |
| Not all providers allow to upload own images or provide NixOS images for installation. However there are a few ways to install NixOS anyhow. [https://github.com/jeaye/nixos-in-place nixos-in-place] and [https://github.com/elitak/nixos-infect nixos-infect] are generic approaches to install NixOS from an existing Linux. A different approach is to build an kexec-based image to start the installer from an booted linux as shown in this [https://github.com/cleverca22/nix-tests/tree/master/kexec repo]. Here we list methods known to work on specific providers:
| |
| | |
| === Hetzner ===
| |
| | |
| Hetzner provides an [https://wiki.hetzner.de/index.php/LARA/en#Installing_an_OS interface] to upload your own ISO-images. However you may want to build your own iso-image, which has openssh with ssh keys due the lack of a remote console. An easier method to install NixOS on Hetzner, is to use the existing integration into [https://nixos.org/nixops/manual/#idm140737318364240 NixOps].
| |
| | |
| === Amazon S3 ===
| |
| see [[NixOS on Amazon EC2]].
| |
| | |
| === Digital Ocean ===
| |
| | |
| On Digitalocean the project [https://github.com/elitak/nixos-infect nixos-infect] can be used to transform an existing installation into NixOS. This method will be also used in [https://nixos.org/nixops/manual/#sec-deploying-to-digital-ocean NixOps].
| |
| | |
| === Netcup ===
| |
| | |
| You can mount your own images similar to hetzner, see the [https://www.netcup-wiki.de/wiki/Server_Control_Panel_%28SCP%29#Eigene_DVDs official netcup documentation].
| |
| | |
| === Linode ===
| |
| | |
| NixOS is official supported by Linode. Up to date documentation can be obtained from their [https://www.linode.com/docs/tools-reference/custom-kernels-distros/install-nixos-on-linode manual]
| |
| | |
| === CloudAtCost ===
| |
| | |
| === Scaleway ===
| |
| | |
| The <code>kexec</code> method above works well, but bear in mind it only works with the 'virtual' class of servers, as they run under a hypervisor which attaches the disks before the kernel boots. The 'bare-metal' servers rely on a special Linux kernel booting to attach network <code>/dev/nbdX</code> drives which works only with Scaleway supplied images.
| |
| | |
| === Rackspace ===
| |
| | |
| See [[Install NixOS on Rackspace Cloud Servers]].
| |
| | |
| === Google Compute Engine ===
| |
| | |
| See [[Installing NixOS on GCE]].
| |
| | |
| === Online.net ===
| |
| | |
| See [[Install NixOS on Online.Net]].
| |
| | |
| == 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
| | <!--T:53--> |
| | == NixOS configuration == |
|
| |
|
| The following sections outline two installation methods. Choose the one that suits you best.
| | NixOS is configured through a [[Overview of the NixOS Linux distribution#Declarative Configuration|declarative configuration]] file. To generate a default config file, run [[nixos-generate-config]]: |
| | |
| === 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"> | | <syntaxhighlight lang="console"> |
| # cd host | | # nixos-generate-config --root /mnt |
| # mkdir -p etc dev proc sys
| | # nano /mnt/etc/nixos/configuration.nix |
| # cp /etc/resolv.conf etc | |
| # for fn in dev proc sys; do mount --bind /$fn $fn; done
| |
| </syntaxhighlight> | | </syntaxhighlight> |
|
| |
|
| ==== Circumventing regular init sequence ====
| | For information on working with a system configuration, see [[NixOS system configuration]]. For desktop-specific configurations, see [[NixOS as a desktop]]. |
|
| |
|
| To properly chroot into the host system you must locate the packages named nixos and bash. The following commands may prove helpful:
| | Most essential changes: |
| <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.'''
| | <!--T:54--> |
| | * keyboard layout, ie <code>[[Keyboard Layout Customization|services.xserver.xkb.layout]]</code> |
| | * [[networking]] (wifi), see below for fix if it breaks |
| | * install [[:Category:Text Editor|editor]] to edit the configuration |
|
| |
|
| 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.
| | <!--T:55--> |
| <syntaxhighlight lang="console"> | | The self-documenting NixOS options can be searched with [https://search.nixos.org/options NixOS options search]. |
| # sed -i "s,exec systemd,exec /$BASH," $INIT
| |
| </syntaxhighlight>
| |
|
| |
|
| ==== Starting the install ==== | | <!--T:52--> |
| | === Swap file === |
|
| |
|
| 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.
| | For additional methods of configuring swap, see [[Swap]]. The following example demonstrates how to create and enable a [[Swap#Swap file|swap file]]: |
| <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.
| | {{file|/mnt/etc/nixos/configuration.nix|nix| |
| <syntaxhighlight lang="console"> | | <nowiki> |
| # (chroot) mount /dev/sda3 /mnt
| | swapDevices = [{ |
| # (chroot) nixos-generate-config --root /mnt | | device = "/var/lib/swapfile"; |
| # (chroot) nano /etc/nixos/configuration.nix
| | size = 16*1024; # 16 GB |
| </syntaxhighlight> | | }]; |
| | </nowiki> |
| | }} |
|
| |
|
| 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.
| | === Bootloader === |
| <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.
| | NixOS supports multiple [[Bootloader|bootloaders]] such as [[GNU GRUB]] and [[Systemd/boot]]. |
| <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.
| | Systemd-boot is the recommended bootloader. The following example demonstrates how to enable systemd-boot in your configuration: |
|
| |
|
| 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.
| | {{file|/mnt/etc/nixos/configuration.nix|nix| |
| | <nowiki> |
| | boot.loader.systemd-boot.enable = true; |
| | </nowiki> |
| | }} |
|
| |
|
| === Running the LiveCD installer from disk ===
| | You may also wish to configure [[Secure Boot]]. |
| In this section we will install NixOS by transfering the installer from the ISO to a bootable partition and then running it.
| |
|
| |
|
| '''WARNING'''
| | === Users === |
|
| |
|
| This approach relies on merging the LiveCD image with the contents of your working partition, so several limitations apply:
| | For information on creating and managing users, see [[User management]] and the {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#sec-user-management}}. See an example below: |
| * 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 ==== | | {{file|/mnt/etc/nixos/configuration.nix|nix| |
| | <nowiki> |
| | users.users.alice = { |
| | isNormalUser = true; |
| | initialPassword = "pw123"; |
| | }; |
| | </nowiki> |
| | }} |
|
| |
|
| | == NixOS installation == |
| <syntaxhighlight lang="console"> | | <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!) | | # cd /mnt |
| # modprobe loop
| | # nixos-install |
| # mount -o loop nixos-minimal-17.03.1449.2e983f14f6-x86_64-linux.iso ~/inst
| | </syntaxhighlight>after installation: Run <code>passwd</code> to change user password. |
| # # mount /dev/sda1 # mount the /boot partition if you have it
| | |
| # cp ~/inst/boot/bzImage /boot/nixos-livecd-bzImage | | <!--T:57--> |
| # cp ~/inst/boot/initrd /boot/nixos-livecd-initrd | | if internet broke/breaks, try one of the following:<syntaxhighlight lang="console"> |
| # cp ~/inst/nix-store.squashfs /nix-store.squashfs
| | # nixos-rebuild switch --option substitute false # no downloads |
| | # nixos-rebuild switch --option binary-caches "" # no downloads |
| </syntaxhighlight> | | </syntaxhighlight> |
| | * wpa_supplicant flags to connect to wifi |
|
| |
|
| ==== Modifying your bootloader's config ====
| | <!--T:58--> |
| | | <hr /> |
| 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 1 =====
| |
| | |
| 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 ==== | | == Additional notes for specific hardware == <!--T:59--> |
|
| |
|
| Reboot. Select "NixOS LiveCD" from the bootloader menu. If everything is OK, you
| | <!--T:60--> |
| will see Login prompt asking you to login as root with empty password.
| | These are collected notes or links for specific hardware issues. |
| ''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 ==
| |
|
| |
|
| | <!--T:61--> |
| * Blog post how to install NixOS on a [http://grahamc.com/blog/nixos-on-dell-9560 Dell 9560] | | * Blog post how to install NixOS on a [http://grahamc.com/blog/nixos-on-dell-9560 Dell 9560] |
| * for embedded Hardware like the Raspberry Pi2 see [[NixOS on ARM]]
| | * Brand servers may require extra kernel modules be included into initrd (<code>boot.initrd.extraKernelModules</code> in configuration.nix) For example HP Proliant needs "hpsa" module to see the disk drive. |
| * Brand servers may require extra kernel modules be included into initrd (boot.initrd.extraKernelModules in configuration.nix) For example HP Proliant needs "hpsa" module to see the disk drive. | |
| | |
|
| |
|
| | <!--T:62--> |
| [[Category:Guide]] | | [[Category:Guide]] |
| | | [[Category:Deployment]] |
| [[Category:Installation]] | | [[Category:NixOS]] |
| | </translate> |