nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems

`nixos-rebuild build-vm-with-bootloader` currently fails with the
default NixOS EFI configuration:

  $ cat >configuration.nix <<EOF
  {
    fileSystems."/".device = "/dev/sda1";
    boot.loader.systemd-boot.enable = true;
    boot.loader.efi.canTouchEfiVariables = true;
  }
  EOF

  $ nixos-rebuild build-vm-with-bootloader -I nixos-config=$PWD/configuration.nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-20.09.tar.gz
  [...]
  insmod: ERROR: could not insert module /nix/store/1ibmgfr13r8b6xyn4f0wj115819f359c-linux-5.4.83/lib/modules/5.4.83/kernel/fs/efivarfs/efivarfs.ko.xz: No such device
  mount: /sys/firmware/efi/efivars: mount point does not exist.
  [    1.908328] reboot: Power down
  builder for '/nix/store/dx2ycclyknvibrskwmii42sgyalagjxa-nixos-boot-disk.drv' failed with exit code 32
  [...]

Fix it by setting virtualisation.useEFIBoot = true in qemu-vm.nix, when
efi is needed.

And remove the now unneeded configuration in
./nixos/tests/systemd-boot.nix, since it's handled globally.

Before:
* release-20.03: successful build, unsuccessful run
* release-20.09 (and master): unsuccessful build

After:
* Successful build and run.

Fixes https://github.com/NixOS/nixpkgs/issues/107255
This commit is contained in:
Bjørn Forsman 2020-12-20 20:04:15 +01:00
parent b1499452b8
commit 39fad297fd
2 changed files with 4 additions and 1 deletions

View File

@ -605,6 +605,10 @@ in
virtualisation.bootDevice = mkDefault (driveDeviceName 1); virtualisation.bootDevice = mkDefault (driveDeviceName 1);
virtualisation.useEFIBoot = mkDefault
(config.boot.loader.systemd-boot.enable ||
config.boot.loader.efi.canTouchEfiVariables);
virtualisation.pathsInNixDB = [ config.system.build.toplevel ]; virtualisation.pathsInNixDB = [ config.system.build.toplevel ];
# FIXME: Consolidate this one day. # FIXME: Consolidate this one day.

View File

@ -9,7 +9,6 @@ with pkgs.lib;
let let
common = { common = {
virtualisation.useBootLoader = true; virtualisation.useBootLoader = true;
virtualisation.useEFIBoot = true;
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
environment.systemPackages = [ pkgs.efibootmgr ]; environment.systemPackages = [ pkgs.efibootmgr ];