Skip to content

Instantly share code, notes, and snippets.

@ivan
Last active March 27, 2020 21:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan/f525cc4f8f858ed1a0b210f6fd6693c5 to your computer and use it in GitHub Desktop.
Save ivan/f525cc4f8f858ed1a0b210f6fd6693c5 to your computer and use it in GitHub Desktop.
Replace Debian with NixOS on scaleway

Replace Debian install with NixOS on Scaleway

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
@ivan
Copy link
Author

ivan commented Jan 12, 2019

{ lib, pkgs, ... }:

let
  hostName = "scale1";

in

{
  imports = [
    ../../common/configuration.nix
    <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
  ];

  boot.loader.systemd-boot.enable = true;

  fileSystems = {
    "/"     = { device = "/dev/vda1";  fsType = "ext4"; options = [ "noatime" ]; };
    "/boot" = { device = "/dev/vda15"; fsType = "vfat"; options = [ "noatime" ]; };
  };

  networking.hostName = hostName;

}

@ivan
Copy link
Author

ivan commented Jan 12, 2019

Make sure your ../../common/configuration.nix includes an SSH server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment