hosts: nixos: porthos: migrate to new host

OVH/Kimsufi are deprecating my current server by the end of the year. So
let's migrate to a new host.

This was more painful than initially planned, OVH introduced a change to
their rescue system which messes with the NixOS installation [1].

In the end I used a kexec image [2] to run the installation.

[1]: https://github.com/NixOS/nix/issues/7790
[2]: https://github.com/nix-community/nixos-images
This commit is contained in:
Bruno BELANYI 2024-03-05 00:45:31 +01:00
parent 0f33dbd5c2
commit 5d3160fb0d
7 changed files with 48 additions and 46 deletions

View file

@ -3,15 +3,14 @@
{ {
boot = { boot = {
# Use the GRUB 2 boot loader. # Use the systemd-boot EFI boot loader.
loader.grub = { loader = {
enable = true; systemd-boot.enable = true;
# Define on which hard drive you want to install Grub. efi.canTouchEfiVariables = true;
device = "/dev/disk/by-id/ata-HGST_HUS724020ALA640_PN2181P6J58M1P";
}; };
initrd = { initrd = {
availableKernelModules = [ "uhci_hcd" "ahci" "usbhid" ]; availableKernelModules = [ "ahci" "xhci_pci" "ehci_pci" "usbhid" "sd_mod" ];
kernelModules = [ "dm-snapshot" ]; kernelModules = [ "dm-snapshot" ];
}; };

View file

@ -16,11 +16,5 @@
# Set your time zone. # Set your time zone.
time.timeZone = "Europe/Paris"; time.timeZone = "Europe/Paris";
# This value determines the NixOS release from which the default system.stateVersion = "24.05"; # Did you read the comment?
# settings for stateful data, like file locations and database versions
# on your system were taken. Its perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "20.09"; # Did you read the comment?
} }

View file

@ -1,5 +1,5 @@
# Hardware configuration # Hardware configuration
{ lib, modulesPath, ... }: { modulesPath, ... }:
{ {
imports = [ imports = [
@ -11,9 +11,18 @@
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/boot" = {
device = "/dev/disk/by-label/boot";
fsType = "vfat";
};
swapDevices = [ swapDevices = [
{ device = "/dev/disk/by-label/swap"; } { device = "/dev/disk/by-label/swap"; }
]; ];
powerManagement.cpuFreqGovernor = lib.mkDefault "ondemand"; my.hardware = {
firmware = {
cpuFlavor = "intel";
};
};
} }

View file

@ -3,7 +3,7 @@
SWAP_SIZE=16GiB SWAP_SIZE=16GiB
parted /dev/sda --script -- \ parted /dev/sda --script -- \
mklabel msdos \ mklabel gpt \
mkpart primary 512MiB -$SWAP_SIZE \ mkpart primary 512MiB -$SWAP_SIZE \
mkpart primary linux-swap -$SWAP_SIZE 100% \ mkpart primary linux-swap -$SWAP_SIZE 100% \
mkpart ESP fat32 1MiB 512MiB \ mkpart ESP fat32 1MiB 512MiB \
@ -11,14 +11,24 @@ parted /dev/sda --script -- \
parted /dev/sdb --script -- \ parted /dev/sdb --script -- \
mklabel gpt \ mklabel gpt \
mkpart primary 0MiB 100% mkpart primary 0% 100%
parted /dev/sdc --script -- \
mklabel gpt \
mkpart primary 0% 100%
parted /dev/sdd --script -- \
mklabel gpt \
mkpart primary 0% 100%
mkfs.ext4 -L media1 /dev/sda1 mkfs.ext4 -L media1 /dev/sda1
mkfs.ext4 -L media2 /dev/sdb1 mkfs.ext4 -L media2 /dev/sdb1
mkfs.ext4 -L media3 /dev/sdc1
mkfs.ext4 -L media4 /dev/sdd1
pvcreate /dev/sda1 pvcreate /dev/sda1
pvcreate /dev/sdb1 pvcreate /dev/sdb1
vgcreate lvm /dev/sda1 /dev/sdb1 pvcreate /dev/sdc1
pvcreate /dev/sdd1
vgcreate lvm /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
lvcreate -l 100%FREE -n media lvm lvcreate -l 100%FREE -n media lvm
mkfs.ext4 -L nixos /dev/mapper/lvm-media mkfs.ext4 -L nixos /dev/mapper/lvm-media
@ -27,17 +37,17 @@ mkfs.fat -F 32 -n boot /dev/sda3
mount /dev/disk/by-label/nixos /mnt mount /dev/disk/by-label/nixos /mnt
swapon /dev/sda2 swapon /dev/sda2
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
apt install sudo apt install sudo
useradd -m -G sudo setupuser useradd -m -G sudo setupuser
# shellcheck disable=2117
su setupuser
cat << EOF cat << EOF
# Run the following commands as setup user # Run the following commands as setup user
curl -L https://nixos.org/nix/install | sh curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
. $HOME/.nix-profile/etc/profile.d/nix.sh . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
nix-channel --add https://nixos.org/channels/nixos-20.09 nixpkgs nix profile install nixpkgs#nixos-install-tools
sudo "$(which nixos-generate-config)" --root /mnt sudo "$(which nixos-generate-config)" --root /mnt
# Change uuids to labels # Change uuids to labels
@ -54,3 +64,6 @@ git crypt unlock
nixos-install --root /mnt --flake '.#<hostname>' nixos-install --root /mnt --flake '.#<hostname>'
EOF EOF
# shellcheck disable=2117
su setupuser

View file

@ -6,30 +6,17 @@
hostName = "porthos"; # Define your hostname. hostName = "porthos"; # Define your hostname.
domain = "belanyi.fr"; # Define your domain. domain = "belanyi.fr"; # Define your domain.
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# The global useDHCP flag is deprecated, therefore explicitly set to false here. # (the default) this is the recommended approach. When using systemd-networkd it's
# Per-interface useDHCP will be mandatory in the future, so this generated config # still possible to use this option, but it's recommended to use it in conjunction
# replicates the default behaviour. # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
useDHCP = false; useDHCP = true;
interfaces = { interfaces = {
bond0.useDHCP = true; eno1.useDHCP = true;
bonding_masters.useDHCP = true; eno2.useDHCP = true;
dummy0.useDHCP = true;
erspan0.useDHCP = true;
eth0.useDHCP = true;
eth1.useDHCP = true;
gre0.useDHCP = true;
gretap0.useDHCP = true;
ifb0.useDHCP = true;
ifb1.useDHCP = true;
ip6tnl0.useDHCP = true;
sit0.useDHCP = true;
teql0.useDHCP = true;
tunl0.useDHCP = true;
}; };
}; };
# Which interface is used to connect to the internet # Which interface is used to connect to the internet
my.hardware.networking.externalInterface = "eth0"; my.hardware.networking.externalInterface = "eno1";
} }

View file

@ -49,7 +49,7 @@ in
}; };
porthos = { porthos = {
hostname = "91.121.177.163"; hostname = "37.187.146.15";
identityFile = "~/.ssh/shared_rsa"; identityFile = "~/.ssh/shared_rsa";
user = "ambroisie"; user = "ambroisie";
}; };

View file

@ -13,7 +13,7 @@ let
porthos = { porthos = {
clientNum = 1; clientNum = 1;
publicKey = "PLdgsizztddri0LYtjuNHr5r2E8D+yI+gM8cm5WDfHQ="; publicKey = "PLdgsizztddri0LYtjuNHr5r2E8D+yI+gM8cm5WDfHQ=";
externalIp = "91.121.177.163"; externalIp = "37.187.146.15";
}; };
# "Clients" # "Clients"