ceph: patch getopt path at build time#440224
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR patches the getopt path directly into Ceph's shell scripts during package build time, eliminating the dependency on the NixOS module to provide getopt via systemd's path.
- Adds getopt as a build dependency to the Ceph package
- Patches shell scripts to use absolute paths to getopt binary
- Removes getopt from the systemd service path in the NixOS module
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkgs/tools/filesystems/ceph/default.nix | Adds getopt dependency and patches shell scripts with absolute getopt paths |
| nixos/modules/services/network-filesystems/ceph.nix | Removes getopt from systemd service path since it's now hardcoded in scripts |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| substituteInPlace \ | ||
| src/ceph-osd-prestart.sh \ | ||
| src/ceph-post-file.in \ | ||
| src/init-ceph.in \ | ||
| --replace-fail "GETOPT=/usr/local/bin/getopt" "GETOPT=${getopt}/bin/getopt" \ | ||
| --replace-fail "GETOPT=getopt" "GETOPT=${getopt}/bin/getopt" | ||
|
|
There was a problem hiding this comment.
[nitpick] The substituteInPlace command spans multiple files and replacements. Consider splitting this into separate commands for each file or group of related files to improve readability and make it easier to debug if one of the files doesn't exist.
| substituteInPlace \ | |
| src/ceph-osd-prestart.sh \ | |
| src/ceph-post-file.in \ | |
| src/init-ceph.in \ | |
| --replace-fail "GETOPT=/usr/local/bin/getopt" "GETOPT=${getopt}/bin/getopt" \ | |
| --replace-fail "GETOPT=getopt" "GETOPT=${getopt}/bin/getopt" | |
| substituteInPlace src/ceph-osd-prestart.sh \ | |
| --replace-fail "GETOPT=/usr/local/bin/getopt" "GETOPT=${getopt}/bin/getopt" \ | |
| --replace-fail "GETOPT=getopt" "GETOPT=${getopt}/bin/getopt" | |
| substituteInPlace src/ceph-post-file.in \ | |
| --replace-fail "GETOPT=/usr/local/bin/getopt" "GETOPT=${getopt}/bin/getopt" \ | |
| --replace-fail "GETOPT=getopt" "GETOPT=${getopt}/bin/getopt" | |
| substituteInPlace src/init-ceph.in \ | |
| --replace-fail "GETOPT=/usr/local/bin/getopt" "GETOPT=${getopt}/bin/getopt" \ | |
| --replace-fail "GETOPT=getopt" "GETOPT=${getopt}/bin/getopt" |
| @@ -503,6 +504,10 @@ rec { | |||
| substituteInPlace src/client/fuse_ll.cc \ | |||
| --replace-fail "mount -i -o remount" "${util-linux}/bin/mount -i -o remount" | |||
|
|
|||
| substituteInPlace src/{ceph-osd-prestart.sh,ceph-post-file.in,init-ceph.in} \ | |||
There was a problem hiding this comment.
@josh Compared to the current state, where getopt is on PATH for all Ceph services, this approach runs the risk of missing programs that use it and getting outdated.
I think if we want to go this way (which has the benefit that Ceph binaries also work standalone, when not running under NixOS systemd services), we should at least have a grep for exhaustiveness in the source repo.
For example:
$ git grep GETOPT=
src/ceph-osd-prestart.sh: GETOPT=/usr/local/bin/getopt
src/ceph-osd-prestart.sh: GETOPT=getopt
src/ceph-post-file.in: GETOPT=/usr/local/bin/getopt
src/ceph-post-file.in: GETOPT=getopt
src/init-ceph.in: GETOPT=/usr/local/bin/getopt
src/init-ceph.in: GETOPT=getopt
src/script/run-make.sh: GETOPT=/usr/local/bin/getopt
src/script/run-make.sh: GETOPT=getopt
src/script/run_tox.sh: GETOPT=/usr/local/bin/getopt
src/script/run_tox.sh: GETOPT=getopt
src/tools/ceph-monstore-update-crush.sh: GETOPT=/usr/local/bin/getopt
src/tools/ceph-monstore-update-crush.sh: GETOPT=getopt
src/tools/setup-virtualenv.sh: GETOPT="/usr/local/bin/getopt"
src/tools/setup-virtualenv.sh: GETOPT=getopt
finds a couple more files (unclear so far if relevant).
There was a problem hiding this comment.
The other scripts were only used at build time and don't exist in the final output. Maybe adding a grep assertion on $out that there are no missed GETOPT=getopt be good? Or should we just patch src more aggressively even for build time scripts?
There was a problem hiding this comment.
Maybe adding a grep assertion on
$outthat there are no missedGETOPT=getoptbe good?
@josh Yes, I think such a grep would be good enough.
|
@nh2 pushed the assertion. Good idea for sure. I assume we might be blocked on merging until #442652 is resolved. This PR's merge base is a little older so it's building fine, but can't test once rebased against @nh2 If you have a chance, any thoughts on #440226? This PR came out while working on that idea. Thanks! |
benaryorg
left a comment
There was a problem hiding this comment.
I'm not personally using the scripts in question (I think), so I can't really test much here, however if the regular tests pass then this LGTM.
| ! grep -R 'GETOPT=getopt' $out | ||
| ! grep -R 'GETOPT=/usr/local/bin/getopt' $out |
There was a problem hiding this comment.
- please use
-Ftoo, not only does it make sure no funny regex stuff happens (in case the string changes in the future), but it also improves speed quite a bit (at least last time I checked) - do we really need
-R? Unless I'm mistaken-rshould suffice since the replaced files are part of the output, not just symlinks. That'd help avoiding to grep any potential linked-in dependencies (again saving some time)
That's mostly nit-picking tho.
|
Tweaked the grep flags as suggested. The primary |
|
nh2
left a comment
There was a problem hiding this comment.
All feedback was addressed, merging.
Tests pass fo rme (but https://discourse.nixos.org/t/path-is-not-in-the-nix-store-during-nixos-rebuild-switch/62719/14 made me extra effort for testing them).
|
@nh2 thank you! |
|
@josh Thank you for the contribution! |
This patches the getopt path directly into Ceph during package build, so that ceph-osd-prestart.sh no longer depends on the NixOS module adding getopt via systemd’s path.
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.