NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.63k stars 13.78k forks source link

Darwin: codesign_allocate not found #148189

Open Smaug123 opened 2 years ago

Smaug123 commented 2 years ago

Describe the bug

A build of the Lean4 flake (https://github.com/leanprover/lean4/pull/838/commits/0df78cf801e2e6950c78e57825244e1d0b289a8e) fails with:

> ld: warning: directory not found for option '-L/nix/store/smpng2rrp1dfnik729h4gg917mm0y4ws-leanc/lib/lean'
> libc++abi: terminating with uncaught exception of type std::runtime_error: Failed to spawn codesign_allocate: No such file or directory
       > /nix/store/apxhw055i0z86i3m27xn81w0qg2ssp1q-post-link-sign-hook: line 2: 50824 Abort trap: 6           CODESIGN_ALLOCATE=codesign_allocate /nix/store/hr987fj9ib6v70mmi9jiw5iykkc0zi2f-sigtool-0.1.2/bin/codesign -f -s - "$linkerOutput"

Steps To Reproduce

Steps to reproduce the behaviour on Darwin, macOS Monterey, no developer tools installed, nix 2.4 (Nix is set up as in https://github.com/Smaug123/nix-dotfiles/commit/13e0ea2511e78e0172526c8bc391b6b3f8976f49):

  1. git clone https://github.com/leanprover/lean4 && git checkout 0df78cf801e2e6950c78e57825244e1d0b289a8e
  2. nix build

Expected behavior

The Lean4 build completes successfully and signs the resulting binaries.

Actual behaviour

The Lean4 build completes successfully, but code signing fails.

Additional context

I believe the cause of the problem is https://github.com/NixOS/nixpkgs/blob/283d622397539f196416657da9dc804a4ca89846/pkgs/top-level/darwin-packages.nix#L124, which I believe is referring to an ambient codesign_allocate rather than one obtained from cctools. I attempted a fix (https://github.com/NixOS/nixpkgs/compare/master...Smaug123:aarch-signing-2) but my Nix knowledge isn't good enough to get it right.

Notify maintainers

@matthewbauer @thefloweringash @Ericson2314

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

nix-shell -p nix-info --run "nix-info -m"                                                                                                                                                                    ~/Documents/GitHub/nixpkgs
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.1.0, macOS 12.0.1`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4`
 - channels(patrick): `"darwin, home-manager"`
 - channels(root): `"nixpkgs-22.05pre334335.9c191ebcdfe"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
jmgilman commented 2 years ago

Very (very) novice Nix user who was just trying to learn through the Nix Pills series but I ended up running into this exact error when trying to build the sample C program included in Pill #7.

error: builder for '/nix/store/r3xdz1s0jkrlvabi3q2j9a0lrjliwk1i-simple.drv' failed with exit code 1;
       last 10 log lines:
       > /nix/store/9sll05wmn9b05f0pm1pwfmmq92fg0syh-simple.c: In function 'main':
       > /nix/store/9sll05wmn9b05f0pm1pwfmmq92fg0syh-simple.c:2:3: warning: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
       >     2 |   puts("Simple!");
       >       |   ^~~~
       > /nix/store/9sll05wmn9b05f0pm1pwfmmq92fg0syh-simple.c:1:1: note: include '<stdio.h>' or provide a declaration of 'puts'
       >   +++ |+#include <stdio.h>
       >     1 | void main() {
       > libc++abi: terminating with uncaught exception of type std::runtime_error: Failed to spawn codesign_allocate: No such file or directory
       > /nix/store/7000rh8ksvy4g3fcn563l0pad883iqdq-post-link-sign-hook: line 2: 33532 Abort trap: 6           CODESIGN_ALLOCATE=codesign_allocate /nix/store/cvbl5h2kvznizbc668rirn2q377jlw41-sigtool-0.1.2/bin/codesign -f -s - "$linkerOutput"
       > collect2: error: ld returned 134 exit status
       For full logs, run 'nix log /nix/store/r3xdz1s0jkrlvabi3q2j9a0lrjliwk1i-simple.drv'.
alexandrustana commented 2 years ago

@jmgilman This isn't quite the fix you might expect but at least it will enable you to run the simple example. In Pill #8 the author creates another derivation, but this time he points out that there are some differences when you try running the example on darwin.

To build the derivation you need to change the PATH variable to look like this: export PATH="$coreutils/bin:$clang/bin:$binutils/bin" And when building the derivation in the nix repl you need to have the following values set: clang = clang; coreutils = coreutils; binutils = clang.bintools.bintools_bin

I'm sorry in advance if this is not the place for this sort of comment.