timbertson / opam2nix

Generate nix expressions from opam packages
MIT License
93 stars 28 forks source link

Updates, improves opam+dune integration #91

Closed MisterDA closed 2 months ago

MisterDA commented 3 months ago

This PR improves the opam and dune integration of opam2nix. The opam file with correct dependencies is now generated by dune, and for all the examples as well. The examples have been updated to OCaml 4.14. It should now be easier to release new opam2nix versions as Dune takes care of tagging the version.

I have been unable however to update the examples nix files with new nix opam selections as the solver keeps on trying OCaml 5.3 (unreleased, currently trunk). Where's the bug?

$ gmake -C examples/simple nix/opam-selection.nix
gmake: Entering directory '/Users/antonin/Tarides/opam2nix/examples/simple'
nix-shell -A resolve default.nix
trace: [niv]: providing swhid_core from tarball
trace: [niv]: providing opam from tarball
trace: [niv]: providing opam-file-format from tarball
trace: [niv]: providing spdx_licenses from tarball
trace: [niv]: providing zeroinstall from tarball
trace: [niv]: providing opam-0install-solver from tarball
this derivation will be built:
  /nix/store/cjrimak07bh8i2q2p9pk9zbj39kg7rr4-ocaml4.14.2-opam2nix-33bcff0.drv
building '/nix/store/cjrimak07bh8i2q2p9pk9zbj39kg7rr4-ocaml4.14.2-opam2nix-33bcff0.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/1dhci0wyh0dz67yli3p6q7x0l4bjaiya-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
no configure script, doing nothing
Running phase: buildPhase
Running phase: installPhase
Running phase: fixupPhase
checking for references to /private/tmp/nix-build-ocaml4.14.2-opam2nix-33bcff0.drv-0/ in /nix/store/3ii9dj2n2j3c7r97arbsh1z3984gizn4-ocaml4.14.2-opam2nix-33bcff0...
patching script interpreter paths in /nix/store/3ii9dj2n2j3c7r97arbsh1z3984gizn4-ocaml4.14.2-opam2nix-33bcff0
stripping (with command strip and flags -S) in  /nix/store/3ii9dj2n2j3c7r97arbsh1z3984gizn4-ocaml4.14.2-opam2nix-33bcff0/lib /nix/store/3ii9dj2n2j3c7r97arbsh1z3984gizn4-ocaml4.14.2-opam2nix-33bcff0/bin
+ /nix/store/3ii9dj2n2j3c7r97arbsh1z3984gizn4-ocaml4.14.2-opam2nix-33bcff0/bin/opam2nix resolve --dest /Users/antonin/Tarides/opam2nix/examples/simple/nix/opam-selection.nix --ocaml-version 4.14.2 hello.opam
Fetching...
Importing opam-repository 13d5334f87e9684897511adf5d1c6fffd36d66e9 into nix store...
Solving...
Can't find all required versions.
Selected: base-bytes.base base-threads.base base-unix.base cppo.1.6.9
          csexp.1.5.2 dune.3.16.0 dune-configurator.3.16.0 hello.dev
          lwt.5.7.0 ocaml.5.3.0 ocaml-config.3 ocamlfind.1.9.6
          ocplib-endian.1.2 hello&ocaml-base-compiler ocaml
          ocaml-base-compiler ocaml-base-compiler
- ocaml-base-compiler -> (problem)
    ocaml-base-compiler|ocaml-variants|ocaml-system|dkml-base-compiler ocaml-base-compiler requires = 5.3.0
    Rejected candidates:
      ocaml-base-compiler.4.14.2: Incompatible with restriction: = 5.3.0
gmake: *** [Makefile:5: nix/opam-selection.nix] Error 1
gmake: Leaving directory '/Users/antonin/Tarides/opam2nix/examples/simple'

Would you be open to applying OCamlFormat on the code?

timbertson commented 3 months ago

It should now be easier to release new opam2nix versions as Dune takes care of tagging the version.

I don't use dune to release, where is the version stored in this PR? Or is it auto generated from git tags?

Would you be open to applying OCamlFormat on the code?

Not at this stage, I'd rather not deal with that kind of huge diff.

What's the rationale for changing development to dev? Is there some standard I'm unaware of?

MisterDA commented 3 months ago

Sorry for the delay.

It should now be easier to release new opam2nix versions as Dune takes care of tagging the version.

I don't use dune to release, where is the version stored in this PR? Or is it auto generated from git tags?

Yes, it is generated from git tags or the git commit. You could take a look at dune-build-info and dune-release.

Would you be open to applying OCamlFormat on the code?

Not at this stage, I'd rather not deal with that kind of huge diff.

No problem.

What's the rationale for changing development to dev? Is there some standard I'm unaware of?

It's the default version selected by opam. See:

$ opam pin add opam2nix git+https://github.com/timbertson/opam2nix.git
Package opam2nix does not exist, create as a NEW package? [y/n] y
[opam2nix.dev] synchronised (git+https://github.com/MisterDA/opam2nix.git)
timbertson commented 2 months ago

Sorry, this PR conflates a bit too much for me. I'm sure dune-build-info is nice, but at this stage I don't actively work on opam2nix much, I'm not that keen on learning a new release process. If you want to split out the updates without all the changes to build / release, I'd likely accept those.

MisterDA commented 2 months ago

I thought about using dune-build-info to help with your release process since the VERSION file in the main branch isn't up-to-date with the latest release of opam2nix… it reads 1.1.0, even in the version-1.2.0 tag. This is something that dune-build-info/dune-release can help you with. In the meantime the project I needed opam2nix for switched to hand-written nix flakes… but do feel free to cherry-pick commits from this branch too.