nmattia / niv

Easy dependency management for Nix projects
https://github.com/nmattia/niv
MIT License
1.55k stars 77 forks source link

niv + flakes: can't fetch git repos #276

Closed tfc closed 4 years ago

tfc commented 4 years ago

Hi there,

not sure if this is:

However, this issue is not about using flakes. I just have flakes activated in my system and with this setting, normal niv projects that use git don't work any longer.

I created a minimal example repo and within that, the following does not work:

$ nix-instantiate 
error: --- BadURL ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix-instantiate
'file://git@github.com:tfc/cmake_cpp_example.git' is not a valid URL

The repo: https://github.com/tfc/niv_flakes_git_problem

i just added the one source item with niv add git ....

Output with --show-trace:

$ nix-instantiate --show-trace
error: --- BadURL ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix-instantiate
'file://git@github.com:tfc/cmake_cpp_example.git' is not a valid URL
----------------------------------------------------------------------------------------------------------------- show-trace -----------------------------------------------------------------------------------------------------------------
trace: while evaluating 'fetch_git'
at: (21:15) in file: /tmp/niv_flakes/nix/sources.nix

    20| 
    21|   fetch_git = spec:
      |               ^
    22|     builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };

trace: from call site
at: (76:37) in file: /tmp/niv_flakes/nix/sources.nix

    75|     else if spec.type == "tarball" then fetch_tarball pkgs spec
    76|     else if spec.type == "git" then fetch_git spec
      |                                     ^
    77|     else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec

trace: while evaluating 'fetch'
at: (70:23) in file: /tmp/niv_flakes/nix/sources.nix

    69|   # The actual fetching function.
    70|   fetch = pkgs: name: spec:
      |                       ^
    71| 

trace: from call site
at: (118:31) in file: /tmp/niv_flakes/nix/sources.nix

   117|         else
   118|           spec // { outPath = fetch config.pkgs name spec; }
      |                               ^
   119|     ) config.sources;
nmattia commented 4 years ago

file://git@github.com:tfc/cmake_cpp_example.git

This is an odd URL, shouldn't this be either file:// or SSH? What happens if you remove the file://?

tfc commented 4 years ago

I never added the file:// prefix. the sources.json does not contain it.

nmattia commented 4 years ago

ok, that's odd. I've had so many segfaults with nixFlakes that I stopped using it; I suspect it might be a bug there. What happens if you set the url to ssh://git@... instead?

tfc commented 4 years ago

then it says

$ nix-instantiate 
error: --- BadURL ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix-instantiate
'ssh://git@github.com:tfc/cmake_cpp_example.git' is not a valid URL
nmattia commented 4 years ago

ok, with ssh:// I think you need to replace : with /:

[nix-shell:/tmp/tmp.TXuGlnCBbT]$ cat default.nix 
builtins.fetchGit { url = "ssh://git@github.com/tfc/cmake_cpp_example"; ref = "refs/heads/master"; }

[nix-shell:/tmp/tmp.TXuGlnCBbT]$ nix-build
# basically ok

not sure why exactly to be perfectly honest, will need to investigate a bit more

tfc commented 4 years ago

hm, can't reproduce:

nix-repl> builtins.fetchGit { ref = "master"; rev = "15e516d23f8b9d213c83e15f5d73fc7dc37ea22a"; url = "ssh://git@github.com:tfc/cmake_cpp_example.git"; }
error: --- BadURL ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix
'ssh://git@github.com:tfc/cmake_cpp_example.git' is not a valid URL

nix-repl> builtins.fetchGit { ref = "master"; rev = "15e516d23f8b9d213c83e15f5d73fc7dc37ea22a"; url = "git@github.com:tfc/cmake_cpp_example.git"; }
error: --- BadURL ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix
'file://git@github.com:tfc/cmake_cpp_example.git' is not a valid URL

but at this point it's clear that it's rather a bug in nix than in niv.

oh sorry i did not get that you mean to replace the : after the hostname. doing that, it works.

tfc commented 4 years ago

~https://github.com/NixOS/nix/issues/3987~ https://github.com/NixOS/nix/issues/3503

nmattia commented 4 years ago

I'm closing this for now, feel free to reopen if you think niv should do some special handling.

tchoutri commented 3 years ago

Fixed this by applying this patch:

- "repo": "git@github.com:repo"
+ "repo": "ssh://git@github.com/repo"