28 system = stdenv.hostPlatform.system;
30 yarn' = yarn.override { inherit nodejs; };
31 defaultYarnOpts = [ "frozen-lockfile" "non-interactive" "no-progress" ];
34 x86_64-linux = "linux-x64";
35 aarch64-linux = "linux-arm64";
36 x86_64-darwin = "darwin-x64";
37 aarch64-darwin = "darwin-arm64";
38 }.${system} or (throw "Unsupported system ${system}");
40 esbuild' = esbuild.override {
41 buildGoModule = args: buildGoModule (args // rec {
43 src = fetchFromGitHub {
47 hash = "sha256-4TC1d5FOZHUMuEMTcTOBLZZM+sFUswhyblI5HVWyvPA=";
49 vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
53 # replaces esbuild's download script with a binary from nixpkgs
54 patchEsbuild = path: version: ''
55 mkdir -p ${path}/node_modules/esbuild/bin
56 jq "del(.scripts.postinstall)" ${path}/node_modules/esbuild/package.json | sponge ${path}/node_modules/esbuild/package.json
57 sed -i 's/${version}/${esbuild'.version}/g' ${path}/node_modules/esbuild/lib/main.js
58 ln -s -f ${esbuild'}/bin/esbuild ${path}/node_modules/esbuild/bin/esbuild
61 stdenv.mkDerivation (finalAttrs: {
62 pname = "openvscode-server";
65 src = fetchFromGitHub {
67 repo = "openvscode-server";
68 rev = "openvscode-server-v${finalAttrs.version}";
69 hash = "sha256-Yc16L13Z8AmsGoSFbvy+4+KBdHxvqLMwZLeU2/dAQVU=";
72 yarnCache = stdenv.mkDerivation {
73 name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
74 inherit (finalAttrs) src;
75 nativeBuildInputs = [ cacert yarn' git ];
79 yarn config set yarn-offline-mirror $out
80 find "$PWD" -name "yarn.lock" -printf "%h\n" | \
81 xargs -I {} yarn --cwd {} \
82 --frozen-lockfile --ignore-scripts --ignore-platform \
83 --ignore-engines --no-progress --non-interactive
90 outputHashMode = "recursive";
91 outputHashAlgo = "sha256";
92 outputHash = "sha256-89c6GYLT2RzHqwxBKegYqB6g5rEJ6/nH53cnfV7b0Ts=";
106 buildInputs = lib.optionals (!stdenv.hostPlatform.isDarwin) [ libsecret ]
107 ++ (with xorg; [ libX11 libxkbfile libkrb5 ])
108 ++ lib.optionals stdenv.hostPlatform.isDarwin [
116 # Patch out remote download of nodejs from build script
117 ./remove-node-download.patch
120 # Disable NAPI_EXPERIMENTAL to allow to build with Node.js≥18.20.0.
121 env.NIX_CFLAGS_COMPILE = "-DNODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT";
126 # remove all built-in extensions, as these are 3rd party extensions that
127 # get downloaded from vscode marketplace
128 jq --slurp '.[0] * .[1]' "product.json" <(
131 "builtInExtensions": []
134 ) | sponge product.json
140 # set default yarn opts
141 ${lib.concatMapStrings (option: ''
142 yarn --offline config set ${option}
145 # set offline mirror to yarn cache we created in previous steps
146 yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"
148 # set nodedir to prevent node-gyp from downloading headers
149 # taken from https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
150 mkdir -p $HOME/.node-gyp/${nodejs.version}
151 echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
152 ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
153 export npm_config_nodedir=${nodejs}
155 # use updated node-gyp. fixes the following error on Darwin:
156 # PermissionError: [Errno 1] Operation not permitted: '/usr/sbin/pkgutil'
157 export npm_config_node_gyp=${node-gyp}/lib/node_modules/node-gyp/bin/node-gyp.js
159 runHook postConfigure
165 # install dependencies
166 yarn --offline --ignore-scripts
168 # run yarn install everywhere, skipping postinstall so we can patch esbuild
169 find . -path "*node_modules" -prune -o \
170 -path "./*/*" -name "yarn.lock" -printf "%h\n" | \
171 xargs -I {} yarn --cwd {} \
172 --frozen-lockfile --offline --ignore-scripts --ignore-engines
174 ${patchEsbuild "./build" "0.12.6"}
175 ${patchEsbuild "./extensions" "0.11.23"}
177 # patch shebangs of node_modules to allow binary packages to build
178 patchShebangs ./remote/node_modules
180 # put ripgrep binary into bin so postinstall does not try to download it
181 find -path "*@vscode/ripgrep" -type d \
182 -execdir mkdir -p {}/bin \; \
183 -execdir ln -s ${ripgrep}/bin/rg {}/bin/rg \;
184 '' + lib.optionalString stdenv.hostPlatform.isDarwin ''
185 # use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
186 # (see issue #101229)
187 pushd ./remote/node_modules/@parcel/watcher
188 mkdir -p ./build/Release
189 mv ./prebuilds/darwin-x64/node.napi.glibc.node ./build/Release/watcher.node
190 jq "del(.scripts) | .gypfile = false" ./package.json | sponge ./package.json
193 export NODE_OPTIONS=--openssl-legacy-provider
195 # rebuild binaries, we use npm here, as yarn does not provide an alternative
196 # that would not attempt to try to reinstall everything and break our
198 npm --prefix ./remote rebuild --build-from-source
200 # run postinstall scripts after patching
201 find . -path "*node_modules" -prune -o \
202 -path "./*/*" -name "yarn.lock" -printf "%h\n" | \
203 xargs -I {} sh -c 'jq -e ".scripts.postinstall" {}/package.json >/dev/null && yarn --cwd {} postinstall --frozen-lockfile --offline || true'
206 yarn --offline gulp vscode-reh-web-${vsBuildTarget}-min
215 cp -R -T ../vscode-reh-web-${vsBuildTarget} $out
216 ln -s ${nodejs}/bin/node $out
222 inherit (nixosTests) openvscode-server;
226 description = "Run VS Code on a remote machine";
228 Run upstream VS Code on a remote machine with access through a modern web
229 browser from any device, anywhere.
231 homepage = "https://github.com/gitpod-io/openvscode-server";
232 license = lib.licenses.mit;
233 maintainers = with lib.maintainers; [ dguenther ghuntley emilytrau ];
234 platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
235 mainProgram = "openvscode-server";