Skip to content

Conversation

sellout
Copy link
Contributor

@sellout sellout commented Oct 1, 2025

This extracts the simpler Nix changes from #5796. That PR does a bunch of Nix changes, some of which introduce an issue building with Stack. This PR includes the parts that are independent of that change, both to make that PR smaller and to make the benefits of these changes available.

  • nix flake check now works, since unison-cli:test:cli-tests is no longer sandboxed
  • hpack version is now consistent
  • nix develop no longer requires LD_LIBRARY_PATH to be defined
  • the build systems can be overridden, to either avoid some or to try a new one

On macOS, it requires access to `security`, which is outside the
sandbox, so don’t sandbox it when running on Darwin.

This is made possible by setting `sandbox` to `relaxed` in the flake,
which allows using `__noChroot` to mark derivations as unsandboxed. This
makes things less strict on Linux (where the sandbox is on by default),
but more strict on Darwin (where the sandbox is off by default).
This allows us to install a different version than the one included in
Nixpkgs. We pin it to the version included in our Stack from Nix.

This also re-generates all the Cabal files with the new hpack.
This workaround required another local workaround. If you had a line
like `LD_LIBRARY_PATH=` in your .envrc, it can be removed now.
Somewhat described at https://github.com/nix-systems/nix-systems

This is useful for Haskell projects, because commands like

```bash
nix flake show --allow-import-from-derivation
```

can often fail, complaining that it can’t find some other architecture
to build on. With nix-systems, you can append
`--override-input systems github:nix-systems/x86_64-linux` to the
command to ensure that x86_64-linux is the only platform in play.
Calling it `nixpkgs` makes it clear that it’s the Nixpkgs used for most
things, so if anything follows or overrides this input, they’ll get
reasonable behavior.
@sellout sellout force-pushed the minimal-nix-update branch 2 times, most recently from 33cf154 to 50a09f0 Compare October 2, 2025 01:00
The previous version of cachix/install-nix-action installed too old of a
Nix version to allow sandboxing on macOS.

This also updates the aarch64-darwin runner to `macos-15`.
@sellout sellout force-pushed the minimal-nix-update branch from 50a09f0 to a013b02 Compare October 2, 2025 01:01
@sellout
Copy link
Contributor Author

sellout commented Oct 2, 2025

@sellout sellout marked this pull request as ready for review October 2, 2025 02:44
@sellout sellout requested a review from a team as a code owner October 2, 2025 02:44
@sellout sellout requested review from aryairani and ceedubs October 2, 2025 03:26
Copy link
Contributor

@ceedubs ceedubs left a comment

Choose a reason for hiding this comment

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

Per one of my comments I'm interested in whether we can work around the security issue on darwin, but if that doesn't work then I'm good with merging this as-is. Thanks!

"unison-cli:test:cli-tests" = haskell-nix-flake.checks."unison-cli:test:cli-tests".overrideAttrs (old: {
## On macOS, this derivation requires access to `security`, which is outside the sandbox, so we tell Nix that
## it doesn’t work in the sandbox.
__noChroot = pkgs.stdenv.isDarwin;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does adding a dependency on darwin.apple_sdk.frameworks.Security instead work? I don't have a good way to test that.

Copy link
Contributor Author

@sellout sellout Oct 2, 2025

Choose a reason for hiding this comment

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

It doesn’t, unfortunately. I just updated the comment to at least link to some Nixpkgs discussion. This is the same reason you have https://github.com/ceedubs/unison-nix/blob/trunk/nix/darwin-security-hack.nix (that’s also unsandboxed, but implicitly since you don’t have sandbox = "relaxed").

It might be worth bringing darwin-security-hack over here as a smaller unsandboxed derivation, where we can add more commentary, and then this can be a sandboxed one that depends on that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I don’t think darwin-security-hack would work here. Nixpkgs has already patched the offending Haskell packages to look at the absolute path for security, so copying it to the store doesn’t do anything.

https://github.com/matthewbauer/nixpkgs/blob/master/pkgs/development/haskell-modules/configuration-nix.nix#L151-L167

extra-substituters = ["https://unison.cachix.org"];
extra-trusted-public-keys = ["unison.cachix.org-1:i1DUFkisRPVOyLp/vblDsbsObmyCviq/zs6eRuzth3k="];
## This allows derivations with `__noChroot` set to run outside the sandbox.
sandbox = "relaxed";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a place where we aren't able to do a check that would limit this to darwin, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, NixOS/nix#4945. This spot is particularly annoying, because the defaults are different on Linux and Darwin, but there’s no way to tighten Darwin from false to "relaxed" without simultaneously weakening Linux from true to "relaxed". But … I prefer "relaxed" as my default anyway, since it lets me control it at the derivation level, and individual environments can still be sandboxed, and thus disallow unsandboxed derivations.

@aryairani
Copy link
Contributor

I don't know enough to weigh in, so just waiting to see what you guys decide.

@ceedubs
Copy link
Contributor

ceedubs commented Oct 2, 2025

Sounds good to me. Merging!

@ceedubs ceedubs merged commit 54c27eb into unisonweb:trunk Oct 2, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants