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

Run a single flake check #8881

Open
9999years opened this issue Aug 29, 2023 · 2 comments
Open

Run a single flake check #8881

9999years opened this issue Aug 29, 2023 · 2 comments
Labels
feature Feature request or proposal flakes

Comments

@9999years
Copy link
Contributor

There's currently (Nix 2.17.0) no way to run a single flake check.

For example, with the given flake.nix:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (
      system: let
        pkgs = import nixpkgs {
          inherit system;
        };
      in {
        checks = {
          my-check = pkgs.runCommand "my-check" {} "echo hello > $out";
        };
      }
    );
}

The only way to build the check my-check is with nix flake check, which builds every check (and packages, and other stuff).

Unlike nix build, nix shell, and nix develop, nix flake check doesn't allow specifying a check:

$ nix flake check .#my-check
error: unexpected fragment 'my-check' in flake reference '.#my-check'

As a workaround, nix build can be used, but it requires specifying the full attribute path, including the current architecture: nix build .#checks.aarch64-darwin.my-check.

Describe the solution you'd like
nix flake check could gain a mode to run individual checks with fragments, like nix flake check .#my-check. Alternatively, to match nix build, nix shell, and nix develop, we could introduce a nix check command.

@9999years 9999years added the feature Feature request or proposal label Aug 29, 2023
@roberth roberth added the flakes label Aug 30, 2023
vimpostor added a commit to vimpostor/blobdrop that referenced this issue Sep 7, 2024
Unfortunately it is impossible to run both check steps individually [0],
which would have allowed us to map the concurrent builds to the CI job
level.
Now this way it will be a bit confusing as both jobs will run
concurrently (but in the same CI job) and their stdout will race against
each other for maximum confusion, so the following output is possible:

```
The C compiler identification is GNU 14.2.0
The C compiler identification is Clang 18.1.8
The CXX compiler identification is GNU 14.2.0
The CXX compiler identification is Clang 18.1.8
```

And thus it will also not be possible to directly see which of the two
caused a compiler error.
Fortunately I do not care too much as it is easy for me to run the build
locally for just one of both compilers.

[0] NixOS/nix#8881
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-flake-check-for-current-system-only/18366/4

@tmplt
Copy link
Member

tmplt commented Oct 22, 2024

Anecdotally, nix run .#checks.<arch>.my-check.driver works for pkgs.testers.runNixOSTest, but only if they are trivial.

I have a multi-node Slurm test (i.e. performs intra-node network operations) that passes in a nix flake check but fails in the nix run approach above.


This feature is rather necessary for complex CI projects. I'd love to see it implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal flakes
Projects
None yet
Development

No branches or pull requests

4 participants