2022-08-08 10:49:12 -05:00
{
description = "Development environments on your infrastructure" ;
inputs = {
2025-01-28 16:38:37 +01:00
nixpkgs . url = "github:nixos/nixpkgs/nixos-24.11" ;
2025-03-11 16:23:33 +01:00
nixpkgs-unstable . url = "github:nixos/nixpkgs/nixos-unstable" ;
2024-07-10 13:13:19 -05:00
nixpkgs-pinned . url = "github:nixos/nixpkgs/5deee6281831847857720668867729617629ef1f" ;
2022-08-08 10:49:12 -05:00
flake-utils . url = "github:numtide/flake-utils" ;
2024-07-10 13:13:19 -05:00
pnpm2nix = {
2025-01-22 05:34:53 +01:00
url = "github:ThomasK33/pnpm2nix-nzbr" ;
2024-07-10 13:13:19 -05:00
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" ;
};
2022-08-08 10:49:12 -05:00
};
2025-01-28 16:38:37 +01:00
outputs =
{
self ,
nixpkgs ,
nixpkgs-pinned ,
2025-03-11 16:23:33 +01:00
nixpkgs-unstable ,
2025-01-28 16:38:37 +01:00
flake-utils ,
drpc ,
pnpm2nix ,
}:
flake-utils . lib . eachDefaultSystem (
system :
2022-08-08 10:49:12 -05:00
let
2024-07-10 13:13:19 -05:00
pkgs = import nixpkgs {
inherit system ;
2025-03-11 16:23:33 +01:00
# Workaround for: google-chrome has an unfree license (‘ unfree’ ), refusing to evaluate.
2024-07-10 13:13:19 -05:00
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 ;
};
2025-03-11 16:23:33 +01:00
unstablePkgs = import nixpkgs-unstable {
inherit system ;
# Workaround for: terraform has an unfree license (‘ bsl11’ ), refusing to evaluate.
config . allowUnfreePredicate =
pkg :
builtins . elem ( pkgs . lib . getName pkg ) [
"terraform"
];
};
2025-01-28 16:38:37 +01:00
formatter = pkgs . nixfmt-rfc-style ;
2025-01-15 19:16:40 +01:00
nodejs = pkgs . nodejs_20 ;
2025-01-22 05:34:53 +01:00
pnpm = pkgs . pnpm_9 . override {
2025-01-28 16:38:37 +01:00
inherit nodejs ; # Ensure it points to the above nodejs version
2025-01-22 05:34:53 +01:00
};
2023-08-17 21:19:36 -05:00
# Check in https://search.nixos.org/packages to find new packages.
2023-08-18 19:29:24 +01:00
# Use `nix --extra-experimental-features nix-command --extra-experimental-features flakes flake update`
# to update the lock file if packages are out-of-date.
2023-08-21 11:58:34 +01:00
# From https://nixos.wiki/wiki/Google_Cloud_SDK
2025-01-28 16:38:37 +01:00
gdk = pkgs . google-cloud-sdk . withExtraComponents [
pkgs . google-cloud-sdk . components . gke-gcloud-auth-plugin
];
2023-08-21 11:58:34 +01:00
2024-09-24 18:27:07 +05:30
proto_gen_go_1_30 = pkgs . buildGoModule rec {
name = "protoc-gen-go" ;
owner = "protocolbuffers" ;
repo = "protobuf-go" ;
2024-10-29 12:57:13 -05:00
rev = "v1.30.0" ;
2024-09-24 18:27:07 +05:30
src = pkgs . fetchFromGitHub {
2025-01-28 16:38:37 +01:00
inherit owner repo rev ;
2024-09-24 18:27:07 +05:30
# Updated with ./scripts/update-flake.sh`.
sha256 = "sha256-GTZQ40uoi62Im2F4YvlZWiSNNJ4fEAkRojYa0EYz9HU=" ;
};
subPackages = [ "cmd/protoc-gen-go" ];
vendorHash = null ;
};
2025-02-04 15:10:10 +00:00
# Packages required to build the frontend
frontendPackages =
with pkgs ;
[
cairo
pango
pixman
libpng
libjpeg
giflib
librsvg
python312Packages . setuptools # Needed for node-gyp
]
++ ( lib . optionals stdenv . targetPlatform . isDarwin [
darwin . apple_sdk . frameworks . Foundation
xcbuild
]);
2024-05-06 18:21:20 -04:00
# The minimal set of packages to build Coder.
2025-02-04 15:10:10 +00:00
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
2025-03-13 21:45:11 +05:00
cosign
2025-02-04 15:10:10 +00:00
delve
dive
drpc . defaultPackage . ${ system }
formatter
fzf
2025-02-05 11:25:20 +01:00
gawk
2025-02-04 15:10:10 +00:00
gcc13
gdk
getopt
gh
git
2025-05-07 21:53:06 +02:00
git-lfs
2025-02-04 15:10:10 +00:00
( lib . optionalDrvAttr stdenv . isLinux glibcLocales )
gnumake
gnused
2025-02-04 17:14:03 +01:00
gnugrep
2025-02-05 11:25:20 +01:00
gnutar
2025-04-16 20:11:02 +02:00
unstablePkgs . go_1_24
2025-07-01 15:39:29 +02:00
gofumpt
2025-02-04 15:10:10 +00:00
go-migrate
( pinnedPkgs . golangci-lint )
gopls
gotestsum
2025-03-11 13:49:03 +01:00
hadolint
2025-02-04 15:10:10 +00:00
jq
kubectl
kubectx
kubernetes-helm
2025-05-20 17:07:50 +02:00
lazydocker
2025-02-04 15:10:10 +00:00
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
2025-03-13 21:45:11 +05:00
syft
2025-03-11 16:23:33 +01:00
unstablePkgs . terraform
2025-02-04 15:10:10 +00:00
typos
2025-02-05 11:25:20 +01:00
which
2025-02-04 15:10:10 +00:00
# Needed for many LD system libs!
( lib . optional stdenv . isLinux util-linux )
vim
wget
yq-go
zip
zsh
zstd
]
++ frontendPackages ;
2024-01-31 17:27:11 +03:00
2025-01-29 10:38:06 +01:00
docker = pkgs . callPackage ./nix/docker.nix { };
2024-05-06 18:21:20 -04:00
# buildSite packages the site directory.
buildSite = pnpm2nix . packages . ${ system } . mkPnpmPackage {
2025-01-22 05:34:53 +01:00
inherit nodejs pnpm ;
2025-01-15 19:16:40 +01:00
2024-05-06 18:21:20 -04:00
src = ./site/. ;
# Required for the `canvas` package!
2025-02-04 15:10:10 +00:00
extraBuildInputs = frontendPackages ;
2024-05-06 18:21:20 -04:00
installInPlace = true ;
distDir = "out" ;
2024-01-31 17:27:11 +03:00
};
2024-05-06 18:21:20 -04:00
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.
2025-01-28 16:38:37 +01:00
buildFat =
osArch :
2025-04-16 20:11:02 +02:00
unstablePkgs . buildGo124Module {
2024-05-06 18:21:20 -04:00
name = "coder- ${ osArch } " ;
2024-05-13 13:01:28 +00:00
# Updated with ./scripts/update-flake.sh`.
2024-05-06 18:21:20 -04:00
# This should be updated whenever go.mod changes!
2025-03-11 16:23:33 +01:00
vendorHash = "sha256-6sdvX0Wglj0CZiig2VD45JzuTcxwg7yrGoPPQUYvuqU=" ;
2024-05-06 18:21:20 -04:00
proxyVendor = true ;
src = ./. ;
2025-01-28 16:38:37 +01:00
nativeBuildInputs = with pkgs ; [
getopt
openssl
zstd
];
2024-05-06 18:21:20 -04:00
preBuild = ''
# Replaces /usr/bin/env with an absolute path to the interpreter.
patchShebangs ./scripts
'' ;
buildPhase = ''
runHook preBuild
# Unpack the site contents.
2025-01-15 19:25:36 +01:00
mkdir -p ./site/out ./site/node_modules/
2024-05-06 18:21:20 -04:00
cp -r ${ buildSite . out } /* ./site/out
2025-01-15 19:25:36 +01:00
touch ./site/node_modules/.installed
2024-05-06 18:21:20 -04:00
# Build and copy the binary!
export CODER_FORCE_VERSION= ${ version }
2025-01-15 19:25:36 +01:00
# 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 }
2024-05-06 18:21:20 -04:00
'' ;
installPhase = ''
mkdir -p $out/bin
cp -r ./build/coder_ ${ osArch } $out/bin/coder
'' ;
};
2023-08-18 10:58:52 -05:00
in
2025-03-11 13:49:03 +01:00
# "Keep in mind that you need to use the same version of playwright in your node playwright project as in your nixpkgs, or else playwright will try to use browsers versions that aren't installed!"
# - https://nixos.wiki/wiki/Playwright
assert pkgs . lib . assertMsg
(
( pkgs . lib . importJSON ./site/package.json ) . devDependencies . "@playwright/test"
== pkgs . playwright-driver . version
)
"There is a mismatch between the playwright versions in the ./nix.flake and the ./site/package.json file. Please make sure that they use the exact same version." ;
2025-01-28 16:38:37 +01:00
rec {
inherit formatter ;
2025-01-15 19:16:40 +01:00
devShells = {
default = pkgs . mkShell {
buildInputs = devShellPackages ;
2025-01-30 17:47:19 +01:00
PLAYWRIGHT_BROWSERS_PATH = pkgs . playwright-driver . browsers ;
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = true ;
2025-01-15 17:14:55 +01:00
2025-01-28 16:38:37 +01:00
LOCALE_ARCHIVE =
with pkgs ;
lib . optionalDrvAttr stdenv . isLinux " ${ glibcLocales } /lib/locale/locale-archive" ;
2025-02-04 15:10:10 +00:00
NODE_OPTIONS = "--max-old-space-size=8192" ;
GOPRIVATE = "coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder" ;
2025-01-15 19:16:40 +01:00
};
2024-05-06 18:21:20 -04:00
};
2025-01-15 19:16:40 +01:00
2025-01-28 16:38:37 +01:00
packages =
{
default = packages . ${ system } ;
2024-05-06 18:21:20 -04:00
2025-01-28 16:38:37 +01:00
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 {
2025-01-30 17:47:19 +01:00
dev_image = docker . buildNixShellImage rec {
2025-01-28 16:38:37 +01:00
name = "codercom/oss-dogfood-nix" ;
tag = "latest- ${ system } " ;
2025-01-30 17:47:19 +01:00
# (ThomasK33): Workaround for images with too many layers (>64 layers) causing sysbox
# to have issues on dogfood envs.
2025-01-29 10:38:06 +01:00
maxLayers = 32 ;
2025-01-30 17:47:19 +01:00
uname = "coder" ;
homeDirectory = "/home/ ${ uname } " ;
2025-03-11 13:49:03 +01:00
releaseName = version ;
2025-01-30 17:47:19 +01:00
2025-01-28 16:38:37 +01:00
drv = devShells . default . overrideAttrs ( oldAttrs : {
2025-01-29 10:38:06 +01:00
buildInputs =
2025-01-30 17:47:19 +01:00
( with pkgs ; [
2025-01-29 10:38:06 +01:00
coreutils
2025-03-11 13:49:03 +01:00
nix . out
2025-01-30 17:47:19 +01:00
curl . bin # Ensure the actual curl binary is included in the PATH
glibc . bin # Ensure the glibc binaries are included in the PATH
2025-02-04 15:10:10 +00:00
jq . bin
2025-01-30 17:47:19 +01:00
binutils # ld and strings
filebrowser # Ensure that we're not redownloading filebrowser on each launch
2025-02-04 15:10:10 +00:00
systemd . out
service-wrapper
docker_26
shadow . out
su
2025-02-05 11:25:20 +01:00
ncurses . out # clear
2025-02-04 15:10:10 +00:00
unzip
2025-02-05 11:25:20 +01:00
zip
gzip
2025-02-18 16:24:47 +01:00
procps # free
2025-01-30 17:47:19 +01:00
])
++ oldAttrs . buildInputs ;
2025-01-28 16:38:37 +01:00
});
};
});
2023-08-18 10:58:52 -05:00
}
);
}