Skip to content

nixos/systemd-boot: fix error output#155054

Merged
dasJ merged 1 commit intoNixOS:masterfrom
jonringer:fix-systemd-boot
Jan 23, 2022
Merged

nixos/systemd-boot: fix error output#155054
dasJ merged 1 commit intoNixOS:masterfrom
jonringer:fix-systemd-boot

Conversation

@jonringer
Copy link
Contributor

@jonringer jonringer commented Jan 14, 2022

Motivation for this change

May or may not have borked my build server after /nix/var/nix/db/db.sqlite got corrupted.... and I took a big hammer to it. But stumbled upon this issue.

This should ignore the errors, and just print them. But because profile fell out-of-scope, it becomes a hard error

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-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.05 Release Notes (or backporting 21.11 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.

@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 Jan 14, 2022
@jonringer
Copy link
Contributor Author

cc @jtojnar @grahamc

@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 Jan 14, 2022
@jonringer
Copy link
Contributor Author

For what it's worth, was able to get my system back up and running after using the patch.

@jonringer
Copy link
Contributor Author

For this code path to be hit though, you essentially have to nuke your db.sqlite, then do nix-collect-garbage, then attempt to reinstall

@jonringer
Copy link
Contributor Author

or you could nix-store --delete a generation path

@github-actions
Copy link
Contributor

Successfully created backport PR #156331 for release-21.11.

@m-bdf
Copy link
Contributor

m-bdf commented Jan 26, 2022

This doesn't work as expected, gen is a 3-element tuple so .format(*gen, e) will expand to .format(gen[0], gen[1], gen[2], e). A simple fix would be to either remove the unpack operator (*) so that the full tuple is printed as-is (ugly), or use gen[0] to print only the profile name (cryptic).

That said, the best option is probably to make SystemIdentifier a NamedTuple, which will allow us to use gen.profile, gen.generation and gen.specialisation instead of gen[0], gen[1] and gen[2] respectively. This is exactly the change made by d6354030fa3542a6d604c3206b731f666be36485, proposed in #156798.

@jonringer
Copy link
Contributor Author

This doesn't work as expected, gen is a 3-element tuple so .format(*gen, e) will expand to .format(gen[0], gen[1], gen[2], e). A simple fix would be to either remove the unpack operator (*) so that the full tuple is printed as-is (ugly), or use gen[0] to print only the profile name (cryptic).

That said, the best option is probably to make SystemIdentifier a NamedTuple, which will allow us to use gen.profile, gen.generation and gen.specialisation instead of gen[0], gen[1] and gen[2] respectively. This is exactly the change made by d635403, proposed in #156798.

Yea, currently it looks like:

ignoring generation 'None' in the list of boot entries because of the following error:
1
ignoring generation 'None' in the list of boot entries because of the following error:
2
ignoring generation 'None' in the list of boot entries because of the following error:
3
ignoring generation 'None' in the list of boot entries because of the following error:
4
ignoring generation 'None' in the list of boot entries because of the following error:
5
ignoring generation 'None' in the list of boot entries because of the following error:
6

which hints at gen[0] is always None, and gen[1] is the generation number.

@m-bdf
Copy link
Contributor

m-bdf commented Jan 26, 2022

gen[0] is not always None, it should contain the name of the profile specified with the --profile-name/-p option when the generation was created with nixos-rebuild. gen[0] is None only if the option was not specified and thus the generation was created under the default system profile.

d6354030fa3542a6d604c3206b731f666be36485 handles this case and prints default profile instead of profile 'None'.

Quoting the nixos-rebuild man page:

--profile-name,  -p

Instead of using the Nix profile /nix/var/nix/profiles/system to keep track of the current and previous system configurations, use /nix/var/nix/profiles/system-profiles/name. When you use GRUB 2, for every system profile created with this flag, NixOS will create a submenu named “NixOS - Profile 'name'” in GRUB’s boot menu, containing the current and previous configurations of this profile.

For instance, if you want to test a configuration file named test.nix without affecting the default system profile, you would do:

$ nixos-rebuild switch -p test -I nixos-config=./test.nix

The new configuration will appear in the GRUB 2 submenu “NixOS - Profile 'test'”.

@jonringer
Copy link
Contributor Author

gen[0] is not always None,

Sorry, I meant, its always None in my current case. So it's not really meaningful.

@m-bdf
Copy link
Contributor

m-bdf commented Jan 26, 2022

Oh yes got it, indeed a plain 'None' is not very meaningful, and also the error printed is actually the generation number, which doesn't really help debugging to say the least 😅

What should we do now, revert this commit and merge #156798 (after review of course), or just merge #156798 on top of it after resolving the single-line conflict? Or maybe extract d6354030fa3542a6d604c3206b731f666be36485 from #156798 into another PR to more easily backport this single commit to 21.11 (no clue how and when to backport changes)?

@edrex
Copy link
Contributor

edrex commented Feb 12, 2022

It sounds like y'all already know, but this change masks the underlying OSError (in my case, it was ENOSPACE).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants