Search/discoverability using Flakes

Hello all,

I am using flakes for some of my projects and have run into some issues related to discoverability of packages/apps/devShells etc provided by the flakes.

Lets assume the following scenario:

I have a registry named: foo/0.1.0

The only way to find out user defined/custom registries is to run nix registry list | grep user which I can live with.

The issue comes when I try and search for packages provided by the foo/0.1.0 registry.
I can not simply run nix search foo . Nix search actually expects me to give it the complete name of the registry like nix search foo/0.1.0 which will then show me packages defined by the flake.

Is there a way we can simply run something like nix search foo/* which should go over all the packages defined in all the flakes in foo/* registries?

Now, to extend this it would be really nice to have a complete search over all the flakes in all the available registries to actually work like nix-env -qaP foo* (I hope I am missing something and this is already available out of the box?)

Can I ask why you would have a registry entry named foo/0.1.0?

Sure, I want to make sure I can pin the versions of each of the flake in the project independently and am not aware of any functionality which allows me to do this. foo/0.1.0 basically allows me to then override the flake versions by means of overrides and generate new builds.

You can have the registry entry named foo and foo/0.1.0 will point to the 0.1.0 tag/branch of foo, and you will be able to search at the HEAD of foo without specifying 0.1.0

Hey @figsoda , thanks for replying! I tried out using this method but did not have much success with it (most likely due to some errors I made).

One question I wanted to ask was, does your solution require the flakes to be hosted in a git server?

I added a flake to my registry as follows:

nix registry add foo github:blah/foo

I have added 2 tags to it, v0.1.0 and v0.2.0.

However, when I run nix flake show foo, nix tries to access the master branch.
So my first question is, how can I ask it to use another branch for example main?

You should be able to refer to such a tag via a flake URL like github:blah/foo/v0.1.0. The manual has more details on the full variety of flake URLs: nix flake - Nix Reference Manual

you can use foo/main

Thanks a lot @robx, @figsoda . That does work out fine for me.

I have some questions related to platforms which are supported for the registries (ie. github, gitlab etc).

We actually have private repositories in gitlab as opposed to github, would you be able to confirm if gitlab is also supported?
When I try to add a repository as gitlab:<USER>/<repo>

It doesn’t seem to work. Thanks again for all the help I really appreciate it :smiley:

gitlab is indeed supported, you would need to add your API tokens to your nix config with access-tokens

Hey @figsoda , I did try using both my ssh keys and access tokens to authenticate…but can’t seem to get it to work.

The following are my steps:

  1. Add a registry foo:
    nix registry add foo gitlab:some_user_bar/external/flakes/foo_flake_repo
  2. Add my access token to ~/.config/nix/nix.conf

Now, when I run nix flake show foo, I get an error of the form:

error: unable to download '': HTTP error 404

       response body:

       {"message":"404 Project Not Found"}

The error leads me to believe that the url generated is not really correct. Gitlab allows us to create a group of projects which I dont think is the case with Github. If you look closely at the error message, its trying to look for a ref_name=flakes/foo_flake_repo which is not correct.

Is there anyone who has got registries to work using Gitlab?

Thanks again for your time and effort! :grinning:

I think you ran into Flakeref for gitlab repos inside subgroups · Issue #6435 · NixOS/nix · GitHub, the workaround is to escape / with %2F, so gitlab:some_user_bar/external%2Fflakes%2Ffoo_flake_repo

1 Like

Thanks a lot @figsoda . That did the trick :grinning: