Skip to content

nixos/systemd-boot: fix conditional, undefined variable#132688

Closed
cole-h wants to merge 2 commits intoNixOS:masterfrom
DeterminateSystems:systemd-boot-builder
Closed

nixos/systemd-boot: fix conditional, undefined variable#132688
cole-h wants to merge 2 commits intoNixOS:masterfrom
DeterminateSystems:systemd-boot-builder

Conversation

@cole-h
Copy link
Member

@cole-h cole-h commented Aug 4, 2021

Motivation for this change

I was tinkering with systemd-boot-builder.py and noticed these two oddities. See the individual commits for rationale / reasoning.

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/)
  • 21.11 Release Notes (or backporting 21.05 Relase 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
  • Fits CONTRIBUTING.md.

N.B.: I don't actually use profiles, so if somebody who does could test this and report back, that would fantastic...

cole-h added 2 commits August 4, 2021 10:40
Prior to this change, the conditional would always be true for the system
profile because `prof` would contain `"system"`, whereas everywhere else that
considers the system profile uses `None`.
`profile` is undefined at this point; however it is part of the `gen` tuple, so
access it through that. A `None` is converted to the string `"system"` to align
with the conventions of the rest of the script: `None` profiles refer to the
system profile, whereas anything else is some other profile by the specified
name.
@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 Aug 4, 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 Aug 4, 2021
@cole-h cole-h requested review from KaiHa and Mic92 August 5, 2021 15:42
Copy link
Contributor

@KaiHa KaiHa left a comment

Choose a reason for hiding this comment

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

Ran your code on my system. Creating and deleting profiles works fine. Invalid names are reported as expected.

@Thrimbda
Copy link

Thrimbda commented Dec 3, 2021

Any news on this? I just ran into the issue unfortunately- -

~/Work/dotfiles λ sudo /nix/store/mxx255r92fd3mwa8m0b620z1k20fng8m-nixos-system-threenixos-21.11.20211107.c935f5e/bin/switch-to-configuration boot                   master
could not find any previously installed systemd-boot
Traceback (most recent call last):
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 270, in main
    write_entry(*gen, machine_id)
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 116, in write_entry
    kernel = copy_from_profile(profile, generation, specialisation, "kernel")
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 90, in copy_from_profile
    copy_if_not_exists(store_file_path, "/boot%s" % (efi_file_path))
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 25, in copy_if_not_exists
    shutil.copyfile(source, dest)
  File "/nix/store/8dxxjbiyxwkvh53q5kh6nydla2anacgi-python3-3.9.6/lib/python3.9/shutil.py", line 264, in copyfile
    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/h749dg84ly9a9dh6iwjd9y94j0yjcjv3-source/kernel'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 306, in <module>
    main()
  File "/nix/store/9hnwjfz3jwpa4181s4hyqs07p1qksg9a-systemd-boot", line 276, in main
    print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)
UnboundLocalError: local variable 'profile' referenced before assignment

@@ -162,7 +162,8 @@ def remove_old_entries(gens: List[Tuple[Optional[str], int]]) -> None:
else:
prof = "system"
Copy link
Member

Choose a reason for hiding this comment

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

Should we than not just set this to None?

Suggested change
prof = "system"
prof = None

write_loader_conf(*gen)
except OSError as e:
print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)
print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(gen[0] if gen[0] else "system", e), file=sys.stderr)
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
print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(gen[0] if gen[0] else "system", e), file=sys.stderr)
profile = gen[0] or "system"
print("ignoring profile '{}' in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)

Copy link
Contributor

Choose a reason for hiding this comment

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

Related to #155054

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 13, 2022
@bobby285271 bobby285271 added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 13, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 13, 2022
@cole-h cole-h closed this Mar 7, 2023
@cole-h cole-h deleted the systemd-boot-builder branch March 7, 2023 16:59
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: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants