An all-in-one script for installing NixOS on top of any existing Linux system without using live media. When you reboot, you're in NixOS.
nixos-in-place is known to work on Ubuntu, Debian, CentOS, Fedora, Arch, and Slackware, including x86 and x86_64 variants, with and without LVM, including systems on Digital Ocean droplets and Hetzner Cloud!
How to do it
See the Platform-specifics for your distribution
Run the following (see
./install -hfor options)
STOP AND VERIFY, then hit
Grab some coffee while NixOS installs
yto reboot into NixOS! (root's password will be 'nixos')
Go through the first section of
/etc/nixos/nixos-in-place.nixand remove or change it as you see fit
What you get
A fresh install of NixOS, either minimal or graphical (your choice). Your
old system and all your old files still exist and are setup to mount on
/old-root. As far as the file system is concerned, NixOS is installed in
/ is rebound before spinning up the system; everything
/old-root is fair game to delete.
NixOS installs GRUB2 on top of your existing boot loader. If you'd like to boot
/old-root, you can; you just need to add the GRUB entry, from
/old-root/boot/grub, manually in your Nix files.
DO makes some assumptions about static ips and networking, based on the droplet OS and version you choose. nixos-in-place will work best from a Debian 8 droplet.
To install on a DO droplet, follow the normal steps for your platform, but add
-d flag to
-h for more info). Once installed, if you
/old-root, you must keep
/old-root/etc/network around; DO needs it!
The default configuration for NixOS disables SSH, so you'll need to use the DO console, once you've finished the installation, in order to setup which services you'd actually like.
I recommend installing from a tmux session, to avoid SSH timeouts and losing access to your install part-way through. Seriously, use tmux or screen.
$ apt-get install -y squashfs-tools git
$ apt-get install -y squashfs-tools git
$ pacman -Sy wget squashfs-tools git
$ yum -y install wget squashfs-tools git
$ dnf -y install wget squashfs-tools git
Slackware 14.1 (and -current)
Both Slackware 14.1 and -currrent have a bug where
references a non-existent
/dev/root. You'll need to manually create a link to
your file system root for GRUB to install properly. Example:
ln -s /dev/sda1 /dev/root. For the dependencies, you'll need to go through AUR; use
sbopkg or something else.
$ sbopkg squashfs-tools
It's recommended that you have 1GB of available RAM for unsquashing the NixOS live media. If you're on a machine with less RAM, such as a VPS with 512MB, you can quickly make a swap file for the install.
$ dd if=/dev/zero of=swap bs=1M count=1024 $ mkswap ./swap $ chmod 600 ./swap $ swapon ./swap
To remove it, after the install.
$ swapoff ./swap $ rm -f ./swap
Systems may use LVM. In which case, you'll need to specify
-g with the proper
device for GRUB (likely
/dev/sda). If your guessed GRUB device looks like
/dev/mapper/xxx and not
/dev/xxx then you're likely using LVM.
Systems may put
/tmp onto its own tmpfs, so you may get a warning saying there
may not be enough space. Double check on your own, with
df -h, and feel free
How it works
- Install into
- Wipe out boot loader with GRUB
- Bind the old
More descriptively, the provided
install script will verify your system is
sane, allow you to configure some options, and then pull down the latest ISO
from NixOS. It them enters Stage 1.
Once we have the NixOS live CD ISO, we mount it locally and modify it. The modifications enable us to imbue the image with a chroot that runs Stage 2. Before we chroot, we bind in a number of the host's devices and files into the chroot environment to ensure that functionality like networking will work.
Once we're in the NixOS live CD chroot, we modify the NixOS configs to convey
that it's not a typical setup. After that, we install to
/nixos, which is
bound to the host's
/nixos. NixOS then installs GRUB and we're good to reboot
into our new machine!
The testing suite can be run like so (requires vagrant):