[Nix-dev] Announce: opam2nix

Tim Cuthbertson tim at gfxmonk.net
Tue Aug 18 00:24:02 CEST 2015


Announcing `opam2nix`, my still-early project to derive nix
expressions from OPAM ocaml packages:

https://github.com/gfxmonk/opam2nix/

It's almost entirely driven from vanilla `opam` repo data[0], aside
from a few tweaks to `findlib` to integrate its nix hooks (adding
build inputs to $OCAMLFIND_DESTDIR).

The github page has the details on how to use it, but one thing which
might differ from other similar systems is that the packages produced
aren't ready to be imported directly - they need to be given a set of
selections - equivalent to the set of all installed packages in an
`opam` env. There are a couple of reasons for this:

1) There are a lot of optional dependencies in the opam universe, and
installing _all_ of them might be a bit much (and could even create
conflicts where a more minimal set would work)

2) Having each dependency select its own preferred version of e.g.
`extlib` might mean that your dependencies each come with a different
`extlib` version, and I don't think that will work.

3) Because of (2), it also doesn't make much sense to pre-solve each
package. Maybe `libfoo` can use the latest version of `libcommon`, but
if you're _also_ using `libbar` then maybe you need to use an older
version of `libcommon` which satisfies the requirements of both
libraries.

I don't know how other tools like cabal2nix get around this issue, I'd
be interested in any advice on how to make this better / easier.

Using this tool, I've so far been able to successfully generate (and
build) all dependencies of `opam-lib`, and I'm getting quite close to
a working mirage-xen install. Which felt like a good point to publish
it and see what others think. Ideally I'd like to make it part of
nixpkgs, which might help us include more opam packages, and keep them
up to date easily. So I'd appreciate any advice from maintainers of
existing ocaml packages in nixpkgs, if you have thoughts :)

The generated selection file for `opam-lib` looks like this, if you're curious:

    { pkgs, opam2nix, opamPackages, ocaml ? pkgs.ocaml,
        builder ? opamSelection: pkg: pkgs.callPackage pkg.impl {
inherit opamSelection opam2nix; },
        overrideSelections ? sels: sels
    }:
    let
        selection = overrideSelections
        {
          base-bigarray = true;
          base-bytes = builder selection
          (opamPackages.base-bytes.legacy);
          base-threads = true;
          base-unix = true;
          camlp4 = builder selection
          (opamPackages.camlp4."4.01");
          cmdliner = builder selection
          (opamPackages.cmdliner."0.9.7");
          cudf = builder selection (opamPackages.cudf."0.7");
          dose = builder selection (opamPackages.dose."3.3");
          extlib = builder selection
          (opamPackages.extlib."1.6.1");
          jsonm = builder selection
          (opamPackages.jsonm."0.9.1");
          ocaml = ocaml;
          ocamlfind = builder selection
          (opamPackages.ocamlfind."1.5.5");
          ocamlgraph = builder selection
          (opamPackages.ocamlgraph."1.8.5");
          opam-lib = builder selection
          (opamPackages.opam-lib."1.2.2");
          re = builder selection (opamPackages.re."1.4.1");
          uutf = builder selection (opamPackages.uutf."0.9.4");
        };
    in
    selection




(the pretty-printing could do with some work, though...)

[0] well, my fork at https://github.com/gfxmonk/opam-repository


More information about the nix-dev mailing list