Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake fetching of git repos by URL with a specified ref= parameter does not allow a tag as a ref #8790

Closed
IreneKnapp opened this issue Aug 5, 2023 · 2 comments
Labels

Comments

@IreneKnapp
Copy link

Describe the bug

A flake.nix along the lines of:

{
  inputs = {
    upstream = {
      url = "git+file:///tmp/reproduction/foo?ref=some-tag";
    };
  };

  outputs = { self }: { };
}

... will never succeed with nix flake lock or nix flake update, instead printing a message along the lines of:

fatal: couldn't find remote ref refs/heads/some-tag
error: program 'git' failed with exit code 128
(use '--show-trace' to show detailed location information)

What's happening there is that it's assuming ref= refers to a branch (hence prefixing it with refs/heads/), but it refers to a tag.

Steps To Reproduce

Create a local git repository, with at least one commit, and a tag named some-tag pointing to that commit. The repository also needs to contain a flake.nix; the minimal one is { outputs = { self }: { }; }.

In a separate directory, create a flake.nix which references that repository as an input, using a URL in the form git+file:///path/to/repo?ref=some-tag.

Attempt to do nix flake lock to generate a flake.lock.

Expected behavior

The repository should be retrieved, the tag ref should be found, and the flake.lock should be created.

nix-env --version output

nix-env (Nix) 2.13.3

Additional context

This works fine if you use ref=refs/tags/some-tag instead. However, that may defy user expectations, since the git command-line tools accept both branch and tag names anywhere that they ask for a "ref".

I discovered this in a much more complicated situation, so I was greatly relieved that none of the nuances I dug into turned out to be relevant.

This appears to be caused by

: "refs/heads/" + *ref;

I've spent enough time on this that I want to try my hand at writing a patch, but it's not clear to me why nix thinks it needs to prefix the ref name in the first place, and I don't want to cause a regression by simply removing that logic. Does anybody have context on that?

Priorities

Add 👍 to issues you find important.

@IreneKnapp IreneKnapp added the bug label Aug 5, 2023
@figsoda
Copy link
Member

figsoda commented Aug 5, 2023

might be duplicate of #5291

@IreneKnapp
Copy link
Author

ah yep I believe it is, thanks for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants