blob: 189dc69e681dcc5f848a3a718582815bf374a67a (
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
workflowLib': {
config,
lib,
self,
...
}: let
cfg = config.githubWorkflowGenerator;
inherit
(builtins)
attrNames
elem
;
inherit
(lib)
filter
getAttrs
mapAttrsToList
mdDoc
mkOption
literalExpression
types
;
workflowLib = workflowLib' (
{inherit self;}
// lib.mkIf (cfg.platforms != {}) {
inherit (cfg) platforms;
}
);
supportedOutputs = [
"apps"
"checks"
"devShells"
"darwinConfigurations"
"homeConfigurations"
"nixosConfigurations"
"packages"
];
platformMap = {
options = {
arch = mkOption {
description = mdDoc "the architecture of a system";
type = types.str;
default = null;
example = literalExpression "x86_64";
};
os = mkOption {
description = mdDoc "the name of an os supported by github runners";
type = types.str;
default = null;
example = literalExpression "ubuntu-latest";
};
};
};
overrides = {
options = {
systems = mkOption {
description = mdDoc "list of systems to build an output for";
type = types.listOf types.str;
default = builtins.attrNames cfg.platforms;
};
};
};
jobs = lib.concatLists (
mapAttrsToList (
output: _:
workflowLib.mkMatrix ({inherit output;} // cfg.overrides.${output} or {})
)
(getAttrs cfg.outputs self)
);
in {
options = {
githubWorkflowGenerator = {
outputs = mkOption {
description = mdDoc "outputs to include in workflow";
type = types.listOf types.str;
default = filter (output: elem output supportedOutputs) (attrNames self);
};
platforms = mkOption {
description = mdDoc ''
an attrset that can map a nix system to an architecture and os supported by github
'';
type = types.attrsOf (types.submodule platformMap);
default = {};
};
overrides = mkOption {
description = mdDoc "overrides for mkMatrix args";
type = types.attrsOf (types.submodule overrides);
default = {};
example = literalExpression ''
{
githubWorkflowGenerator.overrides = {
checks.systems = [ "x86_64-linux" ];
};
}
'';
};
};
};
config.flake.githubWorkflow = {
matrix.include = jobs;
};
}
|