Support Nix depexts with opam env#5982
Conversation
|
Rebased on master |
9e67415 to
f348b9f
Compare
|
Looks like I'm running into NixOS/nix#10587 with the Docker image |
1a47e83 to
9892788
Compare
|
Rebased on master -- and could do with another depext CI run if it needs re-approval! |
ff88713 to
2184b56
Compare
|
Okay! The CI is failing only due to ocaml/opam-repository#26261 (I've got it working locally with my branch of opam-repository) |
|
Anyone wanting to play around with this on a NixOS system can try: Or add it to your own overlay with: This URL is just the https://github.com/RyanGibb/opam/tree/nixos-depexts-2.3.0 branch with vendored dependencies since I couldn't get them working in Nix, |
|
David made an observation in today's Opam dev meeting that this PR will not remove depexts from the Nix derivation until the next install. This might effect reproducibility in some circumstances, but this isn't a huge deal as if Nix users want full reproducibility they can use opam2nix. |
kit-ty-kate
left a comment
There was a problem hiding this comment.
while tracking down NixOS/nixpkgs#388471 i tried this branch and it worked really well in a nixos docker container. I was able to build opam-publish which requires openssl and gmp without any issues at all, like magic.
src/state/opamSysInteract.ml
Outdated
| let stateless_install ?(env=OpamVariable.Map.empty) () = | ||
| match family ~env () with | ||
| | exception Failure _ -> false (* no depexts *) | ||
| | Nix -> false |
There was a problem hiding this comment.
Shouldn't the function name be reversed? Nix is a stateless install, as well as no depext, but everything else should be stateful. So either the boolean needs to be flipped or the function needs to be renamed to stateful_install
Co-authored-by: Ryan Gibb <ryan@freumh.org>
…entiate newly requested and required ones Co-authored-by: Ryan Gibb <ryan@freumh.org> Co-authored-by: Kate <kit-ty-kate@outlook.com>
…onised already installed systems dependencies with switch state Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com> Co-authored-by: Kate <kit-ty-kate@outlook.com>
… write internally in the switch Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
At each install, a Nix derivation is created and stored in the switch containing all system packages needed: newly "installed" ones and already "required" ones. An environment files is also generated ans used to complete 'opam env'. Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com> Co-authored-by: Kate <kit-ty-kate@outlook.com>
Co-authored-by: Kate <kit-ty-kate@outlook.com> Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
|
Thanks a lot! |
|
Wow, awesome that this got merged at long last! Thank you both for all the work you put in :-) |
Nix doesn't install packages in the traditional sense -- instead it puts them in a store and makes them available through environment variables. I.e.,
nix-shell -p gccwill drop us into a shell with gcc in the$PATH.We can set appropriate environment variables with Opam to make system dependencies (depexts) available with Nix.
Similar to how
nix-shellworks under the hood, we create a Nix derivation such asWhich we can build to output a file with environment variables that make depexts available, in Opam's environment variable format. This file is a Nix store root, so it's dependencies won't be garbage collected by Nix until the file is removed.
This approach came from conversations with @dra27 and is distinct from previous approaches in that it supports providing development environment, which imperative installations with Nix don't #5332 (comment); and doesn't require the user to manage the environment outside of Opam, which would lead to a different workflow #5942.
Initial experiments were done using a package to set such environment variables https://github.com/RyanGibb/nix.opam.
However, in order to work with generic depexts (as opposed to just conf packages), to avoid cyclic dependencies (if conf packages depend on nix.opam but nix.opam depends on conf packages), and due to opam package sandboxing (nix derivation fetching would require opam sandboxing to be disabled or the nix store to be 'primed'), it's better implemented as a depext mechanism.
This has been tested and successfully creates an environment to provide packages
conf-gmpandconf-libseccomp, as well as depexts directly.