opam icon indicating copy to clipboard operation
opam copied to clipboard

The archive-mirrors value from repo files are not overridable, displayed nor deduplicated

Open kit-ty-kate opened this issue 4 months ago • 2 comments

There are two forms of archive-mirrors:

  • The archive-mirrors from the global options, displayed in opam option and changeable there (since https://github.com/ocaml/opam/pull/5315). By default empty.
  • The archive-mirrors from each repositories currently set in your switch

Currently the latter isn't used very much due to https://github.com/ocaml/opam/pull/4830, but as most people who will actually set archive-mirrors manually are most likely using opam >= 2.2, the idea of setting it in opam-repository sounds doable.

However i can see some minor problems with the way opam handles archive-mirrors for repositories.

  • If one adds several repositories and the all have their archive-mirrors set, then any cache miss will actually try downloading the archive as many times as there are repositories and these urls are not de-duplicated. Meaning that for opam-repository for example, a cache miss will keep sending request to opam.ocaml.org as many times as there are opam-repository forks in the current switch.
  • These values aren't visible anywhere for regular users. The only way for users to know their values is to do grep archive-mirrors: .opam/repo/*/repo or something of the sort.
  • These values aren't overridable. If for whatever reason you do not want to use the mirror from a repository, there are currently no ways of doing that without forking it and removing the archive-mirrors field manually, because...
  • ... removing archive-mirrors from the repo file cannot currently be done automatically without assuming a certain format (e.g. https://github.com/ocaml-opam/opam2web/pull/247) or without using opam-ed

To solve these minor issues, i propose to:

  • improve the handling of the mirrors by transforming the string list to Set.(OpamUrl.t).t where the values are actually used
  • add a Repositories configuration section in opam option that displays the value of archive-mirrors for each repository
  • allow to override the repository configuration with a new opam option --repository argument. Setting it could add a note during opam update to remind them that the value from the repository isn't taken into account
  • add a new opam admin edit-repo-file command, which would allow to remove or edit fields in the repo file

kit-ty-kate avatar Aug 17 '25 13:08 kit-ty-kate

Adding a comment here so that the status appears in https://github.com/ocaml/opam-repository/pull/28348

mseri avatar Sep 16 '25 08:09 mseri

Per 2025/09/22 dev meeting: The variable/option way is a good one, we need to check that it fits well the new repo config format and the variable/option selectors/modifiers. Linked PR is a concluding first draft.

rjbou avatar Oct 31 '25 16:10 rjbou