This is based on nixos-infect.
These instructions assume you have x86 scaleway machines that use UEFI and DHCP. You have may have to change /dev/vda15
if your machines are partitioned differently.
First, rsync
your configuration
to /root/configuration
.
Run:
apt-get update
apt-get install dosfstools
# Get more space on tiny scaleways
tune2fs -m 0 /dev/vda1
umount /boot/efi
mkfs.fat -F 32 -n boot /dev/vda15
rm -rf /boot
mkdir /boot
mount -o noatime /dev/vda15 /boot
mkdir -p -m 0755 /nix
# Add nix build users
groupadd nixbld -g 30000 || true
for i in {1..10}; do
useradd -c "Nix build user $i" -d /var/empty -g nixbld -G nixbld -M -N -r -s "$(which nologin)" nixbld$i || true
done
curl -JLO https://nixos.org/nix/install
chmod +x install
./install
. ~/.nix-profile/etc/profile.d/nix.sh
nix-channel --remove nixpkgs
nix-channel --add "https://nixos.org/channels/nixos-unstable" nixos
nix-channel --update
export NIXOS_CONFIG=/root/configuration/machines/$(hostname).nix
nix-env --set \
-I nixpkgs=$HOME/.nix-defexpr/channels/nixos \
-f '<nixpkgs/nixos>' \
-p /nix/var/nix/profiles/system \
-A system
# Remove nix installed by ./install
rm -fv /nix/var/nix/profiles/default*
/nix/var/nix/profiles/system/sw/bin/nix-collect-garbage
# Use the lustrate mechanism to move away almost all files on next boot
touch /etc/NIXOS /etc/NIXOS_LUSTRATE
echo etc/nixos >> /etc/NIXOS_LUSTRATE
echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE
echo var/secrets >> /etc/NIXOS_LUSTRATE
/nix/var/nix/profiles/system/sw/bin/bootctl install
/nix/store/n6pmahfpmkm1q7i9p63dwib8asb3cs05-systemd-boot-builder.py system
# Confirm that there is a default boot entry for NixOS here:
/nix/var/nix/profiles/system/sw/bin/bootctl list
shutdown -r now