systemd-boot-builder.py: fix crash, clean up code#156798
systemd-boot-builder.py: fix crash, clean up code#156798m-bdf wants to merge 6 commits intoNixOS:masterfrom
Conversation
edrex
left a comment
There was a problem hiding this comment.
I spent ~30 minutes reading through these changes, and no issues jumped out. Overall it's a huge improvement in code quality. The test suite over at nixos/tests/systemd-boot.nix still seems to pass (if I ran it correctly).
|
also CC @danielfullmer who wrote the tests, @Enzime who authored and @pennae who reviewed #150408 |
|
EDIT: My mistake I didn’t see the other commits Can you write a test case for the specific crash this fixes? To anyone who wants to review this, I would click on the commits tab and look at them individually |
|
+1 that #155054 (comment) should be reverted before this is merged |
|
I also did not saw any concerns when reading the code. But maybe address @edrex comment from above. |
|
I also looked through these changes and they are looking good to me. This should fix #159623. Can I help to speed this up? (I am currently affected by this and am "motivated" :/ ) There are some tests for the systemd-boot setting in nixpkgs/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py Lines 220 to 230 in e2be5dc |
|
@lucc AFAIK this doesn't have a fix for #159623, which is a regression from ce8c102. Reverting that change should fix the error reporting, revealing the underlying error (in my case it was ENOSPACE, indicating my boot partition was full). Since this branch hasn't been rebased since that was merged, there would be a merge conflict i guess. |
|
Since ce8c102 has been backported to 21.11, I think that should be reverted in a separate commit before this is merged, and then that commit can be backported. @m-bdf do you want to rebase prepending a revert commit since this seems ready to merge otherwise? |
737d615 to
1316910
Compare
|
Resolved the merge conflict and force-pushed. Can confirm this PR solves #15962 for me (i. e. garbled error messages). I think we should either merge this or revert the regression quickly, as this is a pretty non-obvious pitfall and risks people inadventingly booting into old generations. |
|
Thanks everyone for taking the time to review this PR 💕 @edrex for some reasons I won't explain here, I've been working on a NixOS live USB for a few days already, and trying to clone the nixpkgs repo (unsurprisingly) freezes the entire system, so I haven't been able to revert ce8c102 yet. In the meantime, @sternenseemann rebased this PR on master, making it mergeable as-is by resolving the conflict in the first commit instead of prepending a proper revert commit. Thus, do you think backporting 7c21a5f (or even this entire PR) would be reasonable? |
|
sorry slow response, some time AFK
It seems like just backporting the regression fix would have the smallest impact, but I'm new here so not sure what the guidelines are for backporting. I feel like a fix should definitely be backported since the regression was. Also, didn't mean to steamroll @Enzime's request:
At least characterizing the crash seems like good process. |
|
I also think we should only backport a fix and not the whole refactoring part of this pr. |
FRidh
left a comment
There was a problem hiding this comment.
Paths shouldn't be represented anymore as strings but as pathlib.Path objects.
| from shutil import copyfile | ||
| from ctypes import CDLL | ||
|
|
||
| syncfs = CDLL("libc.so.6").syncfs |
There was a problem hiding this comment.
how is libc.so.6 found? Should we hardcode a path?
| import errno | ||
| import subprocess | ||
|
|
||
| from argparse import ArgumentParser |
There was a problem hiding this comment.
please avoid from imports so it is clear directly in code where something comes from.
|
|
||
|
|
||
| def profile_path(profile: Optional[str]) -> str: | ||
| return "/nix/var/nix/profiles/" + (f"system-profiles/{profile}" if profile else "system") |
There was a problem hiding this comment.
Avoid string concatenation when the strings represent paths. Instead, use pathlib and the / operator.
|
|
||
| def system_dir(gen: SystemIdentifier) -> str: | ||
| generation_dir = f"{profile_path(gen.profile)}-{gen.generation}-link" | ||
| return f"{generation_dir}/specialisation/{gen.specialisation}" if gen.specialisation else generation_dir |
There was a problem hiding this comment.
For clarity I would
| return f"{generation_dir}/specialisation/{gen.specialisation}" if gen.specialisation else generation_dir | |
| specialisation_dir = f"{generation_dir}/specialisation/{gen.specialisation}" | |
| return specialisation_dir if gen.specialisation else generation_dir |
Also, pathlib.
|
Thanks for your review @FRidh! I'm working on the changes you've suggested, using |
Motivation for this change
Fix a crash introduced in e2be5dc and clean up the code to improve coding style consistency, match Python 3 best practices and make the script more readable and easy to maintain overall.
Followed PyLint's advice, which now rates the file 10.00/10 with these reports disabled:
(changes are grouped, so per-commit diffs are a lot clearer than the PR's unified one)
Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes