|
4 | 4 | inputs = { |
5 | 5 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; |
6 | 6 | flake-utils.url = "github:numtide/flake-utils"; |
| 7 | + pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr"; |
7 | 8 | drpc.url = "github:storj/drpc/v0.0.33"; |
8 | 9 | }; |
9 | 10 |
|
10 | | - outputs = { self, nixpkgs, flake-utils, drpc }: |
| 11 | + outputs = { self, nixpkgs, flake-utils, drpc, pnpm2nix }: |
11 | 12 | flake-utils.lib.eachDefaultSystem (system: |
12 | 13 | let |
13 | 14 | # Workaround for: terraform has an unfree license (‘bsl11’), refusing to evaluate. |
14 | 15 | pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; |
15 | | - formatter = pkgs.nixpkgs-fmt; |
16 | 16 | nodejs = pkgs.nodejs-18_x; |
17 | | - yarn = pkgs.yarn.override { inherit nodejs; }; |
18 | 17 | # Check in https://search.nixos.org/packages to find new packages. |
19 | 18 | # Use `nix --extra-experimental-features nix-command --extra-experimental-features flakes flake update` |
20 | 19 | # to update the lock file if packages are out-of-date. |
21 | 20 |
|
22 | 21 | # From https://nixos.wiki/wiki/Google_Cloud_SDK |
23 | | - gdk = pkgs.google-cloud-sdk.withExtraComponents ([pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin]); |
| 22 | + gdk = pkgs.google-cloud-sdk.withExtraComponents ([ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]); |
24 | 23 |
|
| 24 | + # The minimal set of packages to build Coder. |
25 | 25 | devShellPackages = with pkgs; [ |
| 26 | + # google-chrome is not available on OSX |
| 27 | + (if pkgs.stdenv.hostPlatform.isDarwin then null else google-chrome) |
| 28 | + # strace is not available on OSX |
| 29 | + (if pkgs.stdenv.hostPlatform.isDarwin then null else strace) |
26 | 30 | bat |
27 | 31 | cairo |
28 | 32 | curl |
|
31 | 35 | gcc |
32 | 36 | gdk |
33 | 37 | getopt |
34 | | - git |
35 | 38 | gh |
| 39 | + git |
36 | 40 | gnumake |
37 | 41 | gnused |
38 | 42 | go_1_21 |
39 | 43 | go-migrate |
40 | 44 | golangci-lint |
41 | | - # google-chrome is not available on OSX |
42 | | - (if pkgs.stdenv.hostPlatform.isDarwin then null else google-chrome) |
43 | 45 | gopls |
44 | 46 | gotestsum |
45 | 47 | jq |
46 | 48 | kubectl |
47 | 49 | kubectx |
48 | 50 | kubernetes-helm |
49 | 51 | less |
50 | | - # Needed for many LD system libs! |
51 | | - util-linux |
52 | 52 | mockgen |
53 | 53 | nfpm |
54 | 54 | nodejs |
|
67 | 67 | shellcheck |
68 | 68 | shfmt |
69 | 69 | sqlc |
70 | | - # strace is not available on OSX |
71 | | - (if pkgs.stdenv.hostPlatform.isDarwin then null else strace) |
72 | 70 | terraform |
73 | 71 | typos |
| 72 | + # Needed for many LD system libs! |
| 73 | + util-linux |
74 | 74 | vim |
75 | 75 | wget |
76 | | - yarn |
77 | 76 | yq-go |
78 | 77 | zip |
79 | 78 | zsh |
80 | 79 | zstd |
81 | 80 | ]; |
82 | 81 |
|
83 | | - allPackages = pkgs.buildEnv { |
84 | | - name = "all-packages"; |
85 | | - paths = devShellPackages; |
| 82 | + # buildSite packages the site directory. |
| 83 | + buildSite = pnpm2nix.packages.${system}.mkPnpmPackage { |
| 84 | + src = ./site/.; |
| 85 | + # Required for the `canvas` package! |
| 86 | + extraBuildInputs = with pkgs; [ pkgs.cairo pkgs.pango pkgs.pixman ]; |
| 87 | + installInPlace = true; |
| 88 | + distDir = "out"; |
86 | 89 | }; |
| 90 | + |
| 91 | + version = "v0.0.0-nix-${self.shortRev or self.dirtyShortRev}"; |
| 92 | + |
| 93 | + # To make faster subsequent builds, you could extract the `.zst` |
| 94 | + # slim bundle into it's own derivation. |
| 95 | + buildFat = osArch: |
| 96 | + pkgs.buildGo121Module { |
| 97 | + name = "coder-${osArch}"; |
| 98 | + # Updated with ./scripts/update-flake.nix`. |
| 99 | + # This should be updated whenever go.mod changes! |
| 100 | + vendorHash = "sha256-pTRr85MtdlsI0iYGAwLAQ3QvtrDR8rDOynYx8FDaRy0="; |
| 101 | + proxyVendor = true; |
| 102 | + src = ./.; |
| 103 | + nativeBuildInputs = with pkgs; [ getopt openssl zstd ]; |
| 104 | + preBuild = '' |
| 105 | + # Replaces /usr/bin/env with an absolute path to the interpreter. |
| 106 | + patchShebangs ./scripts |
| 107 | + ''; |
| 108 | + buildPhase = '' |
| 109 | + runHook preBuild |
| 110 | +
|
| 111 | + # Unpack the site contents. |
| 112 | + mkdir -p ./site/out |
| 113 | + cp -r ${buildSite.out}/* ./site/out |
| 114 | +
|
| 115 | + # Build and copy the binary! |
| 116 | + export CODER_FORCE_VERSION=${version} |
| 117 | + make -j build/coder_${osArch} |
| 118 | + ''; |
| 119 | + installPhase = '' |
| 120 | + mkdir -p $out/bin |
| 121 | + cp -r ./build/coder_${osArch} $out/bin/coder |
| 122 | + ''; |
| 123 | + }; |
87 | 124 | in |
88 | 125 | { |
89 | | - defaultPackage = formatter; # or replace it with your desired default package. |
90 | 126 | devShell = pkgs.mkShell { |
91 | | - buildInputs = devShellPackages; |
92 | | - shellHook = '' |
93 | | - export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers} |
94 | | - export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true |
95 | | - ''; |
| 127 | + buildInputs = devShellPackages; |
| 128 | + shellHook = '' |
| 129 | + export PLAYWRIGHT_BROWSERS_PATH=${pkgs.playwright-driver.browsers} |
| 130 | + export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true |
| 131 | + ''; |
| 132 | + }; |
| 133 | + packages = { |
| 134 | + all = pkgs.buildEnv { |
| 135 | + name = "all-packages"; |
| 136 | + paths = devShellPackages; |
| 137 | + }; |
| 138 | + site = buildSite; |
| 139 | + |
| 140 | + # Copying `OS_ARCHES` from the Makefile. |
| 141 | + linux_amd64 = buildFat "linux_amd64"; |
| 142 | + linux_arm64 = buildFat "linux_arm64"; |
| 143 | + darwin_amd64 = buildFat "darwin_amd64"; |
| 144 | + darwin_arm64 = buildFat "darwin_arm64"; |
| 145 | + windows_amd64 = buildFat "windows_amd64.exe"; |
| 146 | + windows_arm64 = buildFat "windows_arm64.exe"; |
96 | 147 | }; |
97 | | - packages.all = allPackages; |
98 | 148 | } |
99 | 149 | ); |
100 | 150 | } |
0 commit comments