openvscode-server: use finalAttrs pattern

This commit is contained in:
Pol Dellaiera 2023-06-13 15:07:58 +02:00
parent 40b63ec92d
commit 4f73991ab9
No known key found for this signature in database
GPG key ID: D476DFE9C67467CA

View file

@ -1,13 +1,32 @@
{ lib, stdenv, fetchFromGitHub, buildGoModule, makeWrapper
, cacert, moreutils, jq, git, pkg-config, yarn, python3
, esbuild, nodejs, libsecret, xorg, ripgrep
, AppKit, Cocoa, Security, cctools, nixosTests }:
{ lib
, stdenv
, fetchFromGitHub
, buildGoModule
, makeWrapper
, cacert
, moreutils
, jq
, git
, pkg-config
, yarn
, python3
, esbuild
, nodejs
, libsecret
, xorg
, ripgrep
, AppKit
, Cocoa
, Security
, cctools
, nixosTests
}:
let
system = stdenv.hostPlatform.system;
yarn' = yarn.override { inherit nodejs; };
defaultYarnOpts = [ "frozen-lockfile" "non-interactive" "no-progress"];
defaultYarnOpts = [ "frozen-lockfile" "non-interactive" "no-progress" ];
vsBuildTarget = {
x86_64-linux = "linux-x64";
@ -30,27 +49,27 @@ 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 = "openvscode-server";
version = "1.79.0";
src = fetchFromGitHub {
owner = "gitpod-io";
repo = "openvscode-server";
rev = "openvscode-server-v${version}";
rev = "openvscode-server-v${finalAttrs.version}";
hash = "sha256-dVzGyK1ybZywCm602zWJroSCQ2wx5IzV+HqwZUsEgKU=";
};
yarnCache = stdenv.mkDerivation {
name = "${pname}-${version}-${system}-yarn-cache";
inherit src;
name = "${finalAttrs.pname}-${finalAttrs.version}-${system}-yarn-cache";
inherit (finalAttrs) src;
nativeBuildInputs = [ cacert yarn' git ];
buildPhase = ''
export HOME=$PWD
@ -72,13 +91,23 @@ in stdenv.mkDerivation rec {
};
nativeBuildInputs = [
nodejs yarn' python3 pkg-config makeWrapper git jq moreutils
nodejs
yarn'
python3
pkg-config
makeWrapper
git
jq
moreutils
];
buildInputs = lib.optionals (!stdenv.isDarwin) [ libsecret ]
++ (with xorg; [ libX11 libxkbfile ])
++ lib.optionals stdenv.isDarwin [
AppKit Cocoa Security cctools
];
AppKit
Cocoa
Security
cctools
];
patches = [
# Patch out remote download of nodejs from build script
@ -100,19 +129,25 @@ in stdenv.mkDerivation rec {
'';
configurePhase = ''
runHook preConfigure
# set default yarn opts
${lib.concatMapStrings (option: ''
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}"
yarn --offline config set yarn-offline-mirror "${finalAttrs.yarnCache}"
# set nodedir, so we can build binaries later
npm config set nodedir "${nodejs}"
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
# install dependencies
yarn --offline --ignore-scripts
@ -155,27 +190,33 @@ in stdenv.mkDerivation rec {
# build and minify
yarn --offline gulp vscode-reh-web-${vsBuildTarget}-min
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -R -T ../vscode-reh-web-${vsBuildTarget} $out
ln -s ${nodejs}/bin/node $out
runHook postInstall
'';
passthru.tests = {
inherit (nixosTests) openvscode-server;
};
meta = with lib; {
meta = {
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";
license = licenses.mit;
maintainers = with maintainers; [ dguenther ghuntley emilytrau ];
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ dguenther ghuntley emilytrau ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
};
}
})