summaryrefslogtreecommitdiff
path: root/flake/ci.nix
blob: e8a13737521d52a9537f9796b89907c94db32f52 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{
  config,
  lib,
  withSystem,
  self,
  ...
}:

{
  perSystem =
    { pkgs, ... }:
    {
      quickChecks = {
        actionlint = {
          dependencies = [ pkgs.actionlint ];
          script = "actionlint ${self}/.github/workflows/**";
        };

        deadnix = {
          dependencies = [ pkgs.deadnix ];
          script = "deadnix --fail ${self}";
        };

        just = {
          dependencies = [ pkgs.just ];
          script = ''
            cd ${self}
            just --check --fmt --unstable
            just --summary
          '';
        };

        nixfmt = {
          dependencies = [ pkgs.nixfmt-rfc-style ];
          script = "nixfmt --check ${self}/**/*.nix";
        };

        statix = {
          dependencies = [ pkgs.statix ];
          script = "statix check ${self}";
        };
      };
    };

  flake.hydraJobs =

    let
      # Architecture of "main" CI machine
      ciSystem = "x86_64-linux";

      derivFromCfg = deriv: deriv.config.system.build.toplevel or deriv.activationPackage;
      mapCfgsToDerivs = lib.mapAttrs (lib.const derivFromCfg);
    in

    lib.genAttrs config.systems (
      lib.flip withSystem (
        {
          system,
          self',
          ...
        }:

        let
          mapCfgsForSystem =
            cfgs: lib.filterAttrs (lib.const (deriv: deriv.system == system)) (mapCfgsToDerivs cfgs);
        in

        {
          darwinConfigurations = mapCfgsForSystem self.darwinConfigurations;
          homeConfigurations = mapCfgsForSystem self.homeConfigurations;
          nixosConfigurations = mapCfgsForSystem self.nixosConfigurations;
        }
        # I don't care to run these for each system, as they should be the same
        # and don't need to be cached
        // lib.optionalAttrs (system == ciSystem) {
          inherit (self') checks devShells;
        }
      )
    );
}