Nix flake gitlab HTTP 404 error

Hello,

I am preparing my first flake (using the template from nix flake init -t templates#rust) and

nix flake metadata gitlab:user/group/subgroup/package
nix shell gitlab:user/group/subgroup/package

both fail with

error: unable to download 'https://gitlab.com/api/v4/projects/user%2Fgroup/repository/commits?ref_name=subgroup/package': HTTP error 404 ('')

which is suggestive of the problem … but I am not sure how to solve.

The following succeeds:

nix flake metadata 'git+https://gitlab.com/user/group/subgroup/package'
nix shell 'git+https://gitlab.com/user/group/subgroup/package'

Any guidance on how to get the first way working is appreciated!

1 Like

This most likely means that you’re trying to use a private repository. For that to work, Nix will need a netrc file. Take a look at Enterprise - NixOS Wiki - it only mentions fetchurl, but the same mechanism is used for flakes as well.

1 Like

The gitlab schema does not correctly work with subgroups. The subgroups are parsed as branch…

Using gitlab:user/group%2Fsubgroup%2Fpackage might work, though it might as well happen that the percentsigns are escaped then… You need to try it out…

I also was under the impression that there has been a bug report about that, but I can not find it right now, though if Leverage the "uniform" in URLs for flake refs more · Issue #6304 · NixOS/nix · GitHub would get implemented, gitlab subgroups would be fixed as a drive by, due to the strict question for making ref a query parameter and not allow it in the path anymore.

3 Likes

Yes, your proposal here Leverage the "uniform" in URLs for flake refs more · Issue #6304 · NixOS/nix · GitHub would address my issue. Thanks.

FYI a workaround is to use git+https scheme:
nix shell git+https://gitlab.com/txlab/dx/devenvious.git

Or use a source tarball, or use an alternative like npins for that source.