-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
206 lines (189 loc) · 5.58 KB
/
flake.nix
File metadata and controls
206 lines (189 loc) · 5.58 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
# New to Nix? Start here:
# Language basics: https://nix.dev/tutorials/nix-language
# Flakes intro: https://zero-to-nix.com/concepts/flakes
{
description = "Crossplane CLI";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# 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,
nixpkgs-unstable,
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";
}
];
# Systems where Nix runs (dev machines, CI).
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# Semantic version for binaries. 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
(_final: prev: {
# Allow use of pkgs.unstable.<package-name> to pull individual
# packages from nixpkgs-unstable.
unstable = import nixpkgs-unstable {
inherit (prev.stdenv.hostPlatform) system;
};
})
];
};
};
in
{
# Build outputs (nix build).
packages = forAllSystems (
{ pkgs, ... }:
let
build = import ./nix/build.nix { inherit pkgs self; };
in
{
default = build.release {
inherit
version
goPlatforms
;
};
}
);
# CI checks (nix flake check).
checks = forAllSystems (
{ pkgs, ... }:
let
checks = import ./nix/checks.nix { inherit pkgs self; };
in
{
test = checks.test { inherit version; };
generate = checks.generate { inherit version; };
go-lint = checks.goLint { inherit version; };
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; };
in
{
test = apps.test { };
lint = apps.lint { };
generate = apps.generate { };
tidy = apps.tidy { };
push-artifacts = apps.pushArtifacts {
inherit version;
release = build.release {
inherit version goPlatforms;
};
};
promote-artifacts = apps.promoteArtifacts { };
}
);
# Development shell (nix develop).
devShells = forAllSystems (
{ pkgs, ... }:
{
default = pkgs.mkShell {
buildInputs = [
pkgs.coreutils
pkgs.gnused
pkgs.ncurses
pkgs.unstable.go_1_26
pkgs.unstable.golangci-lint
pkgs.kubectl
pkgs.kind
pkgs.docker-client
pkgs.gotestsum
pkgs.awscli2
pkgs.gomod2nix
# Code generation
pkgs.buf
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 <(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 ""
echo " nix build nix flake check"
echo ""
'';
};
}
);
};
}