2023-06-13 15:07:58 +02:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, buildGoModule
|
|
|
|
, makeWrapper
|
|
|
|
, cacert
|
|
|
|
, moreutils
|
|
|
|
, jq
|
|
|
|
, git
|
|
|
|
, pkg-config
|
|
|
|
, yarn
|
|
|
|
, python3
|
|
|
|
, esbuild
|
|
|
|
, nodejs
|
2023-10-15 00:43:01 +02:00
|
|
|
, node-gyp
|
2023-06-13 15:07:58 +02:00
|
|
|
, libsecret
|
2023-10-15 00:43:01 +02:00
|
|
|
, libkrb5
|
2023-06-13 15:07:58 +02:00
|
|
|
, xorg
|
|
|
|
, ripgrep
|
|
|
|
, AppKit
|
|
|
|
, Cocoa
|
|
|
|
, Security
|
|
|
|
, cctools
|
|
|
|
, nixosTests
|
|
|
|
}:
|
2021-11-07 21:54:56 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
system = stdenv.hostPlatform.system;
|
|
|
|
|
|
|
|
yarn' = yarn.override { inherit nodejs; };
|
2023-06-13 15:07:58 +02:00
|
|
|
defaultYarnOpts = [ "frozen-lockfile" "non-interactive" "no-progress" ];
|
2021-11-07 21:54:56 +01:00
|
|
|
|
|
|
|
vsBuildTarget = {
|
|
|
|
x86_64-linux = "linux-x64";
|
|
|
|
aarch64-linux = "linux-arm64";
|
2022-04-05 20:45:11 +02:00
|
|
|
x86_64-darwin = "darwin-x64";
|
|
|
|
aarch64-darwin = "darwin-arm64";
|
2021-11-07 21:54:56 +01:00
|
|
|
}.${system} or (throw "Unsupported system ${system}");
|
|
|
|
|
2023-01-28 05:20:00 +01:00
|
|
|
esbuild' = esbuild.override {
|
|
|
|
buildGoModule = args: buildGoModule (args // rec {
|
2023-10-15 00:43:01 +02:00
|
|
|
version = "0.17.14";
|
2023-01-28 05:20:00 +01:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "evanw";
|
|
|
|
repo = "esbuild";
|
|
|
|
rev = "v${version}";
|
2023-10-15 00:43:01 +02:00
|
|
|
hash = "sha256-4TC1d5FOZHUMuEMTcTOBLZZM+sFUswhyblI5HVWyvPA=";
|
2023-01-28 05:20:00 +01:00
|
|
|
};
|
|
|
|
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-11-07 21:54:56 +01:00
|
|
|
# replaces esbuild's download script with a binary from nixpkgs
|
2023-06-13 15:07:58 +02:00
|
|
|
patchEsbuild = path: version: ''
|
2021-11-07 21:54:56 +01:00
|
|
|
mkdir -p ${path}/node_modules/esbuild/bin
|
|
|
|
jq "del(.scripts.postinstall)" ${path}/node_modules/esbuild/package.json | sponge ${path}/node_modules/esbuild/package.json
|
2023-01-28 05:20:00 +01:00
|
|
|
sed -i 's/${version}/${esbuild'.version}/g' ${path}/node_modules/esbuild/lib/main.js
|
|
|
|
ln -s -f ${esbuild'}/bin/esbuild ${path}/node_modules/esbuild/bin/esbuild
|
2021-11-07 21:54:56 +01:00
|
|
|
'';
|
2023-06-13 15:07:58 +02:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2021-11-07 21:54:56 +01:00
|
|
|
pname = "openvscode-server";
|
2023-10-15 00:43:01 +02:00
|
|
|
version = "1.84.0";
|
2021-11-07 21:54:56 +01:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "gitpod-io";
|
|
|
|
repo = "openvscode-server";
|
2023-06-13 15:07:58 +02:00
|
|
|
rev = "openvscode-server-v${finalAttrs.version}";
|
2023-10-15 00:43:01 +02:00
|
|
|
hash = "sha256-kYKvJrHWKHDIqJsN0j1WFN3OBWwEyNgY5hjNHBg+kKQ=";
|
2021-11-07 21:54:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
yarnCache = stdenv.mkDerivation {
|
2023-06-13 15:07:58 +02:00
|
|
|
name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
|
|
|
|
inherit (finalAttrs) src;
|
2023-02-03 08:04:56 +01:00
|
|
|
nativeBuildInputs = [ cacert yarn' git ];
|
2021-11-07 21:54:56 +01:00
|
|
|
buildPhase = ''
|
|
|
|
export HOME=$PWD
|
|
|
|
|
|
|
|
yarn config set yarn-offline-mirror $out
|
|
|
|
find "$PWD" -name "yarn.lock" -printf "%h\n" | \
|
|
|
|
xargs -I {} yarn --cwd {} \
|
|
|
|
--frozen-lockfile --ignore-scripts --ignore-platform \
|
|
|
|
--ignore-engines --no-progress --non-interactive
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
echo yarnCache
|
|
|
|
'';
|
|
|
|
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHashAlgo = "sha256";
|
2023-10-15 00:43:01 +02:00
|
|
|
outputHash = "sha256-oW/JngHpXb8kscikscI7N9csSyZsZQgG75jOdWll6dw=";
|
2021-11-07 21:54:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2023-06-13 15:07:58 +02:00
|
|
|
nodejs
|
|
|
|
yarn'
|
|
|
|
python3
|
|
|
|
pkg-config
|
|
|
|
makeWrapper
|
|
|
|
git
|
|
|
|
jq
|
|
|
|
moreutils
|
2021-11-07 21:54:56 +01:00
|
|
|
];
|
2023-06-15 23:06:42 +02:00
|
|
|
|
2021-11-07 21:54:56 +01:00
|
|
|
buildInputs = lib.optionals (!stdenv.isDarwin) [ libsecret ]
|
2023-10-15 00:43:01 +02:00
|
|
|
++ (with xorg; [ libX11 libxkbfile libkrb5 ])
|
2021-11-07 21:54:56 +01:00
|
|
|
++ lib.optionals stdenv.isDarwin [
|
2023-06-13 15:07:58 +02:00
|
|
|
AppKit
|
|
|
|
Cocoa
|
|
|
|
Security
|
|
|
|
cctools
|
|
|
|
];
|
2021-11-07 21:54:56 +01:00
|
|
|
|
|
|
|
patches = [
|
|
|
|
# Patch out remote download of nodejs from build script
|
|
|
|
./remove-node-download.patch
|
|
|
|
];
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
export HOME=$PWD
|
|
|
|
|
|
|
|
# remove all built-in extensions, as these are 3rd party extensions that
|
|
|
|
# get downloaded from vscode marketplace
|
|
|
|
jq --slurp '.[0] * .[1]' "product.json" <(
|
|
|
|
cat << EOF
|
|
|
|
{
|
|
|
|
"builtInExtensions": []
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
) | sponge product.json
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
2023-06-13 15:07:58 +02:00
|
|
|
runHook preConfigure
|
|
|
|
|
2021-11-07 21:54:56 +01:00
|
|
|
# set default yarn opts
|
|
|
|
${lib.concatMapStrings (option: ''
|
|
|
|
yarn --offline config set ${option}
|
|
|
|
'') defaultYarnOpts}
|
|
|
|
|
|
|
|
# set offline mirror to yarn cache we created in previous steps
|
2023-06-13 15:07:58 +02:00
|
|
|
yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"
|
2023-05-31 09:46:12 +02:00
|
|
|
|
2023-10-15 00:43:01 +02:00
|
|
|
# set nodedir to prevent node-gyp from downloading headers
|
|
|
|
# taken from https://nixos.org/manual/nixpkgs/stable/#javascript-tool-specific
|
|
|
|
mkdir -p $HOME/.node-gyp/${nodejs.version}
|
|
|
|
echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
|
|
|
|
ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
|
|
|
|
export npm_config_nodedir=${nodejs}
|
|
|
|
|
|
|
|
# use updated node-gyp. fixes the following error on Darwin:
|
|
|
|
# PermissionError: [Errno 1] Operation not permitted: '/usr/sbin/pkgutil'
|
|
|
|
export npm_config_node_gyp=${node-gyp}/lib/node_modules/node-gyp/bin/node-gyp.js
|
2023-06-13 15:07:58 +02:00
|
|
|
|
|
|
|
runHook postConfigure
|
2021-11-07 21:54:56 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
2023-06-13 15:07:58 +02:00
|
|
|
runHook preBuild
|
|
|
|
|
2021-11-07 21:54:56 +01:00
|
|
|
# install dependencies
|
|
|
|
yarn --offline --ignore-scripts
|
|
|
|
|
|
|
|
# run yarn install everywhere, skipping postinstall so we can patch esbuild
|
|
|
|
find . -path "*node_modules" -prune -o \
|
|
|
|
-path "./*/*" -name "yarn.lock" -printf "%h\n" | \
|
|
|
|
xargs -I {} yarn --cwd {} \
|
|
|
|
--frozen-lockfile --offline --ignore-scripts --ignore-engines
|
|
|
|
|
|
|
|
${patchEsbuild "./build" "0.12.6"}
|
|
|
|
${patchEsbuild "./extensions" "0.11.23"}
|
|
|
|
|
|
|
|
# patch shebangs of node_modules to allow binary packages to build
|
|
|
|
patchShebangs ./remote/node_modules
|
|
|
|
|
|
|
|
# put ripgrep binary into bin so postinstall does not try to download it
|
2022-04-05 20:45:11 +02:00
|
|
|
find -path "*@vscode/ripgrep" -type d \
|
2021-11-07 21:54:56 +01:00
|
|
|
-execdir mkdir -p {}/bin \; \
|
|
|
|
-execdir ln -s ${ripgrep}/bin/rg {}/bin/rg \;
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
# use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
|
|
|
|
# (see issue #101229)
|
|
|
|
pushd ./remote/node_modules/@parcel/watcher
|
|
|
|
mkdir -p ./build/Release
|
|
|
|
mv ./prebuilds/darwin-x64/node.napi.glibc.node ./build/Release/watcher.node
|
|
|
|
jq "del(.scripts) | .gypfile = false" ./package.json | sponge ./package.json
|
|
|
|
popd
|
|
|
|
'' + ''
|
2023-02-03 08:04:56 +01:00
|
|
|
export NODE_OPTIONS=--openssl-legacy-provider
|
|
|
|
|
2021-11-07 21:54:56 +01:00
|
|
|
# rebuild binaries, we use npm here, as yarn does not provide an alternative
|
|
|
|
# that would not attempt to try to reinstall everything and break our
|
|
|
|
# patching attempts
|
2023-05-31 09:46:12 +02:00
|
|
|
npm --prefix ./remote rebuild --build-from-source
|
2021-11-07 21:54:56 +01:00
|
|
|
|
|
|
|
# run postinstall scripts after patching
|
|
|
|
find . -path "*node_modules" -prune -o \
|
|
|
|
-path "./*/*" -name "yarn.lock" -printf "%h\n" | \
|
|
|
|
xargs -I {} sh -c 'jq -e ".scripts.postinstall" {}/package.json >/dev/null && yarn --cwd {} postinstall --frozen-lockfile --offline || true'
|
|
|
|
|
|
|
|
# build and minify
|
|
|
|
yarn --offline gulp vscode-reh-web-${vsBuildTarget}-min
|
2023-06-13 15:07:58 +02:00
|
|
|
|
|
|
|
runHook postBuild
|
2021-11-07 21:54:56 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2023-06-13 15:07:58 +02:00
|
|
|
runHook preInstall
|
|
|
|
|
2022-04-05 20:45:11 +02:00
|
|
|
mkdir -p $out
|
|
|
|
cp -R -T ../vscode-reh-web-${vsBuildTarget} $out
|
|
|
|
ln -s ${nodejs}/bin/node $out
|
2023-06-13 15:07:58 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
2021-11-07 21:54:56 +01:00
|
|
|
'';
|
|
|
|
|
2023-05-15 15:33:37 +02:00
|
|
|
passthru.tests = {
|
|
|
|
inherit (nixosTests) openvscode-server;
|
|
|
|
};
|
|
|
|
|
2023-06-13 15:07:58 +02:00
|
|
|
meta = {
|
2021-11-07 21:54:56 +01:00
|
|
|
description = "Run VS Code on a remote machine";
|
|
|
|
longDescription = ''
|
|
|
|
Run upstream VS Code on a remote machine with access through a modern web
|
|
|
|
browser from any device, anywhere.
|
|
|
|
'';
|
|
|
|
homepage = "https://github.com/gitpod-io/openvscode-server";
|
2023-06-13 15:07:58 +02:00
|
|
|
license = lib.licenses.mit;
|
|
|
|
maintainers = with lib.maintainers; [ dguenther ghuntley emilytrau ];
|
2022-04-05 20:45:11 +02:00
|
|
|
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
2023-07-31 21:21:43 +02:00
|
|
|
mainProgram = "openvscode-server";
|
2021-11-07 21:54:56 +01:00
|
|
|
};
|
2023-06-13 15:07:58 +02:00
|
|
|
})
|