summaryrefslogtreecommitdiff
path: root/parts/ci.nix
blob: 1f74d15345f4c2f9bd8d9e53e8f8635bc3ebed8f (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
81
82
83
84
85
86
{
  config,
  inputs,
  self,
  withSystem,
  ...
}: let
  ciSystems = [
    "x86_64-linux"
    "aarch64-linux"
  ];
in {
  imports = [
    inputs.hercules-ci-effects.flakeModule
  ];

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

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

      findCompatible = filterAttrs (s: _: elem s ciSystems);
      findCompatible' = filterAttrs (_: v: elem v.pkgs.system ciSystems);
      findSystem = system: filterAttrs (s: _: s == system);
      #buildCfgs = mapAttrs (_: v: v.config.system.build.toplevel);
      evalCfgs = mapAttrs (_: v: seq v.config.system.build.toplevel v.pkgs.emptyFile);
    in
      mkForce {
        outputs = {
          checks = findCompatible self.checks;
          devShells = findSystem "x86_64-linux" self.devShells;
          homeConfigurations = findSystem "x86_64-linux" self.homeConfigurations;
          nixosConfigurations = evalCfgs (findCompatible' self.nixosConfigurations);
        };
      };

    onSchedule = let
      inherit (lib) mkForce mapAttrs optionalAttrs;

      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;
          });

      mkUpdates = mapAttrs (n: {
        inputs ? [],
        dayOfMonth ? [],
        msg ? "all",
      }:
        mkForce {
          when =
            {
              hour = [0];
              minute = 0;
            }
            // optionalAttrs (dayOfMonth != []) {inherit dayOfMonth;};

          outputs = {
            effects.${n} = mkUpdateEffect inputs "flake: update ${msg} inputs";
          };
        });
    in
      mkUpdates {
        nixpkgs-update = {
          inputs = ["nixpkgs" "nixpkgs-stable"];
          msg = "nixpkgs";
        };

        flake-update = {
          dayOfMonth = [1 8 15 22 29];
          msg = "all";
        };
      };
  };
}