forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
251 lines (230 loc) · 7.43 KB
/
flake.nix
File metadata and controls
251 lines (230 loc) · 7.43 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
{
description = "Development environments on your infrastructure";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-pinned.url = "github:nixos/nixpkgs/5deee6281831847857720668867729617629ef1f";
flake-utils.url = "github:numtide/flake-utils";
pnpm2nix = {
url = "github:ThomasK33/pnpm2nix-nzbr";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
drpc = {
url = "github:storj/drpc/v0.0.34";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-pinned,
flake-utils,
drpc,
pnpm2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
# Workaround for: terraform has an unfree license (‘bsl11’), refusing to evaluate.
config.allowUnfree = true;
};
# pinnedPkgs is used to pin packages that need to stay in sync with CI.
# Everything else uses unstable.
pinnedPkgs = import nixpkgs-pinned {
inherit system;
};
formatter = pkgs.nixfmt-rfc-style;
nodejs = pkgs.nodejs_20;
pnpm = pkgs.pnpm_9.override {
inherit nodejs; # Ensure it points to the above nodejs version
};
# Check in https://search.nixos.org/packages to find new packages.
# Use `nix --extra-experimental-features nix-command --extra-experimental-features flakes flake update`
# to update the lock file if packages are out-of-date.
# From https://nixos.wiki/wiki/Google_Cloud_SDK
gdk = pkgs.google-cloud-sdk.withExtraComponents [
pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin
];
proto_gen_go_1_30 = pkgs.buildGoModule rec {
name = "protoc-gen-go";
owner = "protocolbuffers";
repo = "protobuf-go";
rev = "v1.30.0";
src = pkgs.fetchFromGitHub {
inherit owner repo rev;
# Updated with ./scripts/update-flake.sh`.
sha256 = "sha256-GTZQ40uoi62Im2F4YvlZWiSNNJ4fEAkRojYa0EYz9HU=";
};
subPackages = [ "cmd/protoc-gen-go" ];
vendorHash = null;
};
# The minimal set of packages to build Coder.
devShellPackages = with pkgs; [
# google-chrome is not available on aarch64 linux
(lib.optionalDrvAttr (!stdenv.isLinux || !stdenv.isAarch64) google-chrome)
# strace is not available on OSX
(lib.optionalDrvAttr (!pkgs.stdenv.isDarwin) strace)
bat
cairo
curl
delve
dive
drpc.defaultPackage.${system}
formatter
fzf
gcc
gdk
getopt
gh
git
(lib.optionalDrvAttr stdenv.isLinux glibcLocales)
gnumake
gnused
go_1_22
go-migrate
(pinnedPkgs.golangci-lint)
gopls
gotestsum
jq
kubectl
kubectx
kubernetes-helm
lazygit
less
mockgen
moreutils
neovim
nfpm
nix-prefetch-git
nodejs
openssh
openssl
pango
pixman
pkg-config
playwright-driver.browsers
pnpm
postgresql_16
proto_gen_go_1_30
protobuf_23
ripgrep
shellcheck
(pinnedPkgs.shfmt)
sqlc
terraform
typos
# Needed for many LD system libs!
(lib.optional stdenv.isLinux util-linux)
vim
wget
yq-go
zip
zsh
zstd
];
# buildSite packages the site directory.
buildSite = pnpm2nix.packages.${system}.mkPnpmPackage {
inherit nodejs pnpm;
src = ./site/.;
# Required for the `canvas` package!
extraBuildInputs =
with pkgs;
[
cairo
pango
pixman
libpng
libjpeg
giflib
librsvg
python312Packages.setuptools
]
++ (lib.optionals stdenv.targetPlatform.isDarwin [
darwin.apple_sdk.frameworks.Foundation
xcbuild
]);
installInPlace = true;
distDir = "out";
};
version = "v0.0.0-nix-${self.shortRev or self.dirtyShortRev}";
# To make faster subsequent builds, you could extract the `.zst`
# slim bundle into it's own derivation.
buildFat =
osArch:
pkgs.buildGo122Module {
name = "coder-${osArch}";
# Updated with ./scripts/update-flake.sh`.
# This should be updated whenever go.mod changes!
vendorHash = "sha256-hJBNmHz9ZJLS/QTu8w8y1w/Yi45aSoaSeZ//ysllp6c=";
proxyVendor = true;
src = ./.;
nativeBuildInputs = with pkgs; [
getopt
openssl
zstd
];
preBuild = ''
# Replaces /usr/bin/env with an absolute path to the interpreter.
patchShebangs ./scripts
'';
buildPhase = ''
runHook preBuild
# Unpack the site contents.
mkdir -p ./site/out ./site/node_modules/
cp -r ${buildSite.out}/* ./site/out
touch ./site/node_modules/.installed
# Build and copy the binary!
export CODER_FORCE_VERSION=${version}
# Flagging 'site/node_modules/.installed' as an old file,
# as we do not want to trigger codegen during a build.
make -j -o 'site/node_modules/.installed' build/coder_${osArch}
'';
installPhase = ''
mkdir -p $out/bin
cp -r ./build/coder_${osArch} $out/bin/coder
'';
};
in
rec {
inherit formatter;
devShells = {
default = pkgs.mkShell {
buildInputs = devShellPackages;
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
LOCALE_ARCHIVE =
with pkgs;
lib.optionalDrvAttr stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
};
};
packages =
{
default = packages.${system};
proto_gen_go = proto_gen_go_1_30;
site = buildSite;
# Copying `OS_ARCHES` from the Makefile.
x86_64-linux = buildFat "linux_amd64";
aarch64-linux = buildFat "linux_arm64";
x86_64-darwin = buildFat "darwin_amd64";
aarch64-darwin = buildFat "darwin_arm64";
x86_64-windows = buildFat "windows_amd64.exe";
aarch64-windows = buildFat "windows_arm64.exe";
}
// (pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
dev_image = pkgs.dockerTools.buildNixShellImage {
name = "codercom/oss-dogfood-nix";
tag = "latest-${system}";
drv = devShells.default.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ pkgs.nix ];
});
};
});
}
);
}