blob: 233d0ab90a56a69ccbcd6b231bc832f19230e472 (
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
workflowLib': {
config,
lib,
self,
...
}: let
cfg = config.nix2workflow;
inherit
(lib)
attrNames
concatLists
elem
filter
filterAttrs
literalExpression
mapAttrsToList
mdDoc
mkOption
recursiveUpdate
types
;
workflowLib = workflowLib' {inherit (cfg) platforms;};
inherit (workflowLib) mkMatrix mkMatrix';
supportedOutputs = [
"checks"
"devShells"
"nixosConfigurations"
"darwinConfigurations"
"homeConfigurations"
"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.either types.str (types.listOf 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 = attrNames cfg.platforms;
};
};
};
jobs = concatLists (
mapAttrsToList (
output: value: let
common =
recursiveUpdate
{
root = cfg.output;
inherit output;
}
(cfg.overrides.${output} or {});
flat = mkMatrix' common;
multi = mkMatrix common;
in
{
# TODO: maybe make this configurable? or follow flake-schemas?
# these are known "flat" values
"nixosConfigurations" = flat;
"darwinConfigurations" = flat;
"homeConfigurations" = flat;
}
.${output}
or multi
)
(filterAttrs (output: _: elem output supportedOutputs) cfg.output)
);
in {
options = {
nix2workflow = {
output = mkOption {
description = mdDoc "Root attribute for CI jobs";
type = types.lazyAttrsOf types.raw;
default = self;
example = literalExpression "hydraJobs";
};
platforms = mkOption {
description = mdDoc ''
an attrset that can map a nix system to an architecture and os supported by github
'';
type = types.nullOr (types.attrsOf (types.submodule platformMap));
default = null;
example = literalExpression ''
{
"x86_64-linux" = {
os = "ubuntu-latest";
arch = "x64";
};
"aarch64-linux" = {
os = "self-hosted";
arch = "aarch64";
};
"x86_64-darwin" = {
os = "macos-latest";
arch = "x64";
};
}
'';
};
exclude = mkOption {
description = mdDoc "outputs to exclude from matrix";
type = types.listOf types.str;
default = [];
example = literalExpression ''
{
nix2workflow.exclude = [
"packages.x86_64-linux.foo"
];
}
'';
};
overrides = mkOption {
description = mdDoc "overrides for mkMatrix args";
type = types.attrsOf (types.submodule overrides);
default = {};
example = literalExpression ''
{
nix2workflow.overrides = {
checks.systems = [ "x86_64-linux" ];
};
}
'';
};
};
};
config.flake.workflowMatrix = {
include = filter (job: !elem job.attr cfg.exclude) jobs;
};
}
|