2023-07-15 17:15:38 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, buildGoModule
|
|
|
|
, makeWrapper
|
|
|
|
, cacert
|
|
|
|
, moreutils
|
|
|
|
, jq
|
|
|
|
, git
|
|
|
|
, rsync
|
|
|
|
, pkg-config
|
|
|
|
, yarn
|
|
|
|
, python3
|
|
|
|
, esbuild
|
|
|
|
, nodejs
|
|
|
|
, node-gyp
|
|
|
|
, libsecret
|
|
|
|
, xorg
|
|
|
|
, ripgrep
|
|
|
|
, AppKit
|
|
|
|
, Cocoa
|
|
|
|
, CoreServices
|
|
|
|
, Security
|
|
|
|
, cctools
|
|
|
|
, xcbuild
|
|
|
|
, quilt
|
|
|
|
, nixosTests
|
|
|
|
}:
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
system = stdenv.hostPlatform.system;
|
|
|
|
|
2021-07-14 22:03:04 +00:00
|
|
|
python = python3;
|
2020-06-15 15:56:04 +00:00
|
|
|
yarn' = yarn.override { inherit nodejs; };
|
2022-12-28 21:21:41 +00:00
|
|
|
defaultYarnOpts = [ ];
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2023-02-02 18:25:31 +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-19 23:45:15 +00:00
|
|
|
# replaces esbuild's download script with a binary from nixpkgs
|
2023-07-15 17:15:38 +00:00
|
|
|
patchEsbuild = path: version: ''
|
2022-01-19 23:45:15 +00: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-02-02 18:25:31 +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-19 23:45:15 +00:00
|
|
|
'';
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
# Comment from @code-asher, the code-server maintainer
|
|
|
|
# See https://github.com/NixOS/nixpkgs/pull/240001#discussion_r1244303617
|
|
|
|
#
|
|
|
|
# If the commit is missing it will break display languages (Japanese, Spanish,
|
|
|
|
# etc). For some reason VS Code has a hard dependency on the commit being set
|
|
|
|
# for that functionality.
|
|
|
|
# The commit is also used in cache busting. Without the commit you could run
|
|
|
|
# into issues where the browser is loading old versions of assets from the
|
|
|
|
# cache.
|
|
|
|
# Lastly, it can be helpful for the commit to be accurate in bug reports
|
|
|
|
# especially when they are built outside of our CI as sometimes the version
|
|
|
|
# numbers can be unreliable (since they are arbitrarily provided).
|
|
|
|
#
|
|
|
|
# To compute the commit when upgrading this derivation, do:
|
|
|
|
# `$ git rev-parse <git-rev>` where <git-rev> is the git revision of the `src`
|
2023-08-04 22:07:22 +00:00
|
|
|
# Example: `$ git rev-parse v4.16.1`
|
2024-07-27 06:49:29 +00:00
|
|
|
commit = "1962f48b7f71772dc2c060dbaa5a6b4c0792a549";
|
2023-07-15 17:15:38 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2020-06-15 15:56:04 +00:00
|
|
|
pname = "code-server";
|
2024-07-27 06:49:29 +00:00
|
|
|
version = "4.91.1";
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2022-12-28 21:21:41 +00:00
|
|
|
owner = "coder";
|
2020-06-15 15:56:04 +00:00
|
|
|
repo = "code-server";
|
2023-07-15 17:15:38 +00:00
|
|
|
rev = "v${finalAttrs.version}";
|
2022-12-28 21:21:41 +00:00
|
|
|
fetchSubmodules = true;
|
2024-07-27 06:49:29 +00:00
|
|
|
hash = "sha256-w0+lg/DcxKLrAz6DQGQ9+yPn42LrQ95Yn16IKNfqPvE=";
|
2021-01-09 10:05:03 +00:00
|
|
|
};
|
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
yarnCache = stdenv.mkDerivation {
|
2023-07-15 17:15:38 +00:00
|
|
|
name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
|
|
|
|
inherit (finalAttrs) src;
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
nativeBuildInputs = [ yarn' git cacert ];
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
buildPhase = ''
|
2023-08-04 22:07:22 +00:00
|
|
|
runHook preBuild
|
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
export HOME=$PWD
|
2021-12-06 16:07:01 +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-06-15 15:56:04 +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-12-28 21:21:41 +00:00
|
|
|
|
|
|
|
find ./lib/vscode -name "yarn.lock" -printf "%h\n" | \
|
|
|
|
xargs -I {} yarn --cwd {} \
|
|
|
|
--ignore-scripts --ignore-engines
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
2020-06-15 15:56:04 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHashAlgo = "sha256";
|
2024-07-27 06:49:29 +00:00
|
|
|
outputHash = "sha256-LCmygPid6VJqR1PCOMk/Hc6bo4nwsLwYr7O1p3FQVvQ=";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2023-07-15 17:15:38 +00:00
|
|
|
nodejs
|
|
|
|
yarn'
|
|
|
|
python
|
|
|
|
pkg-config
|
|
|
|
makeWrapper
|
|
|
|
git
|
|
|
|
rsync
|
|
|
|
jq
|
|
|
|
moreutils
|
|
|
|
quilt
|
2021-02-05 17:12:51 +00:00
|
|
|
];
|
2023-07-15 17:15:38 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
buildInputs = [
|
|
|
|
xorg.libX11
|
|
|
|
xorg.libxkbfile
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
|
2024-04-21 15:54:59 +00:00
|
|
|
libsecret
|
2024-09-26 11:04:55 +00:00
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
|
2023-07-15 17:15:38 +00:00
|
|
|
AppKit
|
|
|
|
Cocoa
|
|
|
|
CoreServices
|
|
|
|
Security
|
|
|
|
cctools
|
|
|
|
xcbuild
|
|
|
|
];
|
2021-02-05 17:12:51 +00:00
|
|
|
|
|
|
|
patches = [
|
2023-07-15 17:15:38 +00:00
|
|
|
# Remove all git calls from the VS Code build script except `git rev-parse
|
|
|
|
# HEAD` which is replaced in postPatch with the commit.
|
2022-12-28 21:21:41 +00:00
|
|
|
./build-vscode-nogit.patch
|
2020-06-15 15:56:04 +00:00
|
|
|
];
|
|
|
|
|
2021-01-09 10:05:03 +00:00
|
|
|
postPatch = ''
|
2020-06-15 15:56:04 +00:00
|
|
|
export HOME=$PWD
|
|
|
|
|
|
|
|
patchShebangs ./ci
|
|
|
|
|
|
|
|
# inject git commit
|
2023-07-15 17:15:38 +00:00
|
|
|
substituteInPlace ./ci/build/build-vscode.sh \
|
2024-04-21 15:54:59 +00:00
|
|
|
--replace-fail '$(git rev-parse HEAD)' "${commit}"
|
2023-07-15 17:15:38 +00:00
|
|
|
substituteInPlace ./ci/build/build-release.sh \
|
2024-04-21 15:54:59 +00:00
|
|
|
--replace-fail '$(git rev-parse HEAD)' "${commit}"
|
2020-06-15 15:56:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
configurePhase = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
runHook preConfigure
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
# run yarn offline by default
|
|
|
|
echo '--install.offline true' >> .yarnrc
|
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
# set default yarn opts
|
2021-01-15 22:18:51 +00:00
|
|
|
${lib.concatMapStrings (option: ''
|
2020-06-15 15:56:04 +00:00
|
|
|
yarn --offline config set ${option}
|
|
|
|
'') defaultYarnOpts}
|
|
|
|
|
|
|
|
# set offline mirror to yarn cache we created in previous steps
|
2023-07-15 17:15:38 +00:00
|
|
|
yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2021-01-09 10:05:03 +00:00
|
|
|
# skip unnecessary electron download
|
|
|
|
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
|
2022-01-19 23:45:15 +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
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
runHook postConfigure
|
2020-06-15 15:56:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
runHook preBuild
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Apply patches.
|
2022-12-28 21:21:41 +00:00
|
|
|
quilt push -a
|
|
|
|
|
|
|
|
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
|
|
|
|
export SKIP_SUBMODULE_DEPS=1
|
2024-04-21 15:54:59 +00:00
|
|
|
export NODE_OPTIONS="--openssl-legacy-provider --max-old-space-size=4096"
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Remove all built-in extensions, as these are 3rd party extensions that
|
|
|
|
# get downloaded from the VS Code marketplace.
|
2022-12-28 21:21:41 +00:00
|
|
|
jq --slurp '.[0] * .[1]' "./lib/vscode/product.json" <(
|
2021-12-06 16:07:01 +00:00
|
|
|
cat << EOF
|
|
|
|
{
|
|
|
|
"builtInExtensions": []
|
|
|
|
}
|
|
|
|
EOF
|
2022-12-28 21:21:41 +00:00
|
|
|
) | sponge ./lib/vscode/product.json
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Disable automatic updates.
|
2021-12-06 16:07:01 +00:00
|
|
|
sed -i '/update.mode/,/\}/{s/default:.*/default: "none",/g}' \
|
2022-12-28 21:21:41 +00:00
|
|
|
lib/vscode/src/vs/platform/update/common/update.config.contribution.ts
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Patch out remote download of nodejs from build script.
|
2022-01-19 23:45:15 +00:00
|
|
|
patch -p1 -i ${./remove-node-download.patch}
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Install dependencies.
|
|
|
|
patchShebangs .
|
|
|
|
find . -name "yarn.lock" -printf "%h\n" | \
|
2021-12-06 16:07:01 +00:00
|
|
|
xargs -I {} yarn --cwd {} \
|
2024-04-21 15:54:59 +00:00
|
|
|
--offline --frozen-lockfile --ignore-scripts --ignore-engines
|
2021-12-06 16:07:01 +00:00
|
|
|
patchShebangs .
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Use esbuild from nixpkgs.
|
2022-12-28 21:21:41 +00:00
|
|
|
${patchEsbuild "./lib/vscode/build" "0.12.6"}
|
|
|
|
${patchEsbuild "./lib/vscode/extensions" "0.11.23"}
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Kerberos errors while building, so remove it for now as it is not
|
|
|
|
# required.
|
|
|
|
yarn remove kerberos --cwd lib/vscode/remote --offline --frozen-lockfile --ignore-scripts --ignore-engines
|
|
|
|
|
|
|
|
# Put ripgrep binary into bin, so post-install does not try to download it.
|
2022-12-28 21:21:41 +00:00
|
|
|
find -name ripgrep -type d \
|
|
|
|
-execdir mkdir -p {}/bin \; \
|
|
|
|
-execdir ln -s ${ripgrep}/bin/rg {}/bin/rg \;
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Run post-install scripts after patching.
|
2023-07-15 17:15:38 +00:00
|
|
|
find ./lib/vscode \( -path "*/node_modules/*" -or -path "*/extensions/*" \) \
|
|
|
|
-and -type f -name "yarn.lock" -printf "%h\n" | \
|
2021-12-06 16:07:01 +00:00
|
|
|
xargs -I {} sh -c 'jq -e ".scripts.postinstall" {}/package.json >/dev/null && yarn --cwd {} postinstall --frozen-lockfile --offline || true'
|
2024-04-21 15:54:59 +00:00
|
|
|
patchShebangs .
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
|
2024-04-21 15:54:59 +00:00
|
|
|
# Use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
|
|
|
|
# (see issue #101229).
|
|
|
|
pushd ./lib/vscode/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
|
|
|
|
'' + ''
|
|
|
|
|
|
|
|
# Build binary packages (argon2, node-pty, etc).
|
|
|
|
npm rebuild --offline
|
|
|
|
npm rebuild --offline --prefix lib/vscode/remote
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Build code-server and VS Code.
|
|
|
|
yarn build
|
2023-07-15 17:15:38 +00:00
|
|
|
VERSION=${finalAttrs.version} yarn build:vscode
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Inject version into package.json.
|
2023-07-15 17:15:38 +00:00
|
|
|
jq --slurp '.[0] * .[1]' ./package.json <(
|
|
|
|
cat << EOF
|
|
|
|
{
|
|
|
|
"version": "${finalAttrs.version}"
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
) | sponge ./package.json
|
2020-06-15 15:56:04 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
# Create release, keeping all dependencies.
|
|
|
|
KEEP_MODULES=1 yarn release
|
|
|
|
|
|
|
|
# Prune development dependencies. We only need to do this for the root as
|
|
|
|
# the VS Code build process already does this for VS Code.
|
|
|
|
npm prune --omit=dev --prefix release
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
runHook postBuild
|
2020-06-15 15:56:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2023-07-15 17:15:38 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
mkdir -p $out/libexec/code-server $out/bin
|
|
|
|
|
|
|
|
# copy release to libexec path
|
|
|
|
cp -R -T release "$out/libexec/code-server"
|
|
|
|
|
|
|
|
# create wrapper
|
2023-07-15 17:15:38 +00:00
|
|
|
makeWrapper "${nodejs}/bin/node" "$out/bin/code-server" \
|
2020-06-15 15:56:04 +00:00
|
|
|
--add-flags "$out/libexec/code-server/out/node/entry.js"
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
runHook postInstall
|
2020-06-15 15:56:04 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
2023-07-15 17:15:38 +00:00
|
|
|
prefetchYarnCache = lib.overrideDerivation finalAttrs.yarnCache (d: {
|
2021-01-15 22:18:51 +00:00
|
|
|
outputHash = lib.fakeSha256;
|
2020-06-15 15:56:04 +00:00
|
|
|
});
|
2023-07-15 17:15:38 +00:00
|
|
|
tests = {
|
|
|
|
inherit (nixosTests) code-server;
|
|
|
|
};
|
|
|
|
# vscode-with-extensions compatibility
|
|
|
|
executableName = "code-server";
|
|
|
|
longName = "Visual Studio Code Server";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
meta = {
|
2024-07-27 06:49:29 +00:00
|
|
|
changelog = "https://github.com/coder/code-server/blob/${finalAttrs.src.rev}/CHANGELOG.md";
|
2020-10-19 00:13:06 +00:00
|
|
|
description = "Run VS Code on a remote server";
|
2020-06-15 15:56:04 +00:00
|
|
|
longDescription = ''
|
|
|
|
code-server is VS Code running on a remote server, accessible through the
|
|
|
|
browser.
|
|
|
|
'';
|
2022-12-28 21:21:41 +00:00
|
|
|
homepage = "https://github.com/coder/code-server";
|
2023-07-15 17:15:38 +00:00
|
|
|
license = lib.licenses.mit;
|
|
|
|
maintainers = with lib.maintainers; [ offline henkery code-asher ];
|
2021-02-05 17:12:51 +00:00
|
|
|
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
|
2023-08-04 22:07:22 +00:00
|
|
|
mainProgram = "code-server";
|
2020-06-15 15:56:04 +00:00
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
})
|