tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

feat: fake opam list #81

Closed mattjbray closed 8 months ago

mattjbray commented 8 months ago

Sometimes it's useful to see what opam packages and versions have been picked by the solver.

This adds a simple implementation for opam list which just reads $OCAMLPATH.

Note that the output format is different to the real opam list, which tabulates the output and includes the package synopsis by default.

balsoft commented 8 months ago

Note that the output format is different to the real opam list, which tabulates the output and includes the package synopsis by default.

Could you fix this so that the output matches, at least w.r.t the tabulation? Some packages could conceivably be using opam list in a script, having it output something unexpected could lead to some difficult-to-debug errors.

mattjbray commented 8 months ago

Ok, I've changed it to tabulate output. To separate the package name from the version it naively splits on the final occurrence of -, but this will break if the version contains a - character.

With that caveat, the output is now equivalent to opam list --short --columns=name,version --color=never.

Scripts that call fake opam list with different arguments will get unexpected output.

If that's a concern we could log a warning if the arguments are different to the above? I'd rather not require those arguments because the intention here is to provide a useful output to a human typing opam list.

balsoft commented 8 months ago

If that's a concern we could log a warning if the arguments are different to the above? I'd rather not require those arguments because the intention here is to provide a useful output to a human typing opam list.

Could we maybe name the command something else then? E.g. opam nix-list, and make opam list throw a relevant error?

balsoft commented 8 months ago

I ended up doing this myself and merging this into main. You can now do opam fake-list and get the package list. Thanks a lot for the contribution!