summaryrefslogtreecommitdiff
path: root/parts/ci.nix
blob: 839f53569e152af59dd76fff02d10a20ac8fe680 (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
{
  config,
  inputs,
  self,
  withSystem,
  ...
}: let
  ciSystems = [
    "x86_64-linux"
    "aarch64-linux"
  ];
in {
  imports = [
    inputs.effects.flakeModule
  ];

  herculesCI = {lib, ...} @ herculesCI: {
    inherit ciSystems;

    onPush.default = let
      inherit (builtins) elem;
      inherit (lib) filterAttrs mapAttrs mkForce;

      amd64 = ["x86_64-linux"];

      findCompatible = systems: filterAttrs (s: _: elem s systems);
      findCompatibleCfgs = systems: filterAttrs (_: v: elem v.pkgs.system systems);
      buildCfgs = mapAttrs (_: v: v.config.system.build.toplevel);
      buildHMUsers = mapAttrs (_: mapAttrs (_: v: v.activationPackage));
      #evalCfgs = mapAttrs (_: v: seq v.config.system.build.toplevel v.pkgs.emptyFile);
    in
      mkForce {
        outputs = {
          checks = findCompatible amd64 self.checks;
          devShells = findCompatible amd64 self.devShells;
          homeConfigurations = buildHMUsers (findCompatible amd64 self.homeConfigurations);
          nixosConfigurations = buildCfgs (findCompatibleCfgs ciSystems self.nixosConfigurations);
        };
      };

    onSchedule = let
      when = {
        hour = [0];
        minute = 0;
      };

      mkUpdateEffect = inputs: pullRequestTitle: let
        cfg = config.hercules-ci.flake-update;
      in
        withSystem cfg.effect.system ({hci-effects, ...}:
          hci-effects.flakeUpdate {
            gitRemote = herculesCI.config.repo.remoteHttpUrl;
            user = "x-access-token";
            autoMergeMethod = "rebase";
            commitSummary = pullRequestTitle;
            module = cfg.effect.settings;
            inherit pullRequestTitle inputs;
            inherit (cfg) updateBranch forgeType createPullRequest pullRequestBody;
          });
    in {
      nixpkgs-update = {
        inherit when;

        outputs.effects = {
          update = mkUpdateEffect ["nixpkgs" "nixpkgs-stable"] "flake: update nixpkgs inputs";
        };
      };

      flake-update = {
        when = when // {dayOfMonth = [1 8 15 22 29];};

        outputs.effects = {
          update = mkUpdateEffect [] "flake: update all inputs";
        };
      };
    };
  };
}