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

Cargo check fails to load crates.io-index correctly #94

Closed
Anderssorby opened this issue Mar 29, 2021 · 6 comments · Fixed by #246
Closed

Cargo check fails to load crates.io-index correctly #94

Anderssorby opened this issue Mar 29, 2021 · 6 comments · Fixed by #246

Comments

@Anderssorby
Copy link

When enabling cargo-check.enable = true I get this error:

cargo-check..............................................................Failed
- hook id: cargo-check
- exit code: 101

    Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name; class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name; class=Net (12)
error: failed to get `base-x` as a dependency of package `hashexpr v0.1.0 (/build/src/hashexpr)`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  [6] Couldn't resolve host name; class=Net (12)

building '/nix/store/6lsmz02z9679x4wb1qiy0733689h2fk3-git-deps.drv'...
nix-linter...............................................................Passed
nixpkgs-fmt..............................................................Passed
shellcheck...........................................(no files to check)Skipped
builder for '/nix/store/wi0lbb6j045ma537m6xdvyrcya8g56rg-pre-commit-run.drv' failed with exit code 1

I guess the class=Net has gotten there by mistake?

@domenkozar
Copy link
Member

@Anderssorby
Copy link
Author

cargo check runs fine. I think the problem is that it expects to have internet access which is not allowed in nix-build.

@znewman01
Copy link

In the meantime, I have a very hacky workaround (for cargo clippy), by saving $CARGO_HOME from the dependencies build (there should be something better using builtDependencies directly but I'm getting empty output right now).

Write your Naersk package:

my-crate = naersk.buildPackage {
  # standard!
  inherit src;
  pname = "my-crate";
  version = "0.1";

  # hacks for making clippy work in CI
  postInstall = ''
    cp -r $CARGO_HOME $out/.cargo
  '';
};

And then your pre-commit hooks:

pre-commit-hooks.run {
  inherit src;
  hooks = {
    my-clippy = {
      enable = true;
      entry = ''
        bash -c ' \
           cp -r ${builtins.head my-crate.builtDependencies}/.cargo/ .cargo
           CARGO_HOME=.cargo \
           PATH=${rust}/bin:${pkgs.gcc}/bin:$PATH \
           cargo clippy --release --features strict --offline -- --no-deps
        '
      '';
      pass_filenames = false;
      types = [ "file" "rust" ];
    };
  };
};

@NickHu
Copy link

NickHu commented Apr 19, 2023

This is not fixed, I am still getting issues with clippy not being able to download dependencies

@giodamelio
Copy link

Ya, I am getting bit by this today also. I am looking into solutions.

My error for reference.

pre-commit-run> Running: $ pre-commit run --all-files
pre-commit-run> alejandra................................................................Passed
pre-commit-run> cargo-check..............................................................Failed
pre-commit-run> - hook id: cargo-check
pre-commit-run> - exit code: 101
pre-commit-run>     Updating crates.io index
pre-commit-run> warning: spurious network error (3 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
pre-commit-run> warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
pre-commit-run> warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
pre-commit-run> error: failed to get `anyhow` as a dependency of package `idempotent_set v0.1.0 (/build/src)`
pre-commit-run> Caused by:
pre-commit-run>   failed to query replaced source registry `crates-io`
pre-commit-run> Caused by:
pre-commit-run>   download of config.json failed
pre-commit-run> Caused by:
pre-commit-run>   failed to download from `https://index.crates.io/config.json`
pre-commit-run> Caused by:
pre-commit-run>   [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
pre-commit-run> clippy...................................................................Failed
pre-commit-run> - hook id: clippy
pre-commit-run> - exit code: 101
pre-commit-run> error: no matching package named `clap` found
pre-commit-run> location searched: registry `crates-io`
pre-commit-run> required by package `idempotent_set v0.1.0 (/build/src)`
pre-commit-run> As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.
pre-commit-run> deadnix..................................................................Passed
pre-commit-run> flake-checker............................................................Passed
pre-commit-run> rustfmt..................................................................Passed
pre-commit-run> statix...................................................................Passed

@sandydoo
Copy link
Member

sandydoo commented May 7, 2024

#396 tries to address this.

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