diff --git a/flake.nix b/flake.nix index 6b02763..a09ffdd 100644 --- a/flake.nix +++ b/flake.nix @@ -326,6 +326,51 @@ diskSize = "auto"; }; + # USB-bootable Sintra image with DISTINCT partition labels + # (nixos-usb / ESP-USB) so the stick can be booted on a Sintra whose + # eMMC already holds a nixos/ESP-labelled install without a by-label + # collision — stage-1 would otherwise race between the two roots and + # likely mount the eMMC. Auto-upgrade is disabled: this is a portable + # test / hand-off image, not a managed fleet member, and disabling it + # also removes the scheduled bootloader writes that could otherwise + # land on the eMMC's ESP. + disk-image-sintra-usb = + let + cfg = self.nixosConfigurations.sintra-installed.extendModules { + modules = [ + ({ lib, ... }: { + fileSystems."/".device = lib.mkForce "/dev/disk/by-label/nixos-usb"; + fileSystems."/boot".device = lib.mkForce "/dev/disk/by-label/ESP-USB"; + system.autoUpgrade.enable = lib.mkForce false; + }) + ]; + }; + baseImage = import (nixpkgs + "/nixos/lib/make-disk-image.nix") { + inherit pkgs lib; + config = cfg.config; + format = "raw"; + partitionTableType = "efi"; + diskSize = "auto"; + label = "nixos-usb"; # ext4 root label (make-disk-image -L) + }; + in + pkgs.runCommand "nixos-disk-image-sintra-usb" + { nativeBuildInputs = [ pkgs.parted pkgs.mtools ]; } + '' + mkdir -p $out + cp --sparse=always ${baseImage}/nixos.img $out/nixos.img + chmod +w $out/nixos.img + # make-disk-image hardcodes the ESP FAT label to "ESP"; relabel the + # volume to ESP-USB so /boot (by-label/ESP-USB) doesn't collide with + # the eMMC's ESP. Volume label only — bootloader files are untouched, + # and UEFI loads /EFI/BOOT/BOOTX64.EFI regardless of the label. + espStart=$(parted -sm "$out/nixos.img" unit B print | awk -F: '$1==1 {gsub("B","",$2); print $2}') + echo "ESP partition starts at byte $espStart — relabelling to ESP-USB" + export MTOOLS_SKIP_CHECK=1 + mlabel -i "$out/nixos.img@@$espStart" ::ESP-USB + printf 'verify ESP label: '; mlabel -i "$out/nixos.img@@$espStart" -s :: || true + ''; + # Backwards compat iso = self.nixosConfigurations.douro.config.system.build.isoImage; };