forked from crossplane/crossplane
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
236 lines (218 loc) · 6.79 KB
/
flake.nix
File metadata and controls
236 lines (218 loc) · 6.79 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# New to Nix? Start here:
# Language basics: https://nix.dev/tutorials/nix-language
# Flakes intro: https://zero-to-nix.com/concepts/flakes
{
description = "Crossplane - The cloud native control plane framework";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
# TODO(negz): Unpin once https://github.com/nix-community/gomod2nix/pull/231 is released.
gomod2nix = {
url = "github:nix-community/gomod2nix/75c2866d585a75a1b30c634dbd7c2dcce5a6c3a7";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
gomod2nix,
}:
let
# Set by CI to override the auto-generated dev version.
buildVersion = null;
# Platforms we build Go binaries for.
goPlatforms = [
{
os = "linux";
arch = "amd64";
}
{
os = "linux";
arch = "arm64";
}
{
os = "linux";
arch = "arm";
}
{
os = "linux";
arch = "ppc64le";
}
{
os = "darwin";
arch = "arm64";
}
{
os = "darwin";
arch = "amd64";
}
{
os = "windows";
arch = "amd64";
}
];
# Platforms we build OCI images for (Linux only).
imagePlatforms = builtins.filter (p: p.os == "linux") goPlatforms;
# Systems where Nix runs (dev machines, CI).
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# Semantic version for binaries, images, and Helm chart. Uses buildVersion
# if set by CI, otherwise generates a dev version from git metadata.
# (self ? shortRev tests if the attribute exists - clean commits have
# shortRev, uncommitted changes have dirtyShortRev.)
version =
if buildVersion != null then
buildVersion
else if self ? shortRev then
"v0.0.0-${builtins.toString self.lastModified}-${self.shortRev}"
else
"v0.0.0-${builtins.toString self.lastModified}-${self.dirtyShortRev}";
# Helpers for per-system outputs.
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: forSystem system f);
forSystem =
system: f:
f {
inherit system;
pkgs = import nixpkgs {
inherit system;
overlays = [ gomod2nix.overlays.default ];
};
};
in
{
# Build outputs (nix build).
packages = forAllSystems (
{ pkgs, ... }:
let
build = import ./nix/build.nix { inherit pkgs self; };
in
{
default = build.release {
inherit
version
goPlatforms
imagePlatforms
;
};
}
);
# CI checks (nix flake check).
checks = forAllSystems (
{ pkgs, ... }:
let
checks = import ./nix/checks.nix { inherit pkgs self; };
in
{
test = checks.test { inherit version; };
test-apis = checks.testAPIs { inherit version; };
generate = checks.generate { inherit version; };
generate-apis = checks.generateAPIs { inherit version; };
go-lint = checks.goLint { inherit version; };
go-lint-apis = checks.goLintAPIs { inherit version; };
helm-lint = checks.helmLint { };
shell-lint = checks.shellLint { };
nix-lint = checks.nixLint { };
}
);
# Development commands (nix run .#<app>).
apps = forAllSystems (
{ pkgs, ... }:
let
build = import ./nix/build.nix { inherit pkgs self; };
apps = import ./nix/apps.nix { inherit pkgs; };
nativeArch = if pkgs.stdenv.hostPlatform.isAarch64 then "arm64" else "amd64";
images = build.images {
inherit version;
platforms = imagePlatforms;
};
in
{
test = apps.test { };
lint = apps.lint { };
generate = apps.generate { };
tidy = apps.tidy { };
e2e = apps.e2e {
inherit version;
inherit (images."linux-${nativeArch}") image;
bin = build.e2e { inherit version; };
};
hack = apps.hack {
inherit version;
inherit (images."linux-${nativeArch}") image;
chart = build.chart { inherit version; };
};
unhack = apps.unhack { };
push-images = apps.pushImages {
inherit version;
inherit images;
platforms = imagePlatforms;
};
push-artifacts = apps.pushArtifacts {
inherit version;
release = build.release {
inherit version goPlatforms imagePlatforms;
};
};
promote-images = apps.promoteImages { };
promote-artifacts = apps.promoteArtifacts { };
stream-image = apps.streamImage {
imageArgs = build.imageArgs {
inherit version;
arch = nativeArch;
};
};
}
);
# Development shell (nix develop).
devShells = forAllSystems (
{ pkgs, ... }:
{
default = pkgs.mkShell {
buildInputs = [
pkgs.coreutils
pkgs.gnused
pkgs.ncurses
pkgs.go
pkgs.golangci-lint
pkgs.kubectl
pkgs.kubernetes-helm
pkgs.kind
pkgs.docker-client
pkgs.gotestsum
pkgs.awscli2
pkgs.gomod2nix
# Code generation
pkgs.buf
pkgs.helm-docs
pkgs.goverter
pkgs.protoc-gen-go
pkgs.protoc-gen-go-grpc
pkgs.kubernetes-controller-tools
# Nix
pkgs.nixfmt-rfc-style
];
shellHook = ''
export PS1='\[\033[38;2;243;128;123m\][cros\[\033[38;2;255;205;60m\]spla\[\033[38;2;53;208;186m\]ne]\[\033[0m\] \w \$ '
source <(kubectl completion bash 2>/dev/null)
source <(helm completion bash 2>/dev/null)
source <(kind completion bash 2>/dev/null)
alias k=kubectl
echo "Crossplane development shell ($(go version | cut -d' ' -f3))"
echo ""
echo " nix run .#test nix run .#generate"
echo " nix run .#lint nix run .#tidy"
echo " nix run .#e2e nix run .#hack"
echo " nix run .#stream-image | docker load"
echo ""
echo " nix build nix flake check"
echo ""
'';
};
}
);
};
}