Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for VMs that use efi sysmount #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions nixos-infect
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -338,7 +360,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

Expand Down Expand Up @@ -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
}
Expand Down