From 5dbf3d676ff3a7a33da1c367cbd94925472a784d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 17 Jun 2024 14:41:12 +0200 Subject: [PATCH 1/2] Follow redirects when curling config This is required when eg the config is stored in a gist --- nixos-infect | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-infect b/nixos-infect index 06f0171..61113a4 100644 --- a/nixos-infect +++ b/nixos-infect @@ -338,7 +338,7 @@ infect() { if [[ $NIXOS_CONFIG = http* ]] then - curl $NIXOS_CONFIG -o /etc/nixos/configuration.nix + curl -L $NIXOS_CONFIG -o /etc/nixos/configuration.nix unset NIXOS_CONFIG fi From 1261e34cd959edf3d733d31227d36df2cb1075af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Mon, 17 Jun 2024 14:30:34 +0200 Subject: [PATCH 2/2] Add support for VMs that use efi sysmount --- nixos-infect | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/nixos-infect b/nixos-infect index 61113a4..590b4ff 100644 --- a/nixos-infect +++ b/nixos-infect @@ -56,15 +56,30 @@ makeConf() { EOF if isEFI; then - bootcfg=$(cat << EOF + if [[ $bootFs == /boot ]]; then + bootcfg=$(cat << EOF boot.loader.grub = { efiSupport = true; efiInstallAsRemovable = true; device = "nodev"; }; - fileSystems."/boot" = { device = "$esp"; fsType = "vfat"; }; + fileSystems."$bootFs" = { device = "$esp"; fsType = "vfat"; }; EOF ) + else + bootcfg=$(cat << EOF + boot.loader = { + efi.efiSysMountPoint = "/boot/efi"; + grub = { + efiSupport = true; + efiInstallAsRemovable = true; + device = "nodev"; + }; + }; + fileSystems."$bootFs" = { device = "$esp"; fsType = "vfat"; }; +EOF +) + fi else bootcfg=$(cat << EOF boot.loader.grub.device = "$grubdev"; @@ -234,6 +249,13 @@ prepareEnv() { # $esp and $grubdev are used in makeConf() if isEFI; then esp="$(findESP)" + if mount | grep -q /boot/efi; then + bootFs=/boot/efi + elif mount | grep -q /boot/EFI; then + bootFs=/boot/EFI + else + bootFs=/boot + fi else for grubdev in /dev/vda /dev/sda /dev/xvda /dev/nvme0n1 ; do [[ -e $grubdev ]] && break; done fi @@ -370,14 +392,14 @@ infect() { echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE (cd / && ls etc/ssh/ssh_host_*_key* || true) >> /etc/NIXOS_LUSTRATE - rm -rf /boot.bak + rm -rf $bootFs.bak isEFI && umount "$esp" - mv -v /boot /boot.bak || { cp -a /boot /boot.bak ; rm -rf /boot/* ; umount /boot ; } + mv -v $bootFs $bootFs.bak || { cp -a $bootFs $bootFs.bak ; rm -rf $bootFs/* ; umount $bootFs ; } if isEFI; then - mkdir -p /boot - mount "$esp" /boot - find /boot -depth ! -path /boot -exec rm -rf {} + + mkdir -p $bootFs + mount "$esp" $bootFs + find $bootFs -depth ! -path $bootFs -exec rm -rf {} + fi /nix/var/nix/profiles/system/bin/switch-to-configuration boot }