Skip to content

nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems (v2)#108504

Merged
bjornfor merged 1 commit intoNixOS:masterfrom
bjornfor:fix-build-vm-with-bootloader-with-efi-v2
Jan 8, 2021
Merged

nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems (v2)#108504
bjornfor merged 1 commit intoNixOS:masterfrom
bjornfor:fix-build-vm-with-bootloader-with-efi-v2

Conversation

@bjornfor
Copy link
Copy Markdown
Contributor

@bjornfor bjornfor commented Jan 5, 2021

Motivation for this change

(The first version of this change, in commit 39fad29, broke
nix-build -A nixosTests.installer.simpleUefiSystemdBoot. This is the
2nd version, which hopefully does not break anything.)

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 when needed.

Before:

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

After:

  • Successful build and run.

Fixes #107255

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@bjornfor bjornfor requested review from infinisil and nbp as code owners January 5, 2021 19:32
@bjornfor bjornfor added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Jan 5, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jan 5, 2021
@bjornfor bjornfor force-pushed the fix-build-vm-with-bootloader-with-efi-v2 branch from e2bbceb to 1163445 Compare January 6, 2021 08:55
@SuperSandro2000 SuperSandro2000 requested a review from Mic92 January 6, 2021 13:17
Copy link
Copy Markdown
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add this fix to the flake.nix:

{ virtualisation.useBootLoader = true; }

(The first version of this change, in commit 39fad29, broke
`nix-build -A nixosTests.installer.simpleUefiSystemdBoot`. This is the
2nd version, which hopefully does not break anything.)

`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 when needed.

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

After:
* Successful build and run.

Fixes NixOS#107255
@bjornfor bjornfor force-pushed the fix-build-vm-with-bootloader-with-efi-v2 branch from 1163445 to 0956c50 Compare January 8, 2021 06:58
@bjornfor
Copy link
Copy Markdown
Contributor Author

bjornfor commented Jan 8, 2021

Please also add this fix to the flake.nix:

Done.

Copy link
Copy Markdown
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff LGTM.

@bjornfor bjornfor merged commit 72d906a into NixOS:master Jan 8, 2021
@bjornfor bjornfor deleted the fix-build-vm-with-bootloader-with-efi-v2 branch January 8, 2021 18:36
@bjornfor bjornfor changed the title nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems nixos: fix "nixos-rebuild build-vm-with-bootloader" for EFI systems (v2) Jan 10, 2021
@bjornfor
Copy link
Copy Markdown
Contributor Author

Backported to release-20.09 (9148817) now that the nixos-unstable channel has updated (all tests passed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"nixos-rebuild build-vm-with-booloader" with systemd-boot is broken again

2 participants