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

Tags with +suffix breaking vendoring? #549

Open
dpc opened this issue Mar 12, 2024 · 1 comment
Open

Tags with +suffix breaking vendoring? #549

dpc opened this issue Mar 12, 2024 · 1 comment
Labels
needs reproduction Missing a flake which easily reproduces the problem

Comments

@dpc
Copy link
Contributor

dpc commented Mar 12, 2024

We've tried to use a dependency in Cargo.lock that refers to a git repo with tag that contained +suffix, and we got a weird error:

pkgs-group-ci-deps> Caused by:
pkgs-group-ci-deps>   failed to load source for dependency `repo-core`
pkgs-group-ci-deps> Caused by:
pkgs-group-ci-deps>   Unable to update https://github.com/repo/repo-repo?tag=v0.3.0-alpha.0+suffix
pkgs-group-ci-deps> Caused by:
pkgs-group-ci-deps>   the source https://github.com/repo/repo-fedi?tag=v0.3.0-alpha.0+suffix requires a lock file to be present first before it can be
pkgs-group-ci-deps>   used against vendored source code
pkgs-group-ci-deps>   remove the source replacement configuration, generate a lock file, and then
pkgs-group-ci-deps>   restore the source replacement configuration to continue the build

cargo build and cargo vendor work locally just fine. After changing the tag name to not contains +suffix, the problem went away.

@ipetkov
Copy link
Owner

ipetkov commented Mar 12, 2024

Hmm interesting, there's two parts of the code which come to mind:

  1. Parsing the git dependency in Cargo.lock (though nothing about the code immediately jumps out as the culprit):
    parseGitUrl = p:
    let
    lockUrl = removePrefix "git+" p.source;
    revSplit = split "#" (removePrefix "git+" lockUrl);
    # uniquely identifies the repo in terms of what cargo can address via
    # source replacement (e.g. the url along with any branch/tag/rev).
    id = head revSplit;
    # NB: this is distict from the `rev` query param which may show up
    # if the dependency is explicitly listed with a `rev` value.
    lockedRev = if 3 == length revSplit then last revSplit else
    throw ''
    Cargo.lock is missing a locked revision for ${p.name}@${p.version}.
    you can try to resolve this by running `cargo update -p ${lockUrl}#${p.name}@${p.version}`
    '';
    querySplit = split "\\?" (head revSplit);
    git = head querySplit;
    queryParamSplit = filter
    (qp: (isString qp) && any (p: hasPrefix p qp) knownGitParams)
    (split "&" (last querySplit));
    extractedParams = listToAttrs (map
    (qp:
    let
    kvSplit = (split "=" qp);
    in
    nameValuePair (head kvSplit) (last kvSplit)
    )
    queryParamSplit
    );
    in
    extractedParams // {
    inherit git id lockedRev;
    };
  2. How we specify the tag when asking Nix to download it:
    if p ? tag then "refs/tags/${p.tag}"
    else if p ? branch then "refs/heads/${p.branch}"
    else null;
    extractedPackages = downloadCargoPackageFromGit {
    inherit (p) git;
    inherit ref;
    rev = p.lockedRev;
    sha256 = outputHashes.${p.package.source} or (lib.warnIf
    (outputHashes != { })
    "No output hash provided for ${p.package.source}"
    null
    );
    };

Do you have a reproduction I can test out further?

@ipetkov ipetkov added the needs reproduction Missing a flake which easily reproduces the problem label Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction Missing a flake which easily reproduces the problem
Projects
None yet
Development

No branches or pull requests

2 participants