How does one configure a flake registry to use self-hosted GitLab repositories?

I’m wandering through experimental lands of flake registries.

I found I can install my flakes using nix profile install gitlab:cool-group/cool-project/main?host=gitlab.mycompany.com.

That seems verbose and error-prone for end-users.
I’d like to be able to say nix profile install mycompany#cool-group/cool-project.

Have you found how to configure a custom registry to work with self-managed GitLab instances? Or something similar?

If you write the file by hand you can set the reference in attribute representation, which might allow you to set things like host without specifying the rest - I haven’t tried this though: nix registry - Nix Reference Manual

afaik the details of what attributes are supported aren’t exactly documented though: nix flake - Nix Reference Manual

1 Like

Alternatively you can install custom local registry aliases through nix.registry option.

Here’s an example of adding custom aliases (ns = nixpkgs/23.11, nu = nixpkgs-unstable, pin all system inputs as pinned-<inputname>).

Which results in:

❯ nix registry list | grep -m1 'system'
system flake:ns path:/nix/store/yj20wqsmn7x89z6avx9syjwiirga9jpv-source?lastModified=1712543224&narHash=sha256-9RSfZL1TKYdGxZwgDxwtBtsKMGR4Zgn%2BDAnF9s71/lU%3D&rev=b0dab7cc34ef4d8a1b2de36178da801090bcb271
1 Like

Thanks for the ideas folks.
I’ve discovered a bug prevents me from using the path syntax I started with: #6614 broke flake URL decoding for Gitlab · Issue #9161 · NixOS/nix · GitHub

So I’ll like take the attribute representation / meta flake approach.

For posterity, my confusion and issue here looks like a duplicate of this same topic: Nix flake gitlab HTTP 404 error

Unfortunately I could not find a time and my nix flake knowledge reasonable way to install directly with nix profile <installable>.

I solved my use case by:

  1. clone the gitlab repository using a personal access token on the GNU/Linux instance
  2. nix profile install ./cool-project/#my-app