2022-11-06 10:59:21 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, buildGoModule, makeWrapper
|
2022-01-10 00:36:05 +00:00
|
|
|
, cacert, moreutils, jq, git, rsync, pkg-config, yarn, python3
|
2022-11-06 10:59:21 +00:00
|
|
|
, esbuild, nodejs_16, node-gyp, libsecret, xorg, ripgrep
|
2022-11-16 11:25:43 +00:00
|
|
|
, AppKit, Cocoa, CoreServices, Security, cctools, xcbuild, quilt }:
|
2020-05-08 11:33:07 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
system = stdenv.hostPlatform.system;
|
|
|
|
|
2022-11-06 10:59:21 +00:00
|
|
|
nodejs = nodejs_16;
|
2021-07-10 00:47:39 +00:00
|
|
|
python = python3;
|
2020-05-08 11:33:07 +00:00
|
|
|
yarn' = yarn.override { inherit nodejs; };
|
2022-11-16 11:25:43 +00:00
|
|
|
defaultYarnOpts = [ ];
|
2020-05-08 11:33:07 +00:00
|
|
|
|
2023-01-28 04:20:00 +00:00
|
|
|
esbuild' = esbuild.override {
|
|
|
|
buildGoModule = args: buildGoModule (args // rec {
|
|
|
|
version = "0.16.17";
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "evanw";
|
|
|
|
repo = "esbuild";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-8L8h0FaexNsb3Mj6/ohA37nYLFogo5wXkAhGztGUUsQ=";
|
|
|
|
};
|
|
|
|
vendorHash = "sha256-+BfxCyg0KkDQpHt/wycy/8CTG6YBA/VJvJFhhzUnSiQ=";
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-01-10 00:36:05 +00:00
|
|
|
# replaces esbuild's download script with a binary from nixpkgs
|
|
|
|
patchEsbuild = path : version : ''
|
|
|
|
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 04:20:00 +00: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
|
2022-01-10 00:36:05 +00:00
|
|
|
'';
|
|
|
|
|
2020-05-08 11:33:07 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
|
|
|
pname = "code-server";
|
2023-04-26 18:06:38 +00:00
|
|
|
version = "4.12.0";
|
2020-05-08 11:33:07 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2022-11-16 11:25:43 +00:00
|
|
|
owner = "coder";
|
2020-05-08 11:33:07 +00:00
|
|
|
repo = "code-server";
|
2020-10-18 19:10:41 +00:00
|
|
|
rev = "v${version}";
|
2022-11-16 11:25:43 +00:00
|
|
|
fetchSubmodules = true;
|
2023-04-26 18:06:38 +00:00
|
|
|
hash = "sha256-PQp5dji2Ynp+LJRWBka41umwe1/IR76C+at/wyOWGcI=";
|
2020-05-08 11:33:07 +00:00
|
|
|
};
|
|
|
|
|
2020-10-18 19:10:41 +00:00
|
|
|
cloudAgent = buildGoModule rec {
|
|
|
|
pname = "cloud-agent";
|
2022-11-16 11:25:43 +00:00
|
|
|
version = "0.2.6";
|
2020-10-18 19:10:41 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2022-11-16 11:25:43 +00:00
|
|
|
owner = "coder";
|
2020-10-18 19:10:41 +00:00
|
|
|
repo = "cloud-agent";
|
2021-01-18 00:03:35 +00:00
|
|
|
rev = "v${version}";
|
2022-11-16 11:25:43 +00:00
|
|
|
sha256 = "1s3jpgvzizc9skc27c3x35sya2p4ywhvdi3l73927z3j47wszy7f";
|
2020-10-18 19:10:41 +00:00
|
|
|
};
|
|
|
|
|
2022-11-16 11:25:43 +00:00
|
|
|
vendorSha256 = "14xzlbmki8fk8mbcci62q8sklyd0nyga07ww1ap0vdrv7d1g31hn";
|
2021-01-18 00:03:35 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
# the cloud-agent release tag has an empty version string, so add it back in
|
|
|
|
substituteInPlace internal/version/version.go \
|
|
|
|
--replace 'var Version string' 'var Version string = "v${version}"'
|
|
|
|
'';
|
2020-10-18 19:10:41 +00:00
|
|
|
};
|
|
|
|
|
2020-05-08 11:33:07 +00:00
|
|
|
yarnCache = stdenv.mkDerivation {
|
|
|
|
name = "${pname}-${version}-${system}-yarn-cache";
|
|
|
|
inherit src;
|
2021-10-30 22:19:46 +00:00
|
|
|
nativeBuildInputs = [ yarn' git cacert ];
|
2020-05-08 11:33:07 +00:00
|
|
|
buildPhase = ''
|
|
|
|
export HOME=$PWD
|
2021-10-30 22:19:46 +00:00
|
|
|
export GIT_SSL_CAINFO="${cacert}/etc/ssl/certs/ca-bundle.crt"
|
|
|
|
|
|
|
|
yarn --cwd "./vendor" install --modules-folder modules --ignore-scripts --frozen-lockfile
|
2020-05-08 11:33:07 +00:00
|
|
|
|
|
|
|
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
|
2022-11-16 11:25:43 +00:00
|
|
|
|
|
|
|
find ./lib/vscode -name "yarn.lock" -printf "%h\n" | \
|
|
|
|
xargs -I {} yarn --cwd {} \
|
|
|
|
--ignore-scripts --ignore-engines
|
2020-05-08 11:33:07 +00:00
|
|
|
'';
|
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
|
2020-10-18 19:10:41 +00:00
|
|
|
# to get hash values use nix-build -A code-server.prefetchYarnCache
|
2023-04-26 18:06:38 +00:00
|
|
|
outputHash = "sha256-4Vr9u3+W/IhbbTc39jyDyDNQODlmdF+M/N8oJn0Z4+w=";
|
2020-05-08 11:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2022-11-16 11:25:43 +00:00
|
|
|
nodejs yarn' python pkg-config makeWrapper git rsync jq moreutils quilt
|
2020-05-08 11:33:07 +00:00
|
|
|
];
|
2021-01-18 00:03:35 +00:00
|
|
|
buildInputs = lib.optionals (!stdenv.isDarwin) [ libsecret ]
|
|
|
|
++ (with xorg; [ libX11 libxkbfile ])
|
|
|
|
++ lib.optionals stdenv.isDarwin [
|
2022-01-10 00:36:05 +00:00
|
|
|
AppKit Cocoa CoreServices Security cctools xcbuild
|
2021-01-18 00:03:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
patches = [
|
2022-11-16 11:25:43 +00:00
|
|
|
# remove git calls from vscode build script
|
|
|
|
./build-vscode-nogit.patch
|
2021-01-18 00:03:35 +00:00
|
|
|
];
|
2020-05-08 11:33:07 +00:00
|
|
|
|
2020-10-18 19:10:41 +00:00
|
|
|
postPatch = ''
|
2020-05-08 11:33:07 +00:00
|
|
|
export HOME=$PWD
|
|
|
|
|
|
|
|
patchShebangs ./ci
|
|
|
|
|
|
|
|
# inject git commit
|
|
|
|
substituteInPlace ci/build/build-release.sh \
|
|
|
|
--replace '$(git rev-parse HEAD)' "$commit"
|
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
2021-01-18 00:03:35 +00:00
|
|
|
# run yarn offline by default
|
|
|
|
echo '--install.offline true' >> .yarnrc
|
|
|
|
|
2020-05-08 11:33:07 +00:00
|
|
|
# set default yarn opts
|
2021-01-15 07:07:56 +00:00
|
|
|
${lib.concatMapStrings (option: ''
|
2020-05-08 11:33:07 +00:00
|
|
|
yarn --offline config set ${option}
|
|
|
|
'') defaultYarnOpts}
|
|
|
|
|
|
|
|
# set offline mirror to yarn cache we created in previous steps
|
|
|
|
yarn --offline config set yarn-offline-mirror "${yarnCache}"
|
|
|
|
|
2020-10-18 19:10:41 +00:00
|
|
|
# skip unnecessary electron download
|
|
|
|
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
2022-01-10 00:36:05 +00: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
|
2020-05-08 11:33:07 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
# install code-server dependencies
|
2021-10-30 22:19:46 +00:00
|
|
|
yarn --offline --ignore-scripts
|
2020-05-08 11:33:07 +00:00
|
|
|
|
2022-11-16 11:25:43 +00:00
|
|
|
# apply patches
|
|
|
|
quilt push -a
|
|
|
|
|
2021-10-30 22:19:46 +00:00
|
|
|
# patch shebangs of everything to allow binary packages to build
|
|
|
|
patchShebangs .
|
|
|
|
|
2022-11-16 11:25:43 +00:00
|
|
|
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
|
|
|
export SKIP_SUBMODULE_DEPS=1
|
|
|
|
export NODE_OPTIONS=--openssl-legacy-provider
|
2021-10-30 22:19:46 +00:00
|
|
|
|
|
|
|
# rebuild binary packages now that scripts have been patched
|
2022-11-16 11:25:43 +00:00
|
|
|
echo "----- NPM rebuild"
|
|
|
|
npm rebuild --prefer-offline
|
2021-10-30 22:19:46 +00:00
|
|
|
|
|
|
|
# Replicate ci/dev/postinstall.sh
|
|
|
|
echo "----- Replicate ci/dev/postinstall.sh"
|
|
|
|
yarn --cwd "./vendor" install --modules-folder modules --offline --ignore-scripts --frozen-lockfile
|
|
|
|
|
|
|
|
# remove all built-in extensions, as these are 3rd party extensions that
|
|
|
|
# get downloaded from vscode marketplace
|
2022-11-16 11:25:43 +00:00
|
|
|
jq --slurp '.[0] * .[1]' "./lib/vscode/product.json" <(
|
2021-10-30 22:19:46 +00:00
|
|
|
cat << EOF
|
|
|
|
{
|
|
|
|
"builtInExtensions": []
|
|
|
|
}
|
|
|
|
EOF
|
2022-11-16 11:25:43 +00:00
|
|
|
) | sponge ./lib/vscode/product.json
|
2021-10-30 22:19:46 +00:00
|
|
|
|
|
|
|
# disable automatic updates
|
|
|
|
sed -i '/update.mode/,/\}/{s/default:.*/default: "none",/g}' \
|
2022-11-16 11:25:43 +00:00
|
|
|
lib/vscode/src/vs/platform/update/common/update.config.contribution.ts
|
2021-10-30 22:19:46 +00:00
|
|
|
|
2022-01-10 00:36:05 +00:00
|
|
|
# Patch out remote download of nodejs from build script
|
|
|
|
patch -p1 -i ${./remove-node-download.patch}
|
|
|
|
|
2022-11-16 11:25:43 +00:00
|
|
|
# Fetch packages for vscode
|
|
|
|
find ./lib/vscode -name "yarn.lock" -printf "%h\n" | \
|
2021-10-30 22:19:46 +00:00
|
|
|
xargs -I {} yarn --cwd {} \
|
2022-11-16 11:25:43 +00:00
|
|
|
--frozen-lockfile --ignore-scripts --ignore-engines
|
2022-01-10 00:36:05 +00:00
|
|
|
|
2021-10-30 22:19:46 +00:00
|
|
|
# patch shebangs of everything to allow binary packages to build
|
|
|
|
patchShebangs .
|
|
|
|
|
2022-11-16 11:25:43 +00:00
|
|
|
${patchEsbuild "./lib/vscode/build" "0.12.6"}
|
|
|
|
${patchEsbuild "./lib/vscode/extensions" "0.11.23"}
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
2022-01-10 00:36:05 +00:00
|
|
|
# use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
|
|
|
|
# (see issue #101229)
|
2022-11-16 11:25:43 +00:00
|
|
|
pushd ./lib/vscode/remote/node_modules/@parcel/watcher
|
2022-01-10 00:36:05 +00:00
|
|
|
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
|
|
|
|
'' + ''
|
2022-11-16 11:25:43 +00:00
|
|
|
|
|
|
|
# put ripgrep binary into bin, so postinstall does not try to download it
|
|
|
|
find -name ripgrep -type d \
|
|
|
|
-execdir mkdir -p {}/bin \; \
|
|
|
|
-execdir ln -s ${ripgrep}/bin/rg {}/bin/rg \;
|
2020-05-08 11:33:07 +00:00
|
|
|
|
2021-10-30 22:19:46 +00:00
|
|
|
# run postinstall scripts after patching
|
2022-11-16 11:25:43 +00:00
|
|
|
find ./lib/vscode -path "*node_modules" -prune -o \
|
2021-10-30 22:19:46 +00:00
|
|
|
-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'
|
2020-05-08 11:33:07 +00:00
|
|
|
|
|
|
|
# build code-server
|
|
|
|
yarn build
|
|
|
|
|
|
|
|
# build vscode
|
2023-04-26 18:06:38 +00:00
|
|
|
VERSION=${version} yarn build:vscode
|
2020-05-08 11:33:07 +00:00
|
|
|
|
|
|
|
# create release
|
|
|
|
yarn release
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/libexec/code-server $out/bin
|
|
|
|
|
|
|
|
# copy release to libexec path
|
|
|
|
cp -R -T release "$out/libexec/code-server"
|
|
|
|
|
|
|
|
# install only production dependencies
|
|
|
|
yarn --offline --cwd "$out/libexec/code-server" --production
|
|
|
|
|
2020-10-18 19:10:41 +00:00
|
|
|
# link coder-cloud agent from nix store
|
2021-10-30 22:19:46 +00:00
|
|
|
mkdir -p $out/libexec/code-server/lib
|
2020-10-18 19:10:41 +00:00
|
|
|
ln -s "${cloudAgent}/bin/cloud-agent" $out/libexec/code-server/lib/coder-cloud-agent
|
|
|
|
|
2020-05-08 11:33:07 +00:00
|
|
|
# create wrapper
|
2022-11-06 10:59:21 +00:00
|
|
|
makeWrapper "${nodejs_16}/bin/node" "$out/bin/code-server" \
|
2020-05-08 11:33:07 +00:00
|
|
|
--add-flags "$out/libexec/code-server/out/node/entry.js"
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
2021-01-15 07:07:56 +00:00
|
|
|
prefetchYarnCache = lib.overrideDerivation yarnCache (d: {
|
|
|
|
outputHash = lib.fakeSha256;
|
2020-05-08 11:33:07 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2020-10-11 05:55:05 +00:00
|
|
|
description = "Run VS Code on a remote server";
|
2020-05-08 11:33:07 +00:00
|
|
|
longDescription = ''
|
|
|
|
code-server is VS Code running on a remote server, accessible through the
|
|
|
|
browser.
|
|
|
|
'';
|
2022-11-16 11:25:43 +00:00
|
|
|
homepage = "https://github.com/coder/code-server";
|
2020-05-08 11:33:07 +00:00
|
|
|
license = licenses.mit;
|
2022-11-16 11:25:43 +00:00
|
|
|
maintainers = with maintainers; [ offline henkery ];
|
2021-01-18 00:03:35 +00:00
|
|
|
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
|
2020-05-08 11:33:07 +00:00
|
|
|
};
|
|
|
|
}
|