Skip to content

nixos/grub: re-install grub on package change - #1121

Closed
osnyx wants to merge 1 commit into
nixos-26.05from
PL-135147-grub-install-condition
Closed

osnyx wants to merge 1 commit into
nixos-26.05from
PL-135147-grub-install-condition

Conversation

@osnyx

@osnyx osnyx commented Feb 24, 2026 •

Copy link
Copy Markdown
Member

Trigger re-installation of grub files when the store path of the grub package changes.
This is consistent with how side-effects are executed in other parts of NixOS, e.g. systemd service management, and ensures that the actually running grub stays in sync with the grub package in the Nix store that is part of the system closure.
In particular, this causes security patches or dependency changes to be taken into effect without the need to bump the package version.

Background:
So far we only re-installed grub outside of the store when its its version, the package name, or some flags changed.
This leads to the various security patches only fixing new installations of grub and not existing ones. This has been like this for over a decade, but it remains unclear why the implementation decision had been to be overly cautious with modifying boot loader side effects.

Tested:

  • on a grub BIOS system in a qemu VM
  • migration from an old grub state file works
  • checked that grub is re-installed when the package store path changes
  • checked that grub is not re-installed at system switch events with equal package store paths
  • NOT tested on a grubEfi system

Fixes nixpkgs issue 486315

PL-135147

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The nixos-* and nixpkgs-* branches are pushed to by the channel release script and should not be merged into directly.

Please target release-26.05 instead.

@osnyx
osnyx force-pushed the PL-135147-grub-install-condition branch from c202bc8 to 63e57d7 Compare February 24, 2026 15:04
@osnyx

osnyx commented Feb 24, 2026

Copy link
Copy Markdown
Member Author

This draft PR is only filed for an internal revision round. A follow-up PR will be filed against upstream nixpkgs instead.

Trigger re-installation of grub files when the store path of the grub
package changes.
This is consistent with how side-effects are executed in other parts of
NixOS, e.g. systemd service management, and ensures that the actually
running grub stays in sync with the grub package in the Nix store that
is part of the system closure.
In particular, this causes security patches or dependency changes to be
taken into effect without the need to bump the package version.

Impact:
This change causes a re-installation of grub for all systems,
due to the lack of a persisted grub store path in existing state files.

Background:
So far we only re-installed grub outside of the store when its its
version, the package name, or some flags changed.
This leads to the various security patches only fixing new installations
of grub and not existing ones. This has been like this for over a decade,
but it remains unclear why the implementation decision had been to
be overly cautious with modifying boot loader side effects.

Tested:
- on a grub BIOS system in a qemu VM
- migration from an old grub state file works
- checked that grub is re-installed when the package store path changes
- checked that grub is not re-installed at system switch events with
  equal package store paths
- NOT tested on a grubEfi system

Fixes nixpkgs issue 486315

PL-135147
@osnyx
osnyx force-pushed the PL-135147-grub-install-condition branch from 63e57d7 to 71411ed Compare February 24, 2026 15:21

@sysvinit sysvinit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple of small style nits but otherwise looks good.

efiMountPoint => '$',
extraGrubInstallArgs => '@',
grub => '$',
grubEfi => '$',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably better to put the grub and grubEfi arguments before the existing extraGrubInstallArgs, so the latter can still capture a variable number of trailing arguments without needing to wrap them in an arrayref. Compare def func(grub, grubEfi, *extraGrubInstall) in Python.

# because it is read line-by-line.
sub readGrubState {
my $defaultGrubState = GrubState->new(name => "", version => "", efi => "", devices => "", efiMountPoint => "", extraGrubInstallArgs => () );
my $defaultGrubState = GrubState->new(name => "", version => "", efi => "", devices => "", efiMountPoint => "", extraGrubInstallArgs => [], grub => "", grubEfi => "" );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See above, with the reordered args extraGrubInstallArgs can remain an empty list () rather than being an arrayref [].

@osnyx osnyx closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants