fix(darwin): handle code signatures for CA derivations#14999
Draft
andrewgazelka wants to merge 3 commits intoNixOS:masterfrom
Draft
fix(darwin): handle code signatures for CA derivations#14999andrewgazelka wants to merge 3 commits intoNixOS:masterfrom
andrewgazelka wants to merge 3 commits intoNixOS:masterfrom
Conversation
On macOS, content-addressed (CA) derivations fail because Nix's hash rewriting invalidates Mach-O code signatures, causing the kernel to kill binaries with SIGKILL (Code Signature Invalid). This commit implements the fix proposed in issue NixOS#6065: 1. Before computing the CA hash, zero out LC_CODE_SIGNATURE sections in Mach-O binaries (similar to how self-references are handled) 2. After moving outputs to their final CA location, re-sign binaries with ad-hoc signatures using codesign This allows CA derivations to work on Apple Silicon Macs without requiring SIP to be disabled. UNTESTED: This is a draft implementation that compiles but has not been tested with actual CA builds. Feedback welcome. Fixes: NixOS#6065
CA derivations have integrity guaranteed by content hash, so the ownership check (which verifies current build user owns output) is unnecessary and causes failures when outputs built by one nixbld user are reused by another. Permission check (group/world writable) still applies to prevent tampering.
…hing The previous approach zeroed signature bytes in-place, corrupting the signature structure. This made re-signing impossible with error: 'invalid or unsupported format for signature' Using codesign --remove-signature properly removes the LC_CODE_SIGNATURE load command and truncates the signature blob, allowing clean re-signing after hash computation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
!!!!! claude code
will test later. do not trust code works just putting this out here as a potential fix in case anyone is interested. will test later to see if works.
On macOS, content-addressed (CA) derivations fail because Nix's hash rewriting invalidates Mach-O code signatures, causing the kernel to kill binaries with
SIGKILL (Code Signature Invalid).This PR implements the fix proposed in #6065:
LC_CODE_SIGNATUREsections in Mach-O binaries (similar to how self-references are already handled withHashModuloSink)codesign -f -s -Files changed
darwin-codesign.cc/hh: New utilities for detecting Mach-O binaries, zeroing code signatures, and re-signingderivation-builder.cc: Integrate signature handling intoregisterOutputs()for CA derivationsThis is a draft implementation that compiles but has not been tested with actual CA builds. I'm submitting this early to get feedback on the approach.
Known limitations
LC_CODE_SIGNATUREin Mach-O binaries, not extended attributes or_CodeSignaturebundles/usr/bin/codesigndirectly (should always be available on macOS)Test plan
Fixes #6065