Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.5.0-alpha1: Can't build without codesign on macOS #6226

Closed
anmonteiro opened this issue Oct 13, 2022 · 8 comments · Fixed by #6231 or ocaml/opam-repository#22317
Closed

3.5.0-alpha1: Can't build without codesign on macOS #6226

anmonteiro opened this issue Oct 13, 2022 · 8 comments · Fixed by #6231 or ocaml/opam-repository#22317
Milestone

Comments

@anmonteiro
Copy link
Collaborator

Expected Behavior

Able to build Dune 3.5.0-alpha1 on macOS + Nixpkgs

Actual Behavior

dune> File "_unknown_", line 1, characters 0-0:
dune> Error: Program codesign not found in the tree or in PATH
dune> Hint: codesign should be part of the macOS installation

I tried adding darwin.sigtool but I believe it brings up a password prompt that nix doesn't like.

Reproduction

  • PR with a reproducing test:

Specifications

  • Version of dune (output of dune --version):
  • Version of ocaml (output of ocamlc --version)
  • Operating system (distribution and version):

Additional information

  • Link to gist with verbose output (run dune with the --verbose flag):
@rgrinberg rgrinberg added this to the 3.5.0 milestone Oct 13, 2022
@emillon
Copy link
Collaborator

emillon commented Oct 13, 2022

Hi! Happy that you could find that before the release. I thought that any macos that enforces signing would provide codesign. To confirm - is this a M1 mac? Which version of macos is this? Can you post the output of ocaml -config? Thanks!

@anmonteiro
Copy link
Collaborator Author

anmonteiro commented Oct 13, 2022

This is an m1 mac.

Nix is a hermetic build system which clears the PATH before building, so codesign isn't available, or, when it is, it requires an interactive password prompt which nix doesn't like.

Rudi suggested using a heuristic to detect whether it's a Nix environment, and disable this feature in Dune. I believe Nix already has an automatic signing hook to sign binaries.

These environment variables were available in a random Nix build I tried:

NIX_BUILD_CORES
NIX_PKG_CONFIG_WRAPPER_TARGET_HOST_aarch64_apple_darwin
NIX_ENFORCE_NO_NATIVE
NIX_BINTOOLS
NIX_DONT_SET_RPATH
NIX_SSL_CERT_FILE
NIX_STORE
NIX_ENFORCE_PURITY
NIX_LOG_FD
NIX_DONT_SET_RPATH_FOR_BUILD
NIX_NO_SELF_RPATH
NIX_CC_WRAPPER_TARGET_HOST_aarch64_apple_darwin
NIX_BUILD_TOP
NIX_CFLAGS_COMPILE
NIX_IGNORE_LD_THROUGH_GCC
NIX_CC
NIX_BINTOOLS_WRAPPER_TARGET_HOST_aarch64_apple_darwin
NIX_COREFOUNDATION_RPATH
NIX_INDENT_MAKE
NIX_HARDENING_ENABLE
NIX_LDFLAGS

@emillon
Copy link
Collaborator

emillon commented Oct 13, 2022

I'm afraid a bunch of these will be set for nix users even if nix is not being used in the current build (for example I use nix to install some binaries so I'm sourcing some nix stuff, but I don't use nix to build ocaml code). Maybe some of them are only valid when building.
2 ideas for alternatives:

  • we could check if a binary is correctly signed before resigning them. But as I understand it, this requires spctl which I suppose is not in PATH either.
  • we could not call codesign when it's not in the PATH. Sounds a bit dangerous but might be good enough in practice.

@anmonteiro
Copy link
Collaborator Author

I don't believe that's the case. I also use a nix profile, and my environment only has these:

$ env | grep NIX_ | awk -F "=" '{print $1}'
NIX_PROFILES
NIX_SSL_CERT_FILE

@anmonteiro
Copy link
Collaborator Author

we could not call codesign when it's not in the PATH. Sounds a bit dangerous but might be good enough in practice.

perhaps along with a warning that says it tried to invoke codesign and failed.

@emillon
Copy link
Collaborator

emillon commented Oct 13, 2022

Something we could also use is to call codesign only when some substitutions have been performed. That wouldn't solve the problem of supporting substitutions on mac+nix, but at least we'd avoid a regression.

@rgrinberg
Copy link
Member

Another possibility: we could also introduce an env var to disable the code signing. This could be used by nix functions such buildDunePackage that could set this variable.

@emillon
Copy link
Collaborator

emillon commented Oct 14, 2022

I tried on my Debian system where I installed nix and I have NIX_PATH, NIX_PROFILES, and NIX_SSL_CERT_FILE. I'll try to implement the "codesign only if substitutions happened" technique, and otherwise we can try to skip codesign if it's not in path and some nix env var is set. But I don't like that too much, since we're just delaying the problem (we'll probably need to support the case where substitution happens, and codesign (or something else) needs to be provided by nix.

emillon added a commit to emillon/dune that referenced this issue Oct 14, 2022
This ensures that we're not running `codesign` in cases we don't
strictly need it. This in turn prevents a regression in macos+nix, where
the codesign binary is not in PATH.

Closes ocaml#6226

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue Oct 14, 2022
This ensures that we're not running `codesign` in cases we don't
strictly need it. This in turn prevents a regression in macos+nix, where
the codesign binary is not in PATH.

Closes ocaml#6226

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/dune that referenced this issue Oct 17, 2022
This ensures that we're not running `codesign` in cases we don't
strictly need it. This in turn prevents a regression in macos+nix, where
the codesign binary is not in PATH.

Closes ocaml#6226

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this issue Oct 18, 2022
* Only run codesign if there have been substitutions

This ensures that we're not running `codesign` in cases we don't
strictly need it. This in turn prevents a regression in macos+nix, where
the codesign binary is not in PATH.

Closes #6226

Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit to emillon/opam-repository that referenced this issue Oct 19, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.5.0)

CHANGES:

- macOS: Handle unknown fsevents without crashing (ocaml/dune#6217, @rgrinberg)

- Enable file watching on MacOS SDK < 10.13. (ocaml/dune#6218, @rgrinberg)

- Sandbox running cinaps actions starting from cinaps 1.1 (ocaml/dune#6176, @rgrinberg)

- Add a `runtime_deps` field in the `cinaps` stanza to specify runtime
  dependencies for running the cinaps preprocessing action (ocaml/dune#6175, @rgrinberg)

- Shadow alias module `Foo__` when building a library `Foo` (ocaml/dune#6126, @rgrinberg)

- Extend dune describe to include the root path of the workspace and the
  relative path to the build directory. (ocaml/dune#6136, @reubenrowe)

- Allow dune describe workspace to accept directories as arguments.
  The provided directories restrict the worskpace description to those
  directories. (ocaml/dune#6107, fixes ocaml/dune#3893, @esope)

- Add a terminal persistence mode that attempts to clear the terminal history.
  It is enabled by setting terminal persistence to
  `clear-on-rebuild-and-flush-history` (ocaml/dune#6065, @rgrinberg)

- Disallow generating targets in sub direcories in inferred rules. The check to
  forbid this was accidentally done only for manually specified targets (ocaml/dune#6031,
  @rgrinberg)

- Do not ignore rules marked `(promote (until-clean))` when
  `--ignore-promoted-rules` (or `-p`) is passed. (ocaml/dune#6010, fixes ocaml/dune#4401, @emillon)

- Dune no longer considers .aux files as targets during Coq compilation. This
  means that .aux files are no longer cached. (ocaml/dune#6024, fixes ocaml/dune#6004, @Alizter)

- Cinaps actions are now sandboxed by default (ocaml/dune#6062, @rgrinberg)

- Allow rules producing directory targets to be not sandboxed (ocaml/dune#6056,
  @rgrinberg)

- Introduce a `dirs` field in the `install` stanza to install entire
  directories (ocaml/dune#5097, fixes ocaml/dune#5059, @rgrinberg)

- Menhir rules are now sandboxed by default (ocaml/dune#6076, @rgrinberg)

- Allow rules producing directory targets to create symlinks (ocaml/dune#6077, fixes
  ocaml/dune#5945, @rgrinberg)

- Inline tests are now sandboxed by default (ocaml/dune#6079, @rgrinberg)

- Fix build-info version when used with flambda (ocaml/dune#6089, fixes ocaml/dune#6075, @jberdine)

- Add an `(include <file>)` term to the `include_dirs` field for adding
  directories to the include paths sourced from a file. (ocaml/dune#6058, fixes ocaml/dune#3993,
  @gridbugs)

- Support `(extra_objects ...)` field in `(executable ...)` and `(library
  ...)` stanzas (ocaml/dune#6084, fixes ocaml/dune#4129, @gridbugs)

- Fix compilation of Dune under esy on Windows (ocaml/dune#6109, fixes ocaml/dune#6098, @nojb)

- Improve error message when parsing several licenses in `(license)` (ocaml/dune#6114,
  fixes ocaml/dune#6103, @emillon)

- odoc rules now about `ODOC_SYNTAX` and will rerun accordingly (ocaml/dune#6010, fixes
  ocaml/dune#1117, @emillon)

- dune install: copy files in an atomic way (ocaml/dune#6150, @emillon)

- Add `%{coq:...}` macro for accessing data about the configuration about Coq.
  For instance `%{coq:version}` (ocaml/dune#6049, @Alizter)

- update vendored copy of cmdliner to 1.1.1. This improves the built-in
  documentation for command groups such as `dune ocaml`. (ocaml/dune#6038, @emillon,
  ocaml/dune#6169, @shonfeder)

- The test suite for Coq now requires Coq >= 8.16 due to changes in the
  plugin loading mechanism upstream (which now uses `Findlib`).

- Starting with Coq build language 0.6, theories can be built without importing
  Coq's standard library by including `(stdlib no)`.
  (ocaml/dune#6165 ocaml/dune#6164, fixes ocaml/dune#6163, @ejgallego @Alizter @LasseBlaauwbroek)

- on macOS, sign executables produced by artifact substitution (ocaml/dune#6137, ocaml/dune#6231,
  fixes ocaml/dune#5650, fixes ocaml/dune#6226, @emillon)

- Added an (aliases ...) field to the (rules ...) stanza which allows the
  specification of multiple aliases per rule (ocaml/dune#6194, @Alizter)

- The `(coq.theory ...)` stanza will now ensure that for each declared `(plugin
 ...)`, the `META` file for it is built before calling `coqdep`. This enables
 the use of the new `Findlib`-based loading method in Coq 8.16; however as of
 Coq 8.16.0, Coq itself has some bugs preventing this to work yet. (ocaml/dune#6167 ,
 workarounds ocaml/dune#5767, @ejgallego)

- Allow include statement in install stanza (ocaml/dune#6139, fixes ocaml/dune#256, @gridbugs)

- Handle CSI n K code in ANSI escape codes from commands. (ocaml/dune#6214, fixes ocaml/dune#5528,
  @emillon)

- Add a new experimental feature `mode_specific_stubs` that allows the
  specification of different flags and sources for foreign stubs depending on
  the build mode (ocaml/dune#5649, @voodoos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment