Skip to content

ceph: patch getopt path at build time#440224

Merged
nh2 merged 1 commit intoNixOS:masterfrom
josh:ceph-getopt
Oct 25, 2025
Merged

ceph: patch getopt path at build time#440224
nh2 merged 1 commit intoNixOS:masterfrom
josh:ceph-getopt

Conversation

@josh
Copy link
Contributor

@josh josh commented Sep 4, 2025

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

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

Copilot AI review requested due to automatic review settings September 4, 2025 18:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 502 to 508
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"

Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

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

Suggested change
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"

Copilot uses AI. Check for mistakes.
@josh josh requested review from benaryorg and nh2 September 4, 2025 18:42
@nixpkgs-ci nixpkgs-ci bot added 2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 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 Sep 4, 2025
@nix-owners nix-owners bot requested review from adevress, johanot and krav September 4, 2025 18:48
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 4, 2025
@@ -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} \
Copy link
Contributor

Choose a reason for hiding this comment

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

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe adding a grep assertion on $out that there are no missed GETOPT=getopt be good?

@josh Yes, I think such a grep would be good enough.

@josh
Copy link
Contributor Author

josh commented Sep 22, 2025

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

@nh2 If you have a chance, any thoughts on #440226? This PR came out while working on that idea. Thanks!

@josh josh requested a review from nh2 September 26, 2025 18:20
Copy link
Contributor

@benaryorg benaryorg left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 578 to 579
! grep -R 'GETOPT=getopt' $out
! grep -R 'GETOPT=/usr/local/bin/getopt' $out
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. please use -F too, 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)
  2. do we really need -R? Unless I'm mistaken -r should 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.

@josh
Copy link
Contributor Author

josh commented Sep 29, 2025

Tweaked the grep flags as suggested.

The primary ceph-osd-prestart.sh script used by the osd service is the one I encountered. What is nice is that the existing ceph NixOS vm tests excerise this path. I can confirm there will be a test failure there starting a osd if getopt isn’t patched correctly. Thanks to whoever wrote those!

@josh
Copy link
Contributor Author

josh commented Oct 21, 2025

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 440224
Commit: e59c784a9626c70166d94a4664d640978a8bf2f3


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 14 packages built:
  • ceph (ceph-dev)
  • ceph-client
  • ceph-csi
  • ceph.dev (ceph-dev.dev)
  • ceph.doc (ceph-dev.doc)
  • libceph (ceph.lib, libceph.dev, libceph.doc, libceph.lib, libceph.man)
  • ceph.man (ceph-dev.man)
  • qemu_full
  • qemu_full.debug
  • qemu_full.doc
  • qemu_full.ga
  • sambaFull (samba4Full)
  • sambaFull.dev (samba4Full.dev)
  • sambaFull.man (samba4Full.man)

aarch64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 10 packages built:
  • ceph (ceph-dev)
  • ceph-client
  • ceph-csi
  • ceph.dev (ceph-dev.dev)
  • ceph.doc (ceph-dev.doc)
  • libceph (ceph.lib, libceph.dev, libceph.doc, libceph.lib, libceph.man)
  • ceph.man (ceph-dev.man)
  • qemu_full
  • qemu_full.doc
  • qemu_full.ga

Copy link
Contributor

@nh2 nh2 left a comment

Choose a reason for hiding this comment

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

@nh2 nh2 added this pull request to the merge queue Oct 25, 2025
Merged via the queue into NixOS:master with commit 039fab1 Oct 25, 2025
26 of 30 checks passed
@josh josh deleted the ceph-getopt branch October 25, 2025 00:46
@josh
Copy link
Contributor Author

josh commented Oct 25, 2025

@nh2 thank you!

@nh2
Copy link
Contributor

nh2 commented Oct 25, 2025

@josh Thank you for the contribution!

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.

4 participants