Skip to content

nixos-rebuild --install-bootloader does not reinstall the bootloader #144007

@anund

Description

@anund

Describe the bug

Contrary to https://nixos.wiki/wiki/Bootloader#Re-installing_the_bootloader adding --install-bootloader to nixos-rebuild... does not reinstall the boot loader.

Steps To Reproduce

Steps to reproduce the behavior:

  1. sudo nixos-rebuild --install-bootloader switch

Expected behavior

nixos-rebuild should print roughly the following

Copied "/nix/store/3s1ygbkri8rc2z39cv53z55z4cqldpwq-systemd-247.6/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/systemd/systemd-bootx64.efi".
Copied "/nix/store/3s1ygbkri8rc2z39cv53z55z4cqldpwq-systemd-247.6/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/BOOT/BOOTX64.EFI".
Random seed file /boot/loader/random-seed successfully written (512 bytes).
Successfully initialized system token in EFI variable with 512 bytes.
Created EFI boot entry "Linux Boot Manager".

Additional context

A change in ~2019 added sudo -- as a prefix to various calls including switch-to-configuration whenever $SUDO_USER is set. This happens for both sudo nixos-rebuild ... and when run as root. (during the build? process sudo_user is set to root)
--install-bootloader relies on exporting NIX_INSTALL_BOOTLOADER to communicate through? switch-to-configuration.pl to systemd-boot-builder.py. sudo -- does not preserve NIX_INSTALL_BOOTLOADER effectively disabling this option.

Notify maintainers

@zimbatm ?

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.66, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.15`
 - channels(<user>): `"home-manager"`
 - channels(root): `"nixos-21.11pre325810.2deb07f3ac4"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: 
# a list of nixos modules affected by the problem
module:

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: nixosIssues or PRs affecting NixOS modules, or package usability issues specific to NixOS
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions