/
flake.nix
150 lines (140 loc) · 4.67 KB
/
flake.nix
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
{
description = "Development environments on your infrastructure";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr";
drpc.url = "github:storj/drpc/v0.0.33";
};
outputs = { self, nixpkgs, flake-utils, drpc, pnpm2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
# Workaround for: terraform has an unfree license (‘bsl11’), refusing to evaluate.
pkgs = import nixpkgs { inherit system; config.allowUnfree = true; };
nodejs = pkgs.nodejs-18_x;
# 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 ]);
# The minimal set of packages to build Coder.
devShellPackages = with pkgs; [
# google-chrome is not available on OSX
(if pkgs.stdenv.hostPlatform.isDarwin then null else google-chrome)
# strace is not available on OSX
(if pkgs.stdenv.hostPlatform.isDarwin then null else strace)
bat
cairo
curl
delve
drpc.defaultPackage.${system}
gcc
gdk
getopt
gh
git
gnumake
gnused
go_1_21
go-migrate
golangci-lint
gopls
gotestsum
jq
kubectl
kubectx
kubernetes-helm
less
mockgen
nfpm
nodejs
nodejs.pkgs.pnpm
openssh
openssl
pango
pixman
pkg-config
playwright-driver.browsers
postgresql_13
protobuf
protoc-gen-go
ripgrep
sapling
shellcheck
shfmt
sqlc
terraform
typos
# Needed for many LD system libs!
util-linux
vim
wget
yq-go
zip
zsh
zstd
];
# buildSite packages the site directory.
buildSite = pnpm2nix.packages.${system}.mkPnpmPackage {
src = ./site/.;
# Required for the `canvas` package!
extraBuildInputs = with pkgs; [ pkgs.cairo pkgs.pango pkgs.pixman ];
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.buildGo121Module {
name = "coder-${osArch}";
# Updated with ./scripts/update-flake.sh`.
# This should be updated whenever go.mod changes!
vendorHash = "sha256-YOqgW5v7qXfOYcCQECZyJfoewChtQDfRCrTcr7Ui37Y=";
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
cp -r ${buildSite.out}/* ./site/out
# Build and copy the binary!
export CODER_FORCE_VERSION=${version}
make -j build/coder_${osArch}
'';
installPhase = ''
mkdir -p $out/bin
cp -r ./build/coder_${osArch} $out/bin/coder
'';
};
in
{
devShell = pkgs.mkShell {
buildInputs = devShellPackages;
shellHook = ''
export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers}
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true
'';
};
packages = {
all = pkgs.buildEnv {
name = "all-packages";
paths = devShellPackages;
};
site = buildSite;
# Copying `OS_ARCHES` from the Makefile.
linux_amd64 = buildFat "linux_amd64";
linux_arm64 = buildFat "linux_arm64";
darwin_amd64 = buildFat "darwin_amd64";
darwin_arm64 = buildFat "darwin_arm64";
windows_amd64 = buildFat "windows_amd64.exe";
windows_arm64 = buildFat "windows_arm64.exe";
};
}
);
}