code-server: use finalAttrs pattern

- refactor code-style
- add missing phases
- remove cloud-agent
This commit is contained in:
Pol Dellaiera 2023-06-13 21:23:16 +02:00
parent b753a7498b
commit d1556ade02
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
2 changed files with 77 additions and 49 deletions

View File

@ -1,12 +1,35 @@
{ lib, stdenv, fetchFromGitHub, buildGoModule, makeWrapper
, cacert, moreutils, jq, git, rsync, pkg-config, yarn, python3
, esbuild, nodejs_16, node-gyp, libsecret, xorg, ripgrep
, AppKit, Cocoa, CoreServices, Security, cctools, xcbuild, quilt, nixosTests }:
{ 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
}:
let
system = stdenv.hostPlatform.system;
nodejs = nodejs_16;
python = python3;
yarn' = yarn.override { inherit nodejs; };
defaultYarnOpts = [ ];
@ -25,49 +48,31 @@ let
};
# replaces esbuild's download script with a binary from nixpkgs
patchEsbuild = path : version : ''
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
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
'';
in stdenv.mkDerivation rec {
in
stdenv.mkDerivation (finalAttrs: {
pname = "code-server";
version = "4.12.0";
src = fetchFromGitHub {
owner = "coder";
repo = "code-server";
rev = "v${version}";
rev = "v${finalAttrs.version}";
fetchSubmodules = true;
hash = "sha256-PQp5dji2Ynp+LJRWBka41umwe1/IR76C+at/wyOWGcI=";
};
cloudAgent = buildGoModule rec {
pname = "cloud-agent";
version = "0.2.6";
src = fetchFromGitHub {
owner = "coder";
repo = "cloud-agent";
rev = "v${version}";
sha256 = "1s3jpgvzizc9skc27c3x35sya2p4ywhvdi3l73927z3j47wszy7f";
};
vendorSha256 = "14xzlbmki8fk8mbcci62q8sklyd0nyga07ww1ap0vdrv7d1g31hn";
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}"'
'';
};
yarnCache = stdenv.mkDerivation {
name = "${pname}-${version}-${system}-yarn-cache";
inherit src;
name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
inherit (finalAttrs) src;
nativeBuildInputs = [ yarn' git cacert ];
buildPhase = ''
export HOME=$PWD
export GIT_SSL_CAINFO="${cacert}/etc/ssl/certs/ca-bundle.crt"
@ -84,21 +89,35 @@ in stdenv.mkDerivation rec {
xargs -I {} yarn --cwd {} \
--ignore-scripts --ignore-engines
'';
outputHashMode = "recursive";
outputHashAlgo = "sha256";
# to get hash values use nix-build -A code-server.prefetchYarnCache
outputHash = "sha256-4Vr9u3+W/IhbbTc39jyDyDNQODlmdF+M/N8oJn0Z4+w=";
};
nativeBuildInputs = [
nodejs yarn' python pkg-config makeWrapper git rsync jq moreutils quilt
nodejs
yarn'
python
pkg-config
makeWrapper
git
rsync
jq
moreutils
quilt
];
buildInputs = lib.optionals (!stdenv.isDarwin) [ libsecret ]
++ (with xorg; [ libX11 libxkbfile ])
++ lib.optionals stdenv.isDarwin [
AppKit Cocoa CoreServices Security cctools xcbuild
];
AppKit
Cocoa
CoreServices
Security
cctools
xcbuild
];
patches = [
# remove git calls from vscode build script
@ -116,6 +135,8 @@ in stdenv.mkDerivation rec {
'';
configurePhase = ''
runHook preConfigure
# run yarn offline by default
echo '--install.offline true' >> .yarnrc
@ -125,7 +146,7 @@ in stdenv.mkDerivation rec {
'') defaultYarnOpts}
# set offline mirror to yarn cache we created in previous steps
yarn --offline config set yarn-offline-mirror "${yarnCache}"
yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"
# skip unnecessary electron download
export ELECTRON_SKIP_BINARY_DOWNLOAD=1
@ -140,9 +161,13 @@ in stdenv.mkDerivation rec {
# 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
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
# install code-server dependencies
yarn --offline --ignore-scripts
@ -191,7 +216,7 @@ in stdenv.mkDerivation rec {
${patchEsbuild "./lib/vscode/build" "0.12.6"}
${patchEsbuild "./lib/vscode/extensions" "0.11.23"}
'' + lib.optionalString stdenv.isDarwin ''
'' + lib.optionalString stdenv.isDarwin ''
# use prebuilt binary for @parcel/watcher, which requires macOS SDK 10.13+
# (see issue #101229)
pushd ./lib/vscode/remote/node_modules/@parcel/watcher
@ -215,13 +240,17 @@ in stdenv.mkDerivation rec {
yarn build
# build vscode
VERSION=${version} yarn build:vscode
VERSION=${finalAttrs.version} yarn build:vscode
# create release
yarn release
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/libexec/code-server $out/bin
# copy release to libexec path
@ -230,17 +259,15 @@ in stdenv.mkDerivation rec {
# install only production dependencies
yarn --offline --cwd "$out/libexec/code-server" --production
# link coder-cloud agent from nix store
mkdir -p $out/libexec/code-server/lib
ln -s "${cloudAgent}/bin/cloud-agent" $out/libexec/code-server/lib/coder-cloud-agent
# create wrapper
makeWrapper "${nodejs_16}/bin/node" "$out/bin/code-server" \
makeWrapper "${nodejs}/bin/node" "$out/bin/code-server" \
--add-flags "$out/libexec/code-server/out/node/entry.js"
runHook postInstall
'';
passthru = {
prefetchYarnCache = lib.overrideDerivation yarnCache (d: {
prefetchYarnCache = lib.overrideDerivation finalAttrs.yarnCache (d: {
outputHash = lib.fakeSha256;
});
tests = {
@ -248,15 +275,15 @@ in stdenv.mkDerivation rec {
};
};
meta = with lib; {
meta = {
description = "Run VS Code on a remote server";
longDescription = ''
code-server is VS Code running on a remote server, accessible through the
browser.
'';
homepage = "https://github.com/coder/code-server";
license = licenses.mit;
maintainers = with maintainers; [ offline henkery ];
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ offline henkery ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
};
}
})

View File

@ -35270,6 +35270,7 @@ with pkgs;
};
code-server = callPackage ../servers/code-server {
nodejs = nodejs_16;
inherit (darwin.apple_sdk.frameworks) AppKit Cocoa CoreServices Security;
inherit (darwin) cctools;
inherit (nodePackages) node-gyp;