Pin a package from a specific directory of a GitHub repository

I’m trying to add a package that exists in a specific directory of a GitHub repository. The command I’m running (which is also the one noted in their docs) is this one:

opam pin add bril

However, I get this error from that command:

[ERROR] Error getting source from
          - Unknown archive type: /private/var/folders/28/5hk42_6s4z9d5mm7cqc0jng00000gn/T/opam-59021-9b8556/bril-ocaml

I’ve resulted to pinning the package from a local copy of that repository, and that works fine, but I’m wondering what I’m missing to make the suggested command work.

Thanks for any help!

Most likely, opam failed to inferred that your URL should be interpreted as the address to a (remote) git repository. Either one of the following should work:

opam pin add -k git bril


opam pin add bril

I tried unpinning the local copy and then running the commands. I get the same error from both of those commands:

[ERROR] Could not synchronize ./_opam/.opam-switch/sources/bril from "git+":
        "/usr/bin/git fetch -q" exited with code 128 "fatal: repository '' not found"
[ERROR] Error getting source from git+
          - git+

Perhaps I should mention that I am using a switch for this project. Thank you for the suggestion, any other ideas I could try?

Ah yeah, of course, the url you’ve specified is to (the github tree view of) a sub-directory, it is not a git repository in itself. I don’t know if you can opam pin it that way then…

Opam 2.1.0 did at one point experimentally support pinning at a subpath of a repository (with pin --subpath), but the option has since been removed.

1 Like

Ah! Nice to know, thank you. Then would you say the best method of doing this sort of thing is cloning and pinning from the local directory?

1 Like

There are a few options, depending on what workflow you plan on having with the package, but yes cloning + pinning at the right subpath with -k path should work.

Since the package builds with Dune, one alternative is to vendor it by copying the package anywhere inside your source tree (e.g. with a Git submodule in a vendors/ directory) and installing its dependencies. Dune will pick up the library automatically, and you can use (vendored_dirs <path>) to avoid accidentally running its tests / formatting its source code. This has the advantage of being somewhat easier to replicate in CI & avoiding Opam invocations if you ever want to modify the library.

1 Like

Great, this is very helpful! Thank you.

1 Like