Skip to content

nixos/generations-dir: Improve symlinking in /boot#198728

Open
Majiir wants to merge 3 commits intoNixOS:masterfrom
Majiir:generationsdir-improvements
Open

nixos/generations-dir: Improve symlinking in /boot#198728
Majiir wants to merge 3 commits intoNixOS:masterfrom
Majiir:generationsdir-improvements

Conversation

@Majiir
Copy link
Contributor

@Majiir Majiir commented Oct 30, 2022

Description of changes

boot.loader.generationsDir is a simple "boot loader" that creates a directory structure in /boot with symlinks to kernel, initrd, init, and system. This is ideal for some boot loaders (e.g. old or anemic builds of U-Boot) that don't otherwise support a menu of system profiles at boot.

  • f7ccb384323830c3af2b7032b6558a46f4cacc0c fixes an issue where those symlinks are broken when /boot has its own partition.
  • 15d56abf52a9a404c97744fc25b917f1ce72e243 makes it easier to change the default boot profile by re-pointing the default symlink.
  • 9ee1a4b60994514fff2538dc8c6840b232835674 adds an option to suppress the redundant copying of kernel, initrd and init files.
  • 69cdd9fb5e9632f88a8aff5788b03fb7cccc600a changes the default for that option to false.

I tested this on an armv7l-linux system which has a U-Boot build from 2011 that lacks support for extlinux.conf. In particular, I tested that:

  • U-Boot can follow the double symlinks for the default profile.
  • NixOS cleanly updates /boot when upgrading to this branch.
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • armv7l-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@Majiir Majiir requested a review from dasJ as a code owner October 30, 2022 22:34
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Oct 30, 2022
@Majiir Majiir force-pushed the generationsdir-improvements branch 2 times, most recently from 679e0de to 7a97352 Compare October 30, 2022 22:43
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Oct 30, 2022
@bjornfor bjornfor requested a review from samueldr October 31, 2022 08:52
@Majiir Majiir force-pushed the generationsdir-improvements branch from 7a97352 to 0015892 Compare November 1, 2022 18:14
@Majiir Majiir requested a review from ncfavier November 1, 2022 18:15
Copy link
Member

@ncfavier ncfavier left a comment

Choose a reason for hiding this comment

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

Code LGTM, not sure how to test so I'll wait for others.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/1398

@Majiir Majiir force-pushed the generationsdir-improvements branch from 444ed6a to 69cdd9f Compare November 14, 2022 02:00
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/1635

@Majiir
Copy link
Contributor Author

Majiir commented Jul 16, 2023

Rebased and updated the stateVersion check. Still looking for a review/merge.

@RaitoBezarius
Copy link
Member

Please wait some days so that I have time to review this properly.

@Majiir
Copy link
Contributor Author

Majiir commented Aug 16, 2023

@RaitoBezarius Have you had a chance to look this over? Anything that can be improved? Thanks.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-in-distress/3604/70

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

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

This PR makes sense to me, given the use case that @Majiir lays out in the description, and certainly seems no worse than the current implementation.

@RaitoBezarius
Copy link
Member

It slipped my mind… I will review it ASAP.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default = versionOlder config.system.stateVersion "23.11";
default = versionOlder config.system.stateVersion "24.05";

no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the stateVersion

Copy link
Member

@RaitoBezarius RaitoBezarius left a comment

Choose a reason for hiding this comment

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

LGTM, sorry for the delay, we can proceed once you fix the state version.

@Majiir Majiir force-pushed the generationsdir-improvements branch from a25c3f6 to d8a7435 Compare February 18, 2024 17:19
@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two persons. label Mar 9, 2024
@Majiir Majiir force-pushed the generationsdir-improvements branch from d8a7435 to a8ae946 Compare May 23, 2024 17:39
@Majiir
Copy link
Contributor Author

Majiir commented May 23, 2024

  • Rebased on latest master.
  • Removed mdDoc usages.

@philiptaron
Copy link
Contributor

I'm planning on merging this after retesting it later today. Any objections, please speak now.

Comment on lines 51 to 54
Copy link
Member

Choose a reason for hiding this comment

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

This should be 25.05. Looks good otherwise

Copy link
Contributor

@K900 K900 left a comment

Choose a reason for hiding this comment

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

This is not how stateVersion is meant to be used.

@Majiir
Copy link
Contributor Author

Majiir commented Dec 5, 2024

This is not how stateVersion is meant to be used.

nixos/README.md says:

  • Ensure that option changes are backward compatible.
    ...
  • Use lib.versionAtLeast config.system.stateVersion "24.05" on backward incompatible changes which may corrupt, change or update the state stored on existing setups.

I get that "state" was meant for handling things like Postgres upgrades, but there are plenty of stateVersion checks in nixpkgs that are using it to change a default option value without breaking existing users.

Since this change could break boot, we shouldn't quietly change behavior on users. But the existing behavior is not a good default.

If not stateVersion, then what would you suggest?

@philiptaron
Copy link
Contributor

I'm planning on merging this after retesting it later today. Any objections, please speak now.

Wow, my timer did not go off.

@Majiir
Copy link
Contributor Author

Majiir commented Dec 5, 2024

Wow, my timer did not go off.

🥲 If you look upthread, you'll find you weren't even the first! This is my personal best example of PRs that get nitpicked and delayed. stateVersion went stale three times. But the core change is good, right?

I would remove the stateVersion change to unstick things, but we need @K900 to unblock it in any case, so I think we need an answer first.

@K900
Copy link
Contributor

K900 commented Dec 5, 2024

Keep the old behavior, add a warning that it's deprecated, drop it entirely next release?

@Majiir Majiir force-pushed the generationsdir-improvements branch from a8ae946 to dc60840 Compare December 7, 2024 15:17
@Majiir
Copy link
Contributor Author

Majiir commented Dec 7, 2024

  • Rebased on latest master.
  • Dropped the last commit (with the stateVersion check) for now.

philiptaron
philiptaron previously approved these changes Dec 7, 2024
@Majiir Majiir requested a review from K900 December 11, 2024 03:49
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels very dangerous. Maybe at least log a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The delete is required. If $defaultdir is not deleted, then the following ln would error out with ln: default: cannot overwrite directory.

Further up, there is an unconditional rm -Rf /boot/system*. The updates are already destructive and not atomic. Improvements in those areas would be nice, but is it a blocker?

Is the concern that users are storing files in /boot/default other than those created by generationsDir? If so, then what kind of warning would help? At this point in the script, we either finish setting up /boot or the user is left with an unbootable system.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's always hard to tell what is in scope of the bootloader script. IMO if there's an existing directory that contains anything but the files we're about to put there, we should just abort.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 15, 2025
Majiir added 3 commits April 21, 2025 21:25
When /boot is on a separate partition, absolute symlinks can break boot
loaders that assume the partition is mounted at /. For example, U-Boot's
ext2load command follows the relative symlinks correctly but fails to
follow the absolute symlink.
This makes it easier to quickly change the default boot profile. The
contents of the 'default' directory are already symlinks, so anything
that can follow symlinks currently should continue to do so.
Adds an option to suppress the second full copy of the default profile
files (kernel, initrd, init) made in /boot.
@Majiir Majiir force-pushed the generationsdir-improvements branch from dc60840 to 0fd9962 Compare April 22, 2025 01:30
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 22, 2025
@philiptaron philiptaron dismissed their stale review June 5, 2025 23:25

Looking to @K900 to either say yay or nay or recuse.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants