at 18.03-beta 24 kB view raw
1{ system ? builtins.currentSystem }: 2 3with import ../lib/testing.nix { inherit system; }; 4with pkgs.lib; 5 6let 7 8 # The configuration to install. 9 makeConfig = { bootLoader, grubVersion, grubDevice, grubIdentifier, grubUseEfi 10 , extraConfig, forceGrubReinstallCount ? 0 11 }: 12 pkgs.writeText "configuration.nix" '' 13 { config, lib, pkgs, modulesPath, ... }: 14 15 { imports = 16 [ ./hardware-configuration.nix 17 <nixpkgs/nixos/modules/testing/test-instrumentation.nix> 18 ]; 19 20 # To ensure that we can rebuild the grub configuration on the nixos-rebuild 21 system.extraDependencies = with pkgs; [ stdenvNoCC ]; 22 23 ${optionalString (bootLoader == "grub") '' 24 boot.loader.grub.version = ${toString grubVersion}; 25 ${optionalString (grubVersion == 1) '' 26 boot.loader.grub.splashImage = null; 27 ''} 28 29 boot.loader.grub.extraConfig = "serial; terminal_output.serial"; 30 ${if grubUseEfi then '' 31 boot.loader.grub.device = "nodev"; 32 boot.loader.grub.efiSupport = true; 33 boot.loader.grub.efiInstallAsRemovable = true; # XXX: needed for OVMF? 34 '' else '' 35 boot.loader.grub.device = "${grubDevice}"; 36 boot.loader.grub.fsIdentifier = "${grubIdentifier}"; 37 ''} 38 39 boot.loader.grub.configurationLimit = 100 + ${toString forceGrubReinstallCount}; 40 ''} 41 42 ${optionalString (bootLoader == "systemd-boot") '' 43 boot.loader.systemd-boot.enable = true; 44 ''} 45 46 users.extraUsers.alice = { 47 isNormalUser = true; 48 home = "/home/alice"; 49 description = "Alice Foobar"; 50 }; 51 52 hardware.enableAllFirmware = lib.mkForce false; 53 54 ${replaceChars ["\n"] ["\n "] extraConfig} 55 } 56 ''; 57 58 59 channelContents = [ pkgs.rlwrap ]; 60 61 62 # The test script boots a NixOS VM, installs NixOS on an empty hard 63 # disk, and then reboot from the hard disk. It's parameterized with 64 # a test script fragment `createPartitions', which must create 65 # partitions and filesystems. 66 testScriptFun = { bootLoader, createPartitions, grubVersion, grubDevice, grubUseEfi 67 , grubIdentifier, preBootCommands, extraConfig 68 }: 69 let 70 iface = if grubVersion == 1 then "ide" else "virtio"; 71 isEfi = bootLoader == "systemd-boot" || (bootLoader == "grub" && grubUseEfi); 72 qemuFlags = 73 (if system == "x86_64-linux" then "-m 768 " else "-m 512 ") + 74 (optionalString (system == "x86_64-linux") "-cpu kvm64 "); 75 hdFlags = ''hda => "vm-state-machine/machine.qcow2", hdaInterface => "${iface}", '' 76 + optionalString isEfi ''bios => "${pkgs.OVMF.fd}/FV/OVMF.fd", ''; 77 in 78 '' 79 $machine->start; 80 81 # Make sure that we get a login prompt etc. 82 $machine->succeed("echo hello"); 83 #$machine->waitForUnit('getty@tty2'); 84 #$machine->waitForUnit("rogue"); 85 $machine->waitForUnit("nixos-manual"); 86 87 # Wait for hard disks to appear in /dev 88 $machine->succeed("udevadm settle"); 89 90 # Partition the disk. 91 ${createPartitions} 92 93 # Create the NixOS configuration. 94 $machine->succeed("nixos-generate-config --root /mnt"); 95 96 $machine->succeed("cat /mnt/etc/nixos/hardware-configuration.nix >&2"); 97 98 $machine->copyFileFromHost( 99 "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; } }", 100 "/mnt/etc/nixos/configuration.nix"); 101 102 # Perform the installation. 103 $machine->succeed("nixos-install < /dev/null >&2"); 104 105 # Do it again to make sure it's idempotent. 106 $machine->succeed("nixos-install < /dev/null >&2"); 107 108 $machine->succeed("umount /mnt/boot || true"); 109 $machine->succeed("umount /mnt"); 110 $machine->succeed("sync"); 111 112 $machine->shutdown; 113 114 # Now see if we can boot the installation. 115 $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "boot-after-install" }); 116 117 # For example to enter LUKS passphrase. 118 ${preBootCommands} 119 120 # Did /boot get mounted? 121 $machine->waitForUnit("local-fs.target"); 122 123 ${if bootLoader == "grub" then 124 ''$machine->succeed("test -e /boot/grub");'' 125 else 126 ''$machine->succeed("test -e /boot/loader/loader.conf");'' 127 } 128 129 # Check whether /root has correct permissions. 130 $machine->succeed("stat -c '%a' /root") =~ /700/ or die; 131 132 # Did the swap device get activated? 133 # uncomment once https://bugs.freedesktop.org/show_bug.cgi?id=86930 is resolved 134 $machine->waitForUnit("swap.target"); 135 $machine->succeed("cat /proc/swaps | grep -q /dev"); 136 137 # Check that the store is in good shape 138 $machine->succeed("nix-store --verify --check-contents >&2"); 139 140 # Check whether the channel works. 141 $machine->succeed("nix-env -iA nixos.procps >&2"); 142 $machine->succeed("type -tP ps | tee /dev/stderr") =~ /.nix-profile/ 143 or die "nix-env failed"; 144 145 # Check that the daemon works, and that non-root users can run builds (this will build a new profile generation through the daemon) 146 $machine->succeed("su alice -l -c 'nix-env -iA nixos.procps' >&2"); 147 148 # We need a writable Nix store on next boot. 149 $machine->copyFileFromHost( 150 "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; forceGrubReinstallCount = 1; } }", 151 "/etc/nixos/configuration.nix"); 152 153 # Check whether nixos-rebuild works. 154 $machine->succeed("nixos-rebuild switch >&2"); 155 156 # Test nixos-option. 157 $machine->succeed("nixos-option boot.initrd.kernelModules | grep virtio_console"); 158 $machine->succeed("nixos-option boot.initrd.kernelModules | grep 'List of modules'"); 159 $machine->succeed("nixos-option boot.initrd.kernelModules | grep qemu-guest.nix"); 160 161 $machine->shutdown; 162 163 # Check whether a writable store build works 164 $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", name => "rebuild-switch" }); 165 ${preBootCommands} 166 $machine->waitForUnit("multi-user.target"); 167 $machine->copyFileFromHost( 168 "${ makeConfig { inherit bootLoader grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; forceGrubReinstallCount = 2; } }", 169 "/etc/nixos/configuration.nix"); 170 $machine->succeed("nixos-rebuild boot >&2"); 171 $machine->shutdown; 172 173 # And just to be sure, check that the machine still boots after 174 # "nixos-rebuild switch". 175 $machine = createMachine({ ${hdFlags} qemuFlags => "${qemuFlags}", "boot-after-rebuild-switch" }); 176 ${preBootCommands} 177 $machine->waitForUnit("network.target"); 178 $machine->shutdown; 179 ''; 180 181 182 makeInstallerTest = name: 183 { createPartitions, preBootCommands ? "", extraConfig ? "" 184 , extraInstallerConfig ? {} 185 , bootLoader ? "grub" # either "grub" or "systemd-boot" 186 , grubVersion ? 2, grubDevice ? "/dev/vda", grubIdentifier ? "uuid", grubUseEfi ? false 187 , enableOCR ? false, meta ? {} 188 }: 189 makeTest { 190 inherit enableOCR; 191 name = "installer-" + name; 192 meta = with pkgs.stdenv.lib.maintainers; { 193 # put global maintainers here, individuals go into makeInstallerTest fkt call 194 maintainers = [ wkennington ] ++ (meta.maintainers or []); 195 }; 196 nodes = { 197 198 # The configuration of the machine used to run "nixos-install". 199 machine = 200 { config, lib, pkgs, ... }: 201 202 { imports = 203 [ ../modules/profiles/installation-device.nix 204 ../modules/profiles/base.nix 205 extraInstallerConfig 206 ]; 207 208 virtualisation.diskSize = 8 * 1024; 209 virtualisation.memorySize = 1024; 210 211 # Use a small /dev/vdb as the root disk for the 212 # installer. This ensures the target disk (/dev/vda) is 213 # the same during and after installation. 214 virtualisation.emptyDiskImages = [ 512 ]; 215 virtualisation.bootDevice = 216 if grubVersion == 1 then "/dev/sdb" else "/dev/vdb"; 217 virtualisation.qemu.diskInterface = 218 if grubVersion == 1 then "scsi" else "virtio"; 219 220 boot.loader.systemd-boot.enable = mkIf (bootLoader == "systemd-boot") true; 221 222 hardware.enableAllFirmware = mkForce false; 223 224 # The test cannot access the network, so any packages we 225 # need must be included in the VM. 226 system.extraDependencies = with pkgs; 227 [ sudo 228 libxml2.bin 229 libxslt.bin 230 docbook5 231 docbook5_xsl 232 unionfs-fuse 233 ntp 234 nixos-artwork.wallpapers.gnome-dark 235 perlPackages.XMLLibXML 236 perlPackages.ListCompare 237 238 # add curl so that rather than seeing the test attempt to download 239 # curl's tarball, we see what it's trying to download 240 curl 241 ] 242 ++ optional (bootLoader == "grub" && grubVersion == 1) pkgs.grub 243 ++ optionals (bootLoader == "grub" && grubVersion == 2) [ pkgs.grub2 pkgs.grub2_efi ]; 244 245 nix.binaryCaches = mkForce [ ]; 246 nix.extraOptions = 247 '' 248 hashed-mirrors = 249 connect-timeout = 1 250 ''; 251 }; 252 253 }; 254 255 testScript = testScriptFun { 256 inherit bootLoader createPartitions preBootCommands 257 grubVersion grubDevice grubIdentifier grubUseEfi extraConfig; 258 }; 259 }; 260 261 262in { 263 264 # !!! `parted mkpart' seems to silently create overlapping partitions. 265 266 267 # The (almost) simplest partitioning scheme: a swap partition and 268 # one big filesystem partition. 269 simple = makeInstallerTest "simple" 270 { createPartitions = 271 '' 272 $machine->succeed( 273 "parted --script /dev/vda mklabel msdos", 274 "parted --script /dev/vda -- mkpart primary linux-swap 1M 1024M", 275 "parted --script /dev/vda -- mkpart primary ext2 1024M -1s", 276 "udevadm settle", 277 "mkswap /dev/vda1 -L swap", 278 "swapon -L swap", 279 "mkfs.ext3 -L nixos /dev/vda2", 280 "mount LABEL=nixos /mnt", 281 ); 282 ''; 283 }; 284 285 # Simple GPT/UEFI configuration using systemd-boot with 3 partitions: ESP, swap & root filesystem 286 simpleUefiSystemdBoot = makeInstallerTest "simpleUefiSystemdBoot" 287 { createPartitions = 288 '' 289 $machine->succeed( 290 "parted --script /dev/vda mklabel gpt", 291 "parted --script /dev/vda -- mkpart ESP fat32 1M 50MiB", # /boot 292 "parted --script /dev/vda -- set 1 boot on", 293 "parted --script /dev/vda -- mkpart primary linux-swap 50MiB 1024MiB", 294 "parted --script /dev/vda -- mkpart primary ext2 1024MiB -1MiB", # / 295 "udevadm settle", 296 "mkswap /dev/vda2 -L swap", 297 "swapon -L swap", 298 "mkfs.ext3 -L nixos /dev/vda3", 299 "mount LABEL=nixos /mnt", 300 "mkfs.vfat -n BOOT /dev/vda1", 301 "mkdir -p /mnt/boot", 302 "mount LABEL=BOOT /mnt/boot", 303 ); 304 ''; 305 bootLoader = "systemd-boot"; 306 }; 307 308 simpleUefiGrub = makeInstallerTest "simpleUefiGrub" 309 { createPartitions = 310 '' 311 $machine->succeed( 312 "parted --script /dev/vda mklabel gpt", 313 "parted --script /dev/vda -- mkpart ESP fat32 1M 50MiB", # /boot 314 "parted --script /dev/vda -- set 1 boot on", 315 "parted --script /dev/vda -- mkpart primary linux-swap 50MiB 1024MiB", 316 "parted --script /dev/vda -- mkpart primary ext2 1024MiB -1MiB", # / 317 "udevadm settle", 318 "mkswap /dev/vda2 -L swap", 319 "swapon -L swap", 320 "mkfs.ext3 -L nixos /dev/vda3", 321 "mount LABEL=nixos /mnt", 322 "mkfs.vfat -n BOOT /dev/vda1", 323 "mkdir -p /mnt/boot", 324 "mount LABEL=BOOT /mnt/boot", 325 ); 326 ''; 327 bootLoader = "grub"; 328 grubUseEfi = true; 329 }; 330 331 # Same as the previous, but now with a separate /boot partition. 332 separateBoot = makeInstallerTest "separateBoot" 333 { createPartitions = 334 '' 335 $machine->succeed( 336 "parted --script /dev/vda mklabel msdos", 337 "parted --script /dev/vda -- mkpart primary ext2 1M 50MB", # /boot 338 "parted --script /dev/vda -- mkpart primary linux-swap 50MB 1024M", 339 "parted --script /dev/vda -- mkpart primary ext2 1024M -1s", # / 340 "udevadm settle", 341 "mkswap /dev/vda2 -L swap", 342 "swapon -L swap", 343 "mkfs.ext3 -L nixos /dev/vda3", 344 "mount LABEL=nixos /mnt", 345 "mkfs.ext3 -L boot /dev/vda1", 346 "mkdir -p /mnt/boot", 347 "mount LABEL=boot /mnt/boot", 348 ); 349 ''; 350 }; 351 352 # Same as the previous, but with fat32 /boot. 353 separateBootFat = makeInstallerTest "separateBootFat" 354 { createPartitions = 355 '' 356 $machine->succeed( 357 "parted --script /dev/vda mklabel msdos", 358 "parted --script /dev/vda -- mkpart primary ext2 1M 50MB", # /boot 359 "parted --script /dev/vda -- mkpart primary linux-swap 50MB 1024M", 360 "parted --script /dev/vda -- mkpart primary ext2 1024M -1s", # / 361 "udevadm settle", 362 "mkswap /dev/vda2 -L swap", 363 "swapon -L swap", 364 "mkfs.ext3 -L nixos /dev/vda3", 365 "mount LABEL=nixos /mnt", 366 "mkfs.vfat -n BOOT /dev/vda1", 367 "mkdir -p /mnt/boot", 368 "mount LABEL=BOOT /mnt/boot", 369 ); 370 ''; 371 }; 372 373 # zfs on / with swap 374 zfsroot = makeInstallerTest "zfs-root" 375 { 376 extraInstallerConfig = { 377 boot.supportedFilesystems = [ "zfs" ]; 378 }; 379 380 extraConfig = '' 381 boot.supportedFilesystems = [ "zfs" ]; 382 383 # Using by-uuid overrides the default of by-id, and is unique 384 # to the qemu disks, as they don't produce by-id paths for 385 # some reason. 386 boot.zfs.devNodes = "/dev/disk/by-uuid/"; 387 networking.hostId = "00000000"; 388 ''; 389 390 createPartitions = 391 '' 392 $machine->succeed( 393 "parted --script /dev/vda mklabel msdos", 394 "parted --script /dev/vda -- mkpart primary linux-swap 1M 1024M", 395 "parted --script /dev/vda -- mkpart primary 1024M -1s", 396 "udevadm settle", 397 398 "mkswap /dev/vda1 -L swap", 399 "swapon -L swap", 400 401 "zpool create rpool /dev/vda2", 402 "zfs create -o mountpoint=legacy rpool/root", 403 "mount -t zfs rpool/root /mnt", 404 405 "udevadm settle" 406 ); 407 ''; 408 }; 409 410 # Create two physical LVM partitions combined into one volume group 411 # that contains the logical swap and root partitions. 412 lvm = makeInstallerTest "lvm" 413 { createPartitions = 414 '' 415 $machine->succeed( 416 "parted --script /dev/vda mklabel msdos", 417 "parted --script /dev/vda -- mkpart primary 1M 2048M", # PV1 418 "parted --script /dev/vda -- set 1 lvm on", 419 "parted --script /dev/vda -- mkpart primary 2048M -1s", # PV2 420 "parted --script /dev/vda -- set 2 lvm on", 421 "udevadm settle", 422 "pvcreate /dev/vda1 /dev/vda2", 423 "vgcreate MyVolGroup /dev/vda1 /dev/vda2", 424 "lvcreate --size 1G --name swap MyVolGroup", 425 "lvcreate --size 2G --name nixos MyVolGroup", 426 "mkswap -f /dev/MyVolGroup/swap -L swap", 427 "swapon -L swap", 428 "mkfs.xfs -L nixos /dev/MyVolGroup/nixos", 429 "mount LABEL=nixos /mnt", 430 ); 431 ''; 432 }; 433 434 # Boot off an encrypted root partition 435 luksroot = makeInstallerTest "luksroot" 436 { createPartitions = '' 437 $machine->succeed( 438 "parted --script /dev/vda mklabel msdos", 439 "parted --script /dev/vda -- mkpart primary ext2 1M 50MB", # /boot 440 "parted --script /dev/vda -- mkpart primary linux-swap 50M 1024M", 441 "parted --script /dev/vda -- mkpart primary 1024M -1s", # LUKS 442 "udevadm settle", 443 "mkswap /dev/vda2 -L swap", 444 "swapon -L swap", 445 "modprobe dm_mod dm_crypt", 446 "echo -n supersecret | cryptsetup luksFormat -q /dev/vda3 -", 447 "echo -n supersecret | cryptsetup luksOpen --key-file - /dev/vda3 cryptroot", 448 "mkfs.ext3 -L nixos /dev/mapper/cryptroot", 449 "mount LABEL=nixos /mnt", 450 "mkfs.ext3 -L boot /dev/vda1", 451 "mkdir -p /mnt/boot", 452 "mount LABEL=boot /mnt/boot", 453 ); 454 ''; 455 extraConfig = '' 456 boot.kernelParams = lib.mkAfter [ "console=tty0" ]; 457 ''; 458 enableOCR = true; 459 preBootCommands = '' 460 $machine->start; 461 $machine->waitForText(qr/Enter passphrase/); 462 $machine->sendChars("supersecret\n"); 463 ''; 464 }; 465 466 # Test whether opening encrypted filesystem with keyfile 467 # Checks for regression of missing cryptsetup, when no luks device without 468 # keyfile is configured 469 filesystemEncryptedWithKeyfile = makeInstallerTest "filesystemEncryptedWithKeyfile" 470 { createPartitions = '' 471 $machine->succeed( 472 "parted --script /dev/vda mklabel msdos", 473 "parted --script /dev/vda -- mkpart primary ext2 1M 50MB", # /boot 474 "parted --script /dev/vda -- mkpart primary linux-swap 50M 1024M", 475 "parted --script /dev/vda -- mkpart primary 1024M 1280M", # LUKS with keyfile 476 "parted --script /dev/vda -- mkpart primary 1280M -1s", 477 "udevadm settle", 478 "mkswap /dev/vda2 -L swap", 479 "swapon -L swap", 480 "mkfs.ext3 -L nixos /dev/vda4", 481 "mount LABEL=nixos /mnt", 482 "mkfs.ext3 -L boot /dev/vda1", 483 "mkdir -p /mnt/boot", 484 "mount LABEL=boot /mnt/boot", 485 "modprobe dm_mod dm_crypt", 486 "echo -n supersecret > /mnt/keyfile", 487 "cryptsetup luksFormat -q /dev/vda3 --key-file /mnt/keyfile", 488 "cryptsetup luksOpen --key-file /mnt/keyfile /dev/vda3 crypt", 489 "mkfs.ext3 -L test /dev/mapper/crypt", 490 "cryptsetup luksClose crypt", 491 "mkdir -p /mnt/test" 492 ); 493 ''; 494 extraConfig = '' 495 fileSystems."/test" = 496 { device = "/dev/disk/by-label/test"; 497 fsType = "ext3"; 498 encrypted.enable = true; 499 encrypted.blkDev = "/dev/vda3"; 500 encrypted.label = "crypt"; 501 encrypted.keyFile = "/mnt-root/keyfile"; 502 }; 503 ''; 504 }; 505 506 507 swraid = makeInstallerTest "swraid" 508 { createPartitions = 509 '' 510 $machine->succeed( 511 "parted --script /dev/vda --" 512 . " mklabel msdos" 513 . " mkpart primary ext2 1M 100MB" # /boot 514 . " mkpart extended 100M -1s" 515 . " mkpart logical 102M 2102M" # md0 (root), first device 516 . " mkpart logical 2103M 4103M" # md0 (root), second device 517 . " mkpart logical 4104M 4360M" # md1 (swap), first device 518 . " mkpart logical 4361M 4617M", # md1 (swap), second device 519 "udevadm settle", 520 "ls -l /dev/vda* >&2", 521 "cat /proc/partitions >&2", 522 "mdadm --create --force /dev/md0 --metadata 1.2 --level=raid1 --raid-devices=2 /dev/vda5 /dev/vda6", 523 "mdadm --create --force /dev/md1 --metadata 1.2 --level=raid1 --raid-devices=2 /dev/vda7 /dev/vda8", 524 "udevadm settle", 525 "mkswap -f /dev/md1 -L swap", 526 "swapon -L swap", 527 "mkfs.ext3 -L nixos /dev/md0", 528 "mount LABEL=nixos /mnt", 529 "mkfs.ext3 -L boot /dev/vda1", 530 "mkdir /mnt/boot", 531 "mount LABEL=boot /mnt/boot", 532 "udevadm settle", 533 ); 534 ''; 535 preBootCommands = '' 536 $machine->start; 537 $machine->fail("dmesg | grep 'immediate safe mode'"); 538 ''; 539 }; 540 541 # Test a basic install using GRUB 1. 542 grub1 = makeInstallerTest "grub1" 543 { createPartitions = 544 '' 545 $machine->succeed( 546 "parted --script /dev/sda mklabel msdos", 547 "parted --script /dev/sda -- mkpart primary linux-swap 1M 1024M", 548 "parted --script /dev/sda -- mkpart primary ext2 1024M -1s", 549 "udevadm settle", 550 "mkswap /dev/sda1 -L swap", 551 "swapon -L swap", 552 "mkfs.ext3 -L nixos /dev/sda2", 553 "mount LABEL=nixos /mnt", 554 ); 555 ''; 556 grubVersion = 1; 557 grubDevice = "/dev/sda"; 558 }; 559 560 # Test using labels to identify volumes in grub 561 simpleLabels = makeInstallerTest "simpleLabels" { 562 createPartitions = '' 563 $machine->succeed( 564 "sgdisk -Z /dev/vda", 565 "sgdisk -n 1:0:+1M -n 2:0:+1G -N 3 -t 1:ef02 -t 2:8200 -t 3:8300 -c 3:root /dev/vda", 566 "mkswap /dev/vda2 -L swap", 567 "swapon -L swap", 568 "mkfs.ext4 -L root /dev/vda3", 569 "mount LABEL=root /mnt", 570 ); 571 ''; 572 grubIdentifier = "label"; 573 }; 574 575 # Test using the provided disk name within grub 576 # TODO: Fix udev so the symlinks are unneeded in /dev/disks 577 simpleProvided = makeInstallerTest "simpleProvided" { 578 createPartitions = '' 579 my $UUID = "\$(blkid -s UUID -o value /dev/vda2)"; 580 $machine->succeed( 581 "sgdisk -Z /dev/vda", 582 "sgdisk -n 1:0:+1M -n 2:0:+100M -n 3:0:+1G -N 4 -t 1:ef02 -t 2:8300 -t 3:8200 -t 4:8300 -c 2:boot -c 4:root /dev/vda", 583 "mkswap /dev/vda3 -L swap", 584 "swapon -L swap", 585 "mkfs.ext4 -L boot /dev/vda2", 586 "mkfs.ext4 -L root /dev/vda4", 587 ); 588 $machine->execute("ln -s ../../vda2 /dev/disk/by-uuid/$UUID"); 589 $machine->execute("ln -s ../../vda4 /dev/disk/by-label/root"); 590 $machine->succeed( 591 "mount /dev/disk/by-label/root /mnt", 592 "mkdir /mnt/boot", 593 "mount /dev/disk/by-uuid/$UUID /mnt/boot" 594 ); 595 ''; 596 grubIdentifier = "provided"; 597 }; 598 599 # Simple btrfs grub testing 600 btrfsSimple = makeInstallerTest "btrfsSimple" { 601 createPartitions = '' 602 $machine->succeed( 603 "sgdisk -Z /dev/vda", 604 "sgdisk -n 1:0:+1M -n 2:0:+1G -N 3 -t 1:ef02 -t 2:8200 -t 3:8300 -c 3:root /dev/vda", 605 "mkswap /dev/vda2 -L swap", 606 "swapon -L swap", 607 "mkfs.btrfs -L root /dev/vda3", 608 "mount LABEL=root /mnt", 609 ); 610 ''; 611 }; 612 613 # Test to see if we can detect /boot and /nix on subvolumes 614 btrfsSubvols = makeInstallerTest "btrfsSubvols" { 615 createPartitions = '' 616 $machine->succeed( 617 "sgdisk -Z /dev/vda", 618 "sgdisk -n 1:0:+1M -n 2:0:+1G -N 3 -t 1:ef02 -t 2:8200 -t 3:8300 -c 3:root /dev/vda", 619 "mkswap /dev/vda2 -L swap", 620 "swapon -L swap", 621 "mkfs.btrfs -L root /dev/vda3", 622 "btrfs device scan", 623 "mount LABEL=root /mnt", 624 "btrfs subvol create /mnt/boot", 625 "btrfs subvol create /mnt/nixos", 626 "btrfs subvol create /mnt/nixos/default", 627 "umount /mnt", 628 "mount -o defaults,subvol=nixos/default LABEL=root /mnt", 629 "mkdir /mnt/boot", 630 "mount -o defaults,subvol=boot LABEL=root /mnt/boot", 631 ); 632 ''; 633 }; 634 635 # Test to see if we can detect default and aux subvolumes correctly 636 btrfsSubvolDefault = makeInstallerTest "btrfsSubvolDefault" { 637 createPartitions = '' 638 $machine->succeed( 639 "sgdisk -Z /dev/vda", 640 "sgdisk -n 1:0:+1M -n 2:0:+1G -N 3 -t 1:ef02 -t 2:8200 -t 3:8300 -c 3:root /dev/vda", 641 "mkswap /dev/vda2 -L swap", 642 "swapon -L swap", 643 "mkfs.btrfs -L root /dev/vda3", 644 "btrfs device scan", 645 "mount LABEL=root /mnt", 646 "btrfs subvol create /mnt/badpath", 647 "btrfs subvol create /mnt/badpath/boot", 648 "btrfs subvol create /mnt/nixos", 649 "btrfs subvol set-default \$(btrfs subvol list /mnt | grep 'nixos' | awk '{print \$2}') /mnt", 650 "umount /mnt", 651 "mount -o defaults LABEL=root /mnt", 652 "mkdir -p /mnt/badpath/boot", # Help ensure the detection mechanism is actually looking up subvolumes 653 "mkdir /mnt/boot", 654 "mount -o defaults,subvol=badpath/boot LABEL=root /mnt/boot", 655 ); 656 ''; 657 }; 658 659}