NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.31k stars 1.48k forks source link

#6614 broke flake URL decoding for Gitlab #9161

Open Silver-Golden opened 11 months ago

Silver-Golden commented 11 months ago

Describe the bug

The recent change in #6614 broke flake url's for gitlab.
The cause of this is that the gitlab libfetcher uses the github logic of owner/project/branch

Steps To Reproduce (from https://github.com/NixOS/nix/pull/8773#issuecomment-1753901794)

This worked fine on 2.13.2 at least, not sure what was last version it worked on.

compsoc_public.url = "gitlab:compsoc1%2Fcompsoc/presentations?host=gitlab.skynet.ie";
silver@DESKTOP-7RB7S9E:/mnt/c/College/Compsoc/nixos$ nix develop
error:
       … while updating the lock file of flake 'git+file:///mnt/c/College/Compsoc/nixos?ref=refs/heads/main&rev=8ea737d57b224cdc8e5009ff47cb1e013ca71ac0'

       … while updating the flake input 'compsoc_public'

       … while fetching the input 'gitlab:compsoc1/compsoc/presentations'

       error: unable to download 'https://gitlab.skynet.ie/api/v4/projects/compsoc1%2Fcompsoc/repository/commits?ref_name=presentations': HTTP error 404

       response body:

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

If I change the last slash in it to %2F result is the same

compsoc_public.url = "gitlab:compsoc1%2Fcompsoc%2Fpresentations?host=gitlab.skynet.ie";
silver@DESKTOP-7RB7S9E:/mnt/c/College/Compsoc/nixos$ nix develop
warning: Git tree '/mnt/c/College/Compsoc/nixos' is dirty
error:
       … while updating the lock file of flake 'git+file:///mnt/c/College/Compsoc/nixos'

       … while updating the flake input 'compsoc_public'

       … while fetching the input 'gitlab:compsoc1/compsoc/presentations'

       error: unable to download 'https://gitlab.skynet.ie/api/v4/projects/compsoc1%2Fcompsoc/repository/commits?ref_name=presentations': HTTP error 404

       response body:

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

and for funsies use all /, still same error

compsoc_public.url = "gitlab:compsoc1/compsoc/presentations?host=gitlab.skynet.ie";
silver@DESKTOP-7RB7S9E:/mnt/c/College/Compsoc/nixos$ nix develop
warning: Git tree '/mnt/c/College/Compsoc/nixos' is dirty
error:
       … while updating the lock file of flake 'git+file:///mnt/c/College/Compsoc/nixos'

       … while updating the flake input 'compsoc_public'

       … while fetching the input 'gitlab:compsoc1/compsoc/presentations'

       error: unable to download 'https://gitlab.skynet.ie/api/v4/projects/compsoc1%2Fcompsoc/repository/commits?ref_name=presentations': HTTP error 404

       response body:

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

Expected behavior

There is no error in downloading and using gitlab flakes.

nix-env --version output

nix-env (Nix) 2.18.1

Additional context

I am working on teh patch for split out the url parsing logic from teh github version.

Priorities

Add :+1: to issues you find important.

mdarocha commented 10 months ago

For me on Nix 2.18, using the attribute set representation, as described in https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-references works properly.

ie.

inputs.example = {
  type = "gitlab";
  owner = "group%2Fsubgroup";
  repo = "repo";
};
WayneSherman commented 7 months ago

I can confirm this issue. A gitlab repo that is a subgroup two levels deep doesn't get parsed properly:

Gitlab project: https://gitlab.com/freepascal.org/lazarus/lazarus

  inputs = {
    ...
    lazarusSrc = {
      url ="gitlab:freepascal.org%2Flazarus%2flazarus";
      flake = false;
    };
  };
   error while fetching the input 'gitlab:freepascal.org/lazarus/lazarus'

   error: unable to download 'https://gitlab.com/api/v4/projects/freepascal.org%2Flazarus/repository/commits?ref_name=lazarus': HTTP error 404

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

The correct API link should use something like this: https://gitlab.com/api/v4/projects/freepascal.org%2Flazarus%2Flazarus/repository/commits

nixos-discourse commented 5 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-does-one-configure-a-flake-registry-to-use-self-hosted-gitlab-repositories/43662/4