Skip to content

Commit

Permalink
nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems
Browse files Browse the repository at this point in the history
`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 #107255
  • Loading branch information
bjornfor committed Dec 21, 2020
1 parent b149945 commit 39fad29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ in

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 ];

# FIXME: Consolidate this one day.
Expand Down
1 change: 0 additions & 1 deletion nixos/tests/systemd-boot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ with pkgs.lib;
let
common = {
virtualisation.useBootLoader = true;
virtualisation.useEFIBoot = true;
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
environment.systemPackages = [ pkgs.efibootmgr ];
Expand Down

0 comments on commit 39fad29

Please sign in to comment.