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

Clippy hook fails when run using nix flake check #452

Open
Scrumplex opened this issue Jun 2, 2024 · 5 comments · May be fixed by #396
Open

Clippy hook fails when run using nix flake check #452

Scrumplex opened this issue Jun 2, 2024 · 5 comments · May be fixed by #396
Labels
bug Something isn't working flake Related to running in pure environments

Comments

@Scrumplex
Copy link

This is the relevant flake.parts code:

# SPDX-FileCopyrightText: 2023 Sefa Eyeoglu <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
{
  perSystem = {
    config,
    lib,
    pkgs,
    ...
  }: {
    pre-commit.settings = {
      excludes = [
        "vendor/"
      ];
      hooks = {
        alejandra.enable = true;
        rustfmt.enable = true;
        clippy.enable = true;
        prettier = {
          enable = true;
          excludes = ["flake.lock"];
        };
      };
    };
    devShells.default = pkgs.mkShell {
      shellHook = ''
        ${config.pre-commit.installationScript}
      '';

      inputsFrom = [config.packages.default];
      buildInputs = config.pre-commit.settings.enabledPackages;
      packages = with pkgs; [reuse];
    };
    formatter = pkgs.alejandra;
  };
}

The hook works fine when run in a devShell, but it fails when run as a flake check, as there is no internet access, no access to the cargo cache. Error:

       > - hook id: clippy
       > - exit code: 101
       >
       > error: no matching package named `tokio` found
       > location searched: registry `crates-io`
       > required by package `inhibridge v0.3.0 (/build/src)`
       > 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.
       >

Maybe we should have a way to pass a cargoDeps derivation to allow it to run in a flake check.

@sandydoo
Copy link
Member

sandydoo commented Jun 2, 2024

See #396

@Mastermindaxe
Copy link

Maybe a stupid question, but I'm not gaining any insight from that PR. Is there any workaround to make these checks work in nix flake check currently? Or do we have to wait til that PR lands?

@sandydoo sandydoo added bug Something isn't working flake Related to running in pure environments labels Jun 12, 2024
@sandydoo
Copy link
Member

sandydoo commented Jun 12, 2024

Is there any workaround to make these checks work in nix flake check currently?

nix flake check runs in a pure environment, soclippy and cargo don't have access to anything that's not tracked by git and can't fetch dependencies from the internet.

Workarounds:

Use nix develop:

nix develop -c pre-commit run --all-files

Override the run derivation (example for flake-parts):

          checks.pre-commit = pkgs.lib.mkForce (let
             drv = config.pre-commit.settings.run;
          in
            pkgs.stdenv.mkDerivation {
              name = "pre-commit-run";
              src = config.pre-commit.settings.rootSrc;
              buildInputs = [ pkgs.git pkgs.openssl pkgs.pkg-config ];
              nativeBuildInputs = [pkgs.rustPlatform.cargoSetupHook];
              cargoDeps = pkgs.rustPlatform.importCargoLock {
                lockFile = ./Cargo.lock;
              };
              buildPhase = drv.buildCommand;
            });

@sandydoo sandydoo linked a pull request Jun 12, 2024 that will close this issue
@Mastermindaxe
Copy link

@sandydoo Thank you for that!

@greg-hellings
Copy link

Would still be nice to get this resolved in that PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working flake Related to running in pure environments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants