Skip to content

python3Packages.semgrep: fix semgrep-core patchelf and pin mcp - #580821

Closed
pinarruiz wants to merge 1 commit into
NixOS:masterfrom
pinarruiz:fix/semgrep-core-pachelf-mcp
Closed

pinarruiz wants to merge 1 commit into
NixOS:masterfrom
pinarruiz:fix/semgrep-core-pachelf-mcp

Conversation

@pinarruiz

Copy link
Copy Markdown
Contributor

Package semgrep-core failed to build (#579107),

Executing patchelf twice, once per operation, so that the file is reparsed, and pinned mcp to 1.x because semgrep 1.180.0 imports mcp.server.fastmcp.FastMCP, which mcp 2.x renamed.

This is my first PR to nixpkgs, I am not sure if I am making any mistakes, but please let me know.

Resolves #579107

Things done

@nixpkgs-ci nixpkgs-ci Bot added the 12.first-time contribution This PR is the author's first one; please be gentle! label Oct 30, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 6.topic: python Python is a high-level, general-purpose programming language. labels Oct 30, 2026
@ambroisie

Copy link
Copy Markdown
Contributor

Executing patchelf twice, once per operation, so that the file is reparsed

Surprising issue, do you have more visibility into why that is necessary?

@pinarruiz

Copy link
Copy Markdown
Contributor Author

Hi @ambroisie,

The issue is that when patchelf reads the file, it keeps it in memory as an "original", and the two operations happen over this original in memory copy, so the layout shift that will happens with --set-rpath makes the sendond `--set-interpreter'' overlap, or at least that's my understanding hehe

@dotlambda dotlambda left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use python3Packages.overrideScope instead.
EDIT: Never mind, this is not a top-level package. So the only way to fix this is by supporting mcp v2 or pinning mcp in top-level packages that depend on semgrep.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we minimize the diff by keeping the order the same?
Also, use a separate commit for each package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I gave it another go, and figured out what the actual problem was, as i had not a lot of knowledge about how patchelf works, I am not sure if what i made now is "equivalent" to what there was, but it seems to work fine, i had to "move" the ${stdenv.cc.libc}/lib into the $out/bin/libs/ so that the rpath will not take as much room.

Let me know what you think.

@dotlambda dotlambda changed the title semgrep: fix semgrep-core patchelf and pin mcp python3Packages.semgrep: fix semgrep-core patchelf and pin mcp Oct 30, 2026
@pinarruiz
pinarruiz force-pushed the fix/semgrep-core-pachelf-mcp branch 5 times, most recently from 8ac0397 to 9c1bee2 Compare October 30, 2026 21:03
@caverav

caverav commented Oct 30, 2026

Copy link
Copy Markdown
Member

I tested the current PR head (9c1bee2) on x86_64-linux, and the workaround builds successfully.

I also tested the upstream fix from NixOS/patchelf#672. Restoring the original semgrep-core recipe, with a single Patchelf invocation and the original longer RPATH, reproduces the assertion with unpatched Patchelf 0.19.2. Applying only #672's source changes fixes the build without adding the glibc symlinks.

The resulting Semgrep package also passes its Nixpkgs-enabled tests and local Python/JavaScript scan checks. I retained the independent mcp_1 change for this comparison.

I think using the upstream Patchelf fix is the cleaner solution to the ELF issue than adding this package-specific workaround.

@pinarruiz
pinarruiz force-pushed the fix/semgrep-core-pachelf-mcp branch from 9c1bee2 to 47c7e89 Compare November 2, 2026 07:18
@pinarruiz
pinarruiz force-pushed the fix/semgrep-core-pachelf-mcp branch from 47c7e89 to a375315 Compare November 2, 2026 07:18
@pinarruiz

pinarruiz commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

I just created #582116, to update patchelf, once merged i will rebase and we could review this again

siigna added a commit to siigna/nixconfig that referenced this pull request Nov 4, 2026
Fallout from the nixpkgs bump:
- boot.initrd.systemd.enable is now an error: scripted initrd is gone and
  systemd initrd is the only kind, so the line is dropped.
- semgrep 1.180.0 imports mcp.server.fastmcp, renamed in mcp 2.x; build
  it against mcp_1 like NixOS/nixpkgs#580821 does, until that lands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@pinarruiz pinarruiz mentioned this pull request Nov 5, 2026
3 of 13 tasks
@pinarruiz pinarruiz closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure: semgrep-core

4 participants