timbertson / opam2nix

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

Building on Guix #46

Open roptat opened 3 years ago

roptat commented 3 years ago

Hi :)

I'm trying to build opam2nix on Guix, using existing Guix packages (and importing dependencies that are not yet in the distribution). I tried to build v1.2.0 as well as the latest commit, and get the following error:

File "src/opam_metadata.ml", line 30, characters 28-44:
30 |    | ExternalDependencies of (OpamSysPkg.Set.t * OpamTypes.filter) list
                                 ^^^^^^^^^^^^^^^^
Error: Unbound module OpamSysPkg
  version_ml src/version.ml

Am I missing a dependency? Am I using something that's too old/too recent?

timbertson commented 3 years ago

The opam libraries are defined in nix/opam.nix, but the source comes from wrangle.json - each of those libraries comes from the opam repo, which I've currently pinned to version 2.1.0-beta: https://github.com/timbertson/opam2nix/blob/f6b45ed9e95e468f2971f7fee9dd5abbbc1d7577/nix/wrangle.json#L16-L27

Fair warning: I do have a rather invasive script to rip out some dependencies for opam-client: https://github.com/timbertson/opam2nix/blob/f6b45ed9e95e468f2971f7fee9dd5abbbc1d7577/nix/opam-client-minimal.sh That's just to eliminate the need for dose, etc, but if you have those packaged already you should be fine to just use the full opam-client, at least to get started with. I should probably just vendor the functions I need from opam-client, but I worked hard to get them upstreamed in the first place :laughing:

roptat commented 3 years ago

ah, thanks! the package builds with opam 2.1.0-beta2. I was looking at the opam2nix.opam file, where there is no constraint. you might want to add one :). Now I managed to build it, but I'm not sure how to run it on the build side. I found this opam2nix invoke patch (build, install), but I get Missing environment variable: out. Is this supposed to be the output of the derivation? Also, how do I pass the name of the opam file I want to build the sources with?

timbertson commented 3 years ago

Yeah, the .opam file is not actually used (aside from some experiments I was trying), I should probably just delete it.

out is set by nix to the derivation's output / destination path, but it's only set when building a derivaiton. Are you running tis inside a derivation or just testing it out in a shell for now? I assume guix also sets $out during build, but maybe it uses something different. If you just want to try it outside a derivation, setting it to /tmp/whatever should get you a bit further.

Once you get past that, you'll also need to set opamEnv, which is a JSON serialization of all dependencies. That's set up here in the nix code:

https://github.com/timbertson/opam2nix/blob/f6b45ed9e95e468f2971f7fee9dd5abbbc1d7577/nix/api.nix#L116-L124 And it's loaded here in ocaml code, if that's useful:

https://github.com/timbertson/opam2nix/blob/f6b45ed9e95e468f2971f7fee9dd5abbbc1d7577/src/invoke.ml#L73-L120

timbertson commented 3 years ago

(ugh tabs render so ugly in github UI...)