aboutsummaryrefslogtreecommitdiff
path: root/root/nix/checks.nix
blob: 9a0bc16b74a7e828471ebea1ba7d94723259a5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ inputs, self, ... }:
{
  perSystem =
    {
      lib,
      pkgs,
      system,
      ...
    }:
    let
      mkCheck =
        prefix: key: value:
        lib.attrsets.nameValuePair "${prefix}-${key}" value;
      devshells = lib.attrsets.mapAttrs' (mkCheck "devshell") self.devShells."${system}";
      packages = lib.attrsets.mapAttrs' (mkCheck "build") self.packages."${system}";

      nixos =
        let
          isCurrentSystem = _: conf: conf.pkgs.stdenv.hostPlatform.system == system;
          nixos = lib.attrsets.filterAttrs isCurrentSystem self.nixosConfigurations;
        in
        lib.attrsets.mapAttrs' (mkCheck "nixos") (
          lib.attrsets.mapAttrs (_: conf: conf.config.system.build.toplevel) nixos
        );
    in
    {
      checks =
        packages
        // nixos
        // devshells
        // {
          root-lint =
            let
              treefmt = pkgs.callPackage ./_treefmt.nix { treefmt-nix = inputs.treefmt-nix; };
            in
            pkgs.stdenvNoCC.mkDerivation {
              name = "root-lint";
              version = "0.0.1";

              src = lib.fileset.toSource {
                root = ../../.;
                fileset = lib.fileset.unions [
                  ../../flake.lock
                  ../../flake.nix
                  ../../README.md
                  ../../root
                ];
              };

              buildPhase = ''
                "${treefmt}/bin/treefmt" --ci
                touch "$out"
              '';
            };
        };
    };
}