git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Clippy hook fails when run using `nix flake check`

Open Scrumplex opened this issue 1 year ago • 5 comments

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.

Scrumplex avatar Jun 02 '24 14:06 Scrumplex