Merge pull request #308228 from eclairevoyant/vscode-extensions-rfc-166

vscode-extensions.*: format with nixfmt RFC 166 and enforce via CI
This commit is contained in:
superherointj 2024-05-01 10:04:40 -03:00 committed by GitHub
commit e3cd6c03db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 736 additions and 496 deletions

View File

@ -37,6 +37,7 @@ jobs:
pkgs/development/cuda-modules pkgs/development/cuda-modules
pkgs/test/cuda pkgs/test/cuda
pkgs/top-level/cuda-packages.nix pkgs/top-level/cuda-packages.nix
NIX_FMT_PATHS_VSCODE_EXTS: pkgs/applications/editors/vscode/extensions
# Iterate over all environment variables beginning with NIX_FMT_PATHS_. # Iterate over all environment variables beginning with NIX_FMT_PATHS_.
run: | run: |
for env_var in "${!NIX_FMT_PATHS_@}"; do for env_var in "${!NIX_FMT_PATHS_@}"; do

View File

@ -1,22 +1,21 @@
{ lib { lib, vscode-utils }:
, vscode-utils }:
let let
inherit (vscode-utils) buildVscodeMarketplaceExtension; inherit (vscode-utils) buildVscodeMarketplaceExtension;
in in
buildVscodeMarketplaceExtension { buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {
name = "vscode-wakatime"; name = "vscode-wakatime";
publisher = "WakaTime"; publisher = "WakaTime";
version = "18.0.5"; version = "18.0.5";
hash = "sha256-vWqGxMbxKqd4UgKK0sOKadMTDf6Y3TQxfWsc93MHjFs="; hash = "sha256-vWqGxMbxKqd4UgKK0sOKadMTDf6Y3TQxfWsc93MHjFs=";
}; };
meta = { meta = {
description = '' description = ''
Visual Studio Code plugin for automatic time tracking and metrics generated Visual Studio Code plugin for automatic time tracking and metrics generated
from your programming activity from your programming activity
''; '';
license = lib.licenses.bsd3; license = lib.licenses.bsd3;
}; };
} }

View File

@ -1,11 +1,19 @@
{ lib, stdenv, vscode-utils, callPackage }: {
lib,
stdenv,
vscode-utils,
callPackage,
}:
let let
version = "1.50.0"; version = "1.50.0";
rescript-editor-analysis = callPackage ./rescript-editor-analysis.nix { inherit version; }; rescript-editor-analysis = callPackage ./rescript-editor-analysis.nix { inherit version; };
arch = arch =
if stdenv.isLinux then "linux" if stdenv.isLinux then
else if stdenv.isDarwin then "darwin" "linux"
else throw "Unsupported system: ${stdenv.system}"; else if stdenv.isDarwin then
"darwin"
else
throw "Unsupported system: ${stdenv.system}";
analysisDir = "server/analysis_binaries/${arch}"; analysisDir = "server/analysis_binaries/${arch}";
in in
vscode-utils.buildVscodeMarketplaceExtension rec { vscode-utils.buildVscodeMarketplaceExtension rec {
@ -23,7 +31,10 @@ vscode-utils.buildVscodeMarketplaceExtension rec {
meta = { meta = {
description = "The official VSCode plugin for ReScript"; description = "The official VSCode plugin for ReScript";
homepage = "https://github.com/rescript-lang/rescript-vscode"; homepage = "https://github.com/rescript-lang/rescript-vscode";
maintainers = [ lib.maintainers.dlip lib.maintainers.jayesh-bhoot ]; maintainers = [
lib.maintainers.dlip
lib.maintainers.jayesh-bhoot
];
license = lib.licenses.mit; license = lib.licenses.mit;
}; };
} }

View File

@ -1,4 +1,13 @@
{ lib, stdenv, fetchFromGitHub, bash, ocaml, ocamlPackages, dune_3, version }: {
lib,
stdenv,
fetchFromGitHub,
bash,
ocaml,
ocamlPackages,
dune_3,
version,
}:
stdenv.mkDerivation { stdenv.mkDerivation {
pname = "rescript-editor-analysis"; pname = "rescript-editor-analysis";
@ -11,7 +20,11 @@ stdenv.mkDerivation {
hash = "sha256-+Ht8qWwxtFWHFMiV/aoZIs2S3SxkOWgdwSKN+akp/LU="; hash = "sha256-+Ht8qWwxtFWHFMiV/aoZIs2S3SxkOWgdwSKN+akp/LU=";
}; };
nativeBuildInputs = [ ocaml dune_3 ocamlPackages.cppo ]; nativeBuildInputs = [
ocaml
dune_3
ocamlPackages.cppo
];
# Skip testing phases because they need to download and install node modules # Skip testing phases because they need to download and install node modules
postPatch = '' postPatch = ''
@ -28,7 +41,10 @@ stdenv.mkDerivation {
meta = { meta = {
description = "Analysis binary for the ReScript VSCode plugin"; description = "Analysis binary for the ReScript VSCode plugin";
homepage = "https://github.com/rescript-lang/rescript-vscode"; homepage = "https://github.com/rescript-lang/rescript-vscode";
maintainers = [ lib.maintainers.dlip lib.maintainers.jayesh-bhoot ]; maintainers = [
lib.maintainers.dlip
lib.maintainers.jayesh-bhoot
];
license = lib.licenses.mit; license = lib.licenses.mit;
}; };
} }

View File

@ -1,8 +1,9 @@
{ graphviz {
, jre graphviz,
, lib jre,
, makeWrapper lib,
, vscode-utils makeWrapper,
vscode-utils,
}: }:
vscode-utils.buildVscodeMarketplaceExtension rec { vscode-utils.buildVscodeMarketplaceExtension rec {
@ -13,13 +14,9 @@ vscode-utils.buildVscodeMarketplaceExtension rec {
hash = "sha256-TvApcBBI+Egu7t4tJuEYTs6mhvABOY2eXVb57O4gWfs="; hash = "sha256-TvApcBBI+Egu7t4tJuEYTs6mhvABOY2eXVb57O4gWfs=";
}; };
nativeBuildInputs = [ nativeBuildInputs = [ makeWrapper ];
makeWrapper
];
buildInputs = [ buildInputs = [ graphviz ];
graphviz
];
postInstall = '' postInstall = ''
wrapProgram $out/share/vscode/extensions/contextmapper.context-mapper-vscode-extension/lsp/bin/context-mapper-lsp \ wrapProgram $out/share/vscode/extensions/contextmapper.context-mapper-vscode-extension/lsp/bin/context-mapper-lsp \

View File

@ -1,6 +1,4 @@
{ lib { lib, vscode-utils }:
, vscode-utils
}:
vscode-utils.buildVscodeMarketplaceExtension { vscode-utils.buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {

View File

@ -1,4 +1,8 @@
{ lib, vscode-utils, terraform-ls }: {
lib,
vscode-utils,
terraform-ls,
}:
vscode-utils.buildVscodeMarketplaceExtension rec { vscode-utils.buildVscodeMarketplaceExtension rec {
mktplcRef = { mktplcRef = {
name = "terraform"; name = "terraform";

View File

@ -1,4 +1,10 @@
{ lib, vscode-utils, plantuml, jq, moreutils }: {
lib,
vscode-utils,
plantuml,
jq,
moreutils,
}:
vscode-utils.buildVscodeMarketplaceExtension { vscode-utils.buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {
@ -7,7 +13,10 @@ vscode-utils.buildVscodeMarketplaceExtension {
version = "2.17.4"; version = "2.17.4";
hash = "sha256-fnz6ubB73i7rJcv+paYyNV1r4cReuyFPjgPM0HO40ug="; hash = "sha256-fnz6ubB73i7rJcv+paYyNV1r4cReuyFPjgPM0HO40ug=";
}; };
nativeBuildInputs = [ jq moreutils ]; nativeBuildInputs = [
jq
moreutils
];
postInstall = '' postInstall = ''
cd "$out/$installPrefix" cd "$out/$installPrefix"
jq '.contributes.configuration.properties."plantuml.java".default = "${plantuml}/bin/plantuml"' package.json | sponge package.json jq '.contributes.configuration.properties."plantuml.java".default = "${plantuml}/bin/plantuml"' package.json | sponge package.json
@ -15,13 +24,10 @@ vscode-utils.buildVscodeMarketplaceExtension {
meta = { meta = {
description = "A Visual Studio Code extension for supporting Rich PlantUML"; description = "A Visual Studio Code extension for supporting Rich PlantUML";
downloadPage = downloadPage = "https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml";
"https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml";
homepage = "https://github.com/qjebbs/vscode-plantuml"; homepage = "https://github.com/qjebbs/vscode-plantuml";
changelog = changelog = "https://marketplace.visualstudio.com/items/jebbs.plantuml/changelog";
"https://marketplace.visualstudio.com/items/jebbs.plantuml/changelog";
license = lib.licenses.mit; license = lib.licenses.mit;
maintainers = [ lib.maintainers.victormignot ]; maintainers = [ lib.maintainers.victormignot ];
}; };
} }

View File

@ -4,7 +4,12 @@ with vscode-utils;
let let
buildVscodeLanguagePack = { language, version ? "1.76.2023030809", sha256 }: buildVscodeLanguagePack =
{
language,
version ? "1.76.2023030809",
sha256,
}:
buildVscodeMarketplaceExtension { buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {
name = "vscode-language-pack-${language}"; name = "vscode-language-pack-${language}";
@ -15,7 +20,6 @@ let
license = lib.licenses.mit; license = lib.licenses.mit;
}; };
}; };
in in
# See list of core language packs at https://github.com/Microsoft/vscode-loc # See list of core language packs at https://github.com/Microsoft/vscode-loc

View File

@ -1,4 +1,11 @@
{ publisher, name, version, arch ? "", sha256 ? "", hash ? "" }: {
publisher,
name,
version,
arch ? "",
sha256 ? "",
hash ? "",
}:
let let
archurl = (if arch == "" then "" else "?targetPlatform=${arch}"); archurl = (if arch == "" then "" else "?targetPlatform=${arch}");
in in

View File

@ -1,56 +1,59 @@
{ lib {
, icu lib,
, openssl icu,
, patchelf openssl,
, stdenv patchelf,
, vscode-utils stdenv,
vscode-utils,
}: }:
let let
inherit (stdenv.hostPlatform) system; inherit (stdenv.hostPlatform) system;
inherit (vscode-utils) buildVscodeMarketplaceExtension; inherit (vscode-utils) buildVscodeMarketplaceExtension;
extInfo = { extInfo =
x86_64-linux = { {
arch = "linux-x64"; x86_64-linux = {
hash = "sha256-7m85Zl9oV40le3nkNPzoKu/AAf8XhQpI8sBMsQXmBg8="; arch = "linux-x64";
binaries = [ hash = "sha256-7m85Zl9oV40le3nkNPzoKu/AAf8XhQpI8sBMsQXmBg8=";
"components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/servicehub-controller-net60.linux-x64/Microsoft.ServiceHub.Controller" binaries = [
"components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-code-servicehost.linux-x64/Microsoft.VisualStudio.Code.ServiceHost" "components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/servicehub-controller-net60.linux-x64/Microsoft.ServiceHub.Controller"
"components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-reliability-monitor.linux-x64/Microsoft.VisualStudio.Reliability.Monitor" "components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-code-servicehost.linux-x64/Microsoft.VisualStudio.Code.ServiceHost"
"components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-server.linux-x64/Microsoft.VisualStudio.Code.Server" "components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-reliability-monitor.linux-x64/Microsoft.VisualStudio.Reliability.Monitor"
]; "components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-server.linux-x64/Microsoft.VisualStudio.Code.Server"
}; ];
aarch64-linux = { };
arch = "linux-arm64"; aarch64-linux = {
hash = "sha256-39D55EdwE4baDYbHc9GD/1XoxGbQkUkS1H2uysJHlxw="; arch = "linux-arm64";
binaries = [ hash = "sha256-39D55EdwE4baDYbHc9GD/1XoxGbQkUkS1H2uysJHlxw=";
"components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/servicehub-controller-net60.linux-arm64/Microsoft.ServiceHub.Controller" binaries = [
"components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-code-servicehost.linux-arm64/Microsoft.VisualStudio.Code.ServiceHost" "components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/servicehub-controller-net60.linux-arm64/Microsoft.ServiceHub.Controller"
"components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-reliability-monitor.linux-arm64/Microsoft.VisualStudio.Reliability.Monitor" "components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-code-servicehost.linux-arm64/Microsoft.VisualStudio.Code.ServiceHost"
"components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-server.linux-arm64/Microsoft.VisualStudio.Code.Server" "components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-reliability-monitor.linux-arm64/Microsoft.VisualStudio.Reliability.Monitor"
]; "components/vs-green-server/platforms/linux-arm64/node_modules/@microsoft/visualstudio-server.linux-arm64/Microsoft.VisualStudio.Code.Server"
}; ];
x86_64-darwin = { };
arch = "darwin-x64"; x86_64-darwin = {
hash = "sha256-gfhJX07R+DIw9FbzaEE0JZwEmDeifiq4vHyMHZZ1udM="; arch = "darwin-x64";
binaries = [ hash = "sha256-gfhJX07R+DIw9FbzaEE0JZwEmDeifiq4vHyMHZZ1udM=";
"components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/servicehub-controller-net60.darwin-x64/Microsoft.ServiceHub.Controller" binaries = [
"components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-code-servicehost.darwin-x64/Microsoft.VisualStudio.Code.ServiceHost" "components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/servicehub-controller-net60.darwin-x64/Microsoft.ServiceHub.Controller"
"components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-reliability-monitor.darwin-x64/Microsoft.VisualStudio.Reliability.Monitor" "components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-code-servicehost.darwin-x64/Microsoft.VisualStudio.Code.ServiceHost"
"components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-server.darwin-x64/Microsoft.VisualStudio.Code.Server" "components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-reliability-monitor.darwin-x64/Microsoft.VisualStudio.Reliability.Monitor"
]; "components/vs-green-server/platforms/darwin-x64/node_modules/@microsoft/visualstudio-server.darwin-x64/Microsoft.VisualStudio.Code.Server"
}; ];
aarch64-darwin = { };
arch = "darwin-arm64"; aarch64-darwin = {
hash = "sha256-vogstgCWvI9csNF9JfJ41XPR1POy842g2yhWqIDoHLw="; arch = "darwin-arm64";
binaries = [ hash = "sha256-vogstgCWvI9csNF9JfJ41XPR1POy842g2yhWqIDoHLw=";
"components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/servicehub-controller-net60.darwin-arm64/Microsoft.ServiceHub.Controller" binaries = [
"components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-code-servicehost.darwin-arm64/Microsoft.VisualStudio.Code.ServiceHost" "components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/servicehub-controller-net60.darwin-arm64/Microsoft.ServiceHub.Controller"
"components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-reliability-monitor.darwin-arm64/Microsoft.VisualStudio.Reliability.Monitor" "components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-code-servicehost.darwin-arm64/Microsoft.VisualStudio.Code.ServiceHost"
"components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-server.darwin-arm64/Microsoft.VisualStudio.Code.Server" "components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-reliability-monitor.darwin-arm64/Microsoft.VisualStudio.Reliability.Monitor"
]; "components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-server.darwin-arm64/Microsoft.VisualStudio.Code.Server"
}; ];
}.${system} or (throw "Unsupported system: ${system}"); };
}
.${system} or (throw "Unsupported system: ${system}");
in in
buildVscodeMarketplaceExtension { buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {
@ -61,50 +64,55 @@ buildVscodeMarketplaceExtension {
}; };
sourceRoot = "extension"; # This has more than one folder. sourceRoot = "extension"; # This has more than one folder.
nativeBuildInputs = [ nativeBuildInputs = [ patchelf ];
patchelf
];
postPatch = '' postPatch =
declare ext_unique_id ''
ext_unique_id="$(basename "$out" | head -c 32)" declare ext_unique_id
ext_unique_id="$(basename "$out" | head -c 32)"
patchelf_add_icu_as_needed() { patchelf_add_icu_as_needed() {
declare elf="''${1?}" declare elf="''${1?}"
declare icu_major_v="${ declare icu_major_v="${lib.head (lib.splitVersion (lib.getVersion icu.name))}"
lib.head (lib.splitVersion (lib.getVersion icu.name))
}"
for icu_lib in icui18n icuuc icudata; do for icu_lib in icui18n icuuc icudata; do
patchelf --add-needed "lib''${icu_lib}.so.$icu_major_v" "$elf" patchelf --add-needed "lib''${icu_lib}.so.$icu_major_v" "$elf"
done done
} }
patchelf_common() { patchelf_common() {
declare elf="''${1?}" declare elf="''${1?}"
patchelf_add_icu_as_needed "$elf" patchelf_add_icu_as_needed "$elf"
patchelf --add-needed "libssl.so" "$elf" patchelf --add-needed "libssl.so" "$elf"
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${lib.makeLibraryPath [stdenv.cc.cc openssl icu.out]}:\$ORIGIN" \ --set-rpath "${
"$elf" lib.makeLibraryPath [
} stdenv.cc.cc
openssl
icu.out
]
}:\$ORIGIN" \
"$elf"
}
substituteInPlace dist/extension.js \ substituteInPlace dist/extension.js \
--replace 'e.extensionPath,"cache"' 'require("os").tmpdir(),"'"$ext_unique_id"'"' \ --replace 'e.extensionPath,"cache"' 'require("os").tmpdir(),"'"$ext_unique_id"'"' \
--replace 't.setExecuteBit=async function(e){if("win32"!==process.platform){const t=i.join(e[a.SERVICEHUB_CONTROLLER_COMPONENT_NAME],"Microsoft.ServiceHub.Controller"),n=i.join(e[a.SERVICEHUB_HOST_COMPONENT_NAME],(0,a.getServiceHubHostEntrypointName)()),r=[(0,a.getServerPath)(e),t,n,(0,c.getReliabilityMonitorPath)(e)];await Promise.all(r.map((e=>(0,o.chmod)(e,"0755"))))}}' 't.setExecuteBit=async function(e){}' --replace 't.setExecuteBit=async function(e){if("win32"!==process.platform){const t=i.join(e[a.SERVICEHUB_CONTROLLER_COMPONENT_NAME],"Microsoft.ServiceHub.Controller"),n=i.join(e[a.SERVICEHUB_HOST_COMPONENT_NAME],(0,a.getServiceHubHostEntrypointName)()),r=[(0,a.getServerPath)(e),t,n,(0,c.getReliabilityMonitorPath)(e)];await Promise.all(r.map((e=>(0,o.chmod)(e,"0755"))))}}' 't.setExecuteBit=async function(e){}'
'' ''
+ (lib.concatStringsSep "\n" (map + (lib.concatStringsSep "\n" (
(bin: '' map (bin: ''
chmod +x "${bin}" chmod +x "${bin}"
'') '') extInfo.binaries
extInfo.binaries)) ))
+ lib.optionalString stdenv.isLinux (lib.concatStringsSep "\n" (map + lib.optionalString stdenv.isLinux (
(bin: '' lib.concatStringsSep "\n" (
patchelf_common "${bin}" map (bin: ''
'') patchelf_common "${bin}"
extInfo.binaries)); '') extInfo.binaries
)
);
meta = { meta = {
changelog = "https://marketplace.visualstudio.com/items/ms-dotnettools.csdevkit/changelog"; changelog = "https://marketplace.visualstudio.com/items/ms-dotnettools.csdevkit/changelog";
@ -112,6 +120,11 @@ buildVscodeMarketplaceExtension {
downloadPage = "https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit"; downloadPage = "https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit";
license = lib.licenses.unfree; license = lib.licenses.unfree;
maintainers = [ lib.maintainers.ggg ]; maintainers = [ lib.maintainers.ggg ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
}; };
} }

View File

@ -1,11 +1,11 @@
{ lib {
, vscode-utils lib,
, patchelf vscode-utils,
, icu patchelf,
, stdenv icu,
, openssl stdenv,
, coreutils openssl,
, coreutils,
}: }:
let let
inherit (stdenv.hostPlatform) system; inherit (stdenv.hostPlatform) system;
@ -26,31 +26,32 @@ let
".debugger/x86_64/vsdbg" ".debugger/x86_64/vsdbg"
]; ];
in in
{ {
x86_64-linux = { x86_64-linux = {
arch = "linux-x64"; arch = "linux-x64";
hash = "sha256-si4HKGVIHu44QNlNI2WEnMff9+QZOMWiBfWQaaFGyQE="; hash = "sha256-si4HKGVIHu44QNlNI2WEnMff9+QZOMWiBfWQaaFGyQE=";
binaries = linuxBins; binaries = linuxBins;
}; };
aarch64-linux = { aarch64-linux = {
arch = "linux-arm64"; arch = "linux-arm64";
hash = "sha256-1IXkSRgCHOLD4VeCdqyy54MXCBUX5RDDb3pf7GQH5jA="; hash = "sha256-1IXkSRgCHOLD4VeCdqyy54MXCBUX5RDDb3pf7GQH5jA=";
binaries = linuxBins; binaries = linuxBins;
}; };
x86_64-darwin = { x86_64-darwin = {
arch = "darwin-x64"; arch = "darwin-x64";
hash = "sha256-AAbYjZ+YYyGEXSLkiFfluLf7P4OzPhmHzK44N5XT9UI="; hash = "sha256-AAbYjZ+YYyGEXSLkiFfluLf7P4OzPhmHzK44N5XT9UI=";
binaries = darwinBins; binaries = darwinBins;
}; };
aarch64-darwin = { aarch64-darwin = {
arch = "darwin-arm64"; arch = "darwin-arm64";
hash = "sha256-1m47kX0Jo+UvthNfgdoPdBBOcDyCA8DfP+zRk3SicR0="; hash = "sha256-1m47kX0Jo+UvthNfgdoPdBBOcDyCA8DfP+zRk3SicR0=";
binaries = darwinBins ++ [ binaries = darwinBins ++ [
".debugger/arm64/vsdbg-ui" ".debugger/arm64/vsdbg-ui"
".debugger/arm64/vsdbg" ".debugger/arm64/vsdbg"
]; ];
}; };
}.${system} or (throw "Unsupported system: ${system}"); }
.${system} or (throw "Unsupported system: ${system}");
in in
buildVscodeMarketplaceExtension { buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {
@ -60,16 +61,13 @@ buildVscodeMarketplaceExtension {
inherit (extInfo) hash arch; inherit (extInfo) hash arch;
}; };
nativeBuildInputs = [ nativeBuildInputs = [ patchelf ];
patchelf
];
postPatch = '' postPatch =
''
patchelf_add_icu_as_needed() { patchelf_add_icu_as_needed() {
declare elf="''${1?}" declare elf="''${1?}"
declare icu_major_v="${ declare icu_major_v="${lib.head (lib.splitVersion (lib.getVersion icu.name))}"
lib.head (lib.splitVersion (lib.getVersion icu.name))
}"
for icu_lib in icui18n icuuc icudata; do for icu_lib in icui18n icuuc icudata; do
patchelf --add-needed "lib''${icu_lib}.so.$icu_major_v" "$elf" patchelf --add-needed "lib''${icu_lib}.so.$icu_major_v" "$elf"
@ -82,7 +80,13 @@ buildVscodeMarketplaceExtension {
patchelf_add_icu_as_needed "$elf" patchelf_add_icu_as_needed "$elf"
patchelf --add-needed "libssl.so" "$elf" patchelf --add-needed "libssl.so" "$elf"
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \ patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${lib.makeLibraryPath [stdenv.cc.cc openssl icu.out]}:\$ORIGIN" \ --set-rpath "${
lib.makeLibraryPath [
stdenv.cc.cc
openssl
icu.out
]
}:\$ORIGIN" \
"$elf" "$elf"
} }
@ -90,22 +94,29 @@ buildVscodeMarketplaceExtension {
--replace 'uname -m' '${lib.getExe' coreutils "uname"} -m' --replace 'uname -m' '${lib.getExe' coreutils "uname"} -m'
'' ''
+ (lib.concatStringsSep "\n" (map + (lib.concatStringsSep "\n" (
(bin: '' map (bin: ''
chmod +x "${bin}" chmod +x "${bin}"
'') '') extInfo.binaries
extInfo.binaries)) ))
+ lib.optionalString stdenv.isLinux (lib.concatStringsSep "\n" (map + lib.optionalString stdenv.isLinux (
(bin: '' lib.concatStringsSep "\n" (
patchelf_common "${bin}" map (bin: ''
'') patchelf_common "${bin}"
extInfo.binaries)); '') extInfo.binaries
)
);
meta = { meta = {
description = "Official C# support for Visual Studio Code"; description = "Official C# support for Visual Studio Code";
homepage = "https://github.com/dotnet/vscode-csharp"; homepage = "https://github.com/dotnet/vscode-csharp";
license = lib.licenses.mit; license = lib.licenses.mit;
maintainers = with lib.maintainers; [ ggg ]; maintainers = with lib.maintainers; [ ggg ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
}; };
} }

View File

@ -1,19 +1,20 @@
{ lib {
, vscode-utils lib,
, icu vscode-utils,
, python3 icu,
python3,
# When `true`, the python default setting will be fixed to specified. # When `true`, the python default setting will be fixed to specified.
# Use version from `PATH` for default setting otherwise. # Use version from `PATH` for default setting otherwise.
# Defaults to `false` as we expect it to be project specific most of the time. # Defaults to `false` as we expect it to be project specific most of the time.
, pythonUseFixed ? false pythonUseFixed ? false,
# For updateScript # For updateScript
, writeScript writeScript,
, bash bash,
, curl curl,
, coreutils coreutils,
, gnused gnused,
, jq jq,
, nix nix,
}: }:
vscode-utils.buildVscodeMarketplaceExtension rec { vscode-utils.buildVscodeMarketplaceExtension rec {
@ -33,33 +34,37 @@ vscode-utils.buildVscodeMarketplaceExtension rec {
jedi-language-server jedi-language-server
]; ];
postPatch = '' postPatch =
# remove bundled python deps and use libs from nixpkgs ''
rm -r pythonFiles/lib # remove bundled python deps and use libs from nixpkgs
mkdir -p pythonFiles/lib/python/ rm -r pythonFiles/lib
ln -s ${python3.pkgs.debugpy}/lib/*/site-packages/debugpy pythonFiles/lib/python/ mkdir -p pythonFiles/lib/python/
buildPythonPath "$propagatedBuildInputs" ln -s ${python3.pkgs.debugpy}/lib/*/site-packages/debugpy pythonFiles/lib/python/
for i in pythonFiles/*.py; do buildPythonPath "$propagatedBuildInputs"
patchPythonScript "$i" for i in pythonFiles/*.py; do
done patchPythonScript "$i"
'' + lib.optionalString pythonUseFixed '' done
# Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`. ''
substituteInPlace "./package.json" \ + lib.optionalString pythonUseFixed ''
--replace "\"default\": \"python\"" "\"default\": \"${python3.interpreter}\"" # Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`.
''; substituteInPlace "./package.json" \
--replace "\"default\": \"python\"" "\"default\": \"${python3.interpreter}\""
'';
passthru.updateScript = writeScript "update" '' passthru.updateScript = writeScript "update" ''
#! ${bash}/bin/bash #! ${bash}/bin/bash
set -eu -o pipefail set -eu -o pipefail
export PATH=${lib.makeBinPath [ export PATH=${
curl lib.makeBinPath [
coreutils curl
gnused coreutils
jq gnused
nix jq
]} nix
]
}
api=$(curl -s 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \ api=$(curl -s 'https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery' \
-H 'accept: application/json;api-version=3.0-preview.1' \ -H 'accept: application/json;api-version=3.0-preview.1' \
@ -82,7 +87,14 @@ vscode-utils.buildVscodeMarketplaceExtension rec {
homepage = "https://github.com/Microsoft/vscode-python"; homepage = "https://github.com/Microsoft/vscode-python";
changelog = "https://github.com/microsoft/vscode-python/releases"; changelog = "https://github.com/microsoft/vscode-python/releases";
license = lib.licenses.mit; license = lib.licenses.mit;
platforms = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; platforms = [
maintainers = [ lib.maintainers.jraygauthier lib.maintainers.jfchevrette ]; "x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
maintainers = [
lib.maintainers.jraygauthier
lib.maintainers.jfchevrette
];
}; };
} }

View File

@ -1,4 +1,9 @@
{ lib, vscode-utils, jq, moreutils }: {
lib,
vscode-utils,
jq,
moreutils,
}:
vscode-utils.buildVscodeMarketplaceExtension { vscode-utils.buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {

View File

@ -1,7 +1,8 @@
{ lib {
, nixosTests lib,
, vscode-utils nixosTests,
, useLocalExtensions ? false vscode-utils,
useLocalExtensions ? false,
}: }:
# Note that useLocalExtensions requires that vscode-server is not running # Note that useLocalExtensions requires that vscode-server is not running
# on host. If it is, you'll need to remove $HOME/.vscode-server, # on host. If it is, you'll need to remove $HOME/.vscode-server,
@ -92,7 +93,9 @@ buildVscodeMarketplaceExtension {
--replace '# Start the server\n' '${patch}' --replace '# Start the server\n' '${patch}'
''; '';
passthru.tests = { inherit (nixosTests) vscode-remote-ssh; }; passthru.tests = {
inherit (nixosTests) vscode-remote-ssh;
};
meta = { meta = {
description = "Use any remote machine with a SSH server as your development environment."; description = "Use any remote machine with a SSH server as your development environment.";

View File

@ -1,8 +1,19 @@
{ lib, vscode-utils {
, fetchurl, writeScript, runtimeShell lib,
, jq, clang-tools vscode-utils,
, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise. fetchurl,
, autoPatchelfHook, makeWrapper, stdenv, lttng-ust, libkrb5, zlib writeScript,
runtimeShell,
jq,
clang-tools,
gdbUseFixed ? true,
gdb, # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise.
autoPatchelfHook,
makeWrapper,
stdenv,
lttng-ust,
libkrb5,
zlib,
}: }:
/* /*
@ -94,7 +105,13 @@ vscode-utils.buildVscodeMarketplaceExtension {
description = "The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging."; description = "The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging.";
homepage = "https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools"; homepage = "https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools";
license = lib.licenses.unfree; license = lib.licenses.unfree;
maintainers = [ lib.maintainers.jraygauthier lib.maintainers.stargate01 ]; maintainers = [
platforms = [ "x86_64-linux" "aarch64-linux" ]; lib.maintainers.jraygauthier
lib.maintainers.stargate01
];
platforms = [
"x86_64-linux"
"aarch64-linux"
];
}; };
} }

View File

@ -1,4 +1,8 @@
{ lib, vscode-utils, xsel }: {
lib,
vscode-utils,
xsel,
}:
vscode-utils.buildVscodeMarketplaceExtension { vscode-utils.buildVscodeMarketplaceExtension {
mktplcRef = { mktplcRef = {

View File

@ -1,16 +1,17 @@
{ lib {
, fetchFromGitHub lib,
, vscode-utils fetchFromGitHub,
, jq vscode-utils,
, rust-analyzer jq,
, nodePackages rust-analyzer,
, moreutils nodePackages,
, esbuild moreutils,
, pkg-config esbuild,
, libsecret pkg-config,
, stdenv libsecret,
, darwin stdenv,
, setDefaultServerPath ? true darwin,
setDefaultServerPath ? true,
}: }:
let let
@ -29,26 +30,32 @@ let
hash = "sha256-Oj/RPMridKpYt3eRqUIPg9YNrj6npG8THIGuWjsamnE="; hash = "sha256-Oj/RPMridKpYt3eRqUIPg9YNrj6npG8THIGuWjsamnE=";
}; };
build-deps = nodePackages."rust-analyzer-build-deps-../../applications/editors/vscode/extensions/rust-lang.rust-analyzer/build-deps"; build-deps =
nodePackages."rust-analyzer-build-deps-../../applications/editors/vscode/extensions/rust-lang.rust-analyzer/build-deps";
# FIXME: Making a new derivation to link `node_modules` and run `npm run package` # FIXME: Making a new derivation to link `node_modules` and run `npm run package`
# will cause a build failure. # will cause a build failure.
vsix = build-deps.override { vsix = build-deps.override {
src = "${src}/editors/code"; src = "${src}/editors/code";
outputs = [ "vsix" "out" ]; outputs = [
"vsix"
"out"
];
inherit releaseTag; inherit releaseTag;
nativeBuildInputs = [ nativeBuildInputs =
jq [
moreutils jq
esbuild moreutils
# Required by `keytar`, which is a dependency of `vsce`. esbuild
pkg-config # Required by `keytar`, which is a dependency of `vsce`.
libsecret pkg-config
] ++ lib.optionals stdenv.isDarwin [ libsecret
darwin.apple_sdk.frameworks.AppKit ]
darwin.apple_sdk.frameworks.Security ++ lib.optionals stdenv.isDarwin [
]; darwin.apple_sdk.frameworks.AppKit
darwin.apple_sdk.frameworks.Security
];
# Follows https://github.com/rust-lang/rust-analyzer/blob/41949748a6123fd6061eb984a47f4fe780525e63/xtask/src/dist.rs#L39-L65 # Follows https://github.com/rust-lang/rust-analyzer/blob/41949748a6123fd6061eb984a47f4fe780525e63/xtask/src/dist.rs#L39-L65
postRebuild = '' postRebuild = ''
@ -65,7 +72,6 @@ let
echo y | npx vsce package -o $vsix/${pname}.zip echo y | npx vsce package -o $vsix/${pname}.zip
''; '';
}; };
in in
vscode-utils.buildVscodeExtension { vscode-utils.buildVscodeExtension {
inherit version vsix; inherit version vsix;
@ -75,7 +81,10 @@ vscode-utils.buildVscodeExtension {
vscodeExtPublisher = publisher; vscodeExtPublisher = publisher;
vscodeExtName = pname; vscodeExtName = pname;
nativeBuildInputs = lib.optionals setDefaultServerPath [ jq moreutils ]; nativeBuildInputs = lib.optionals setDefaultServerPath [
jq
moreutils
];
preInstall = lib.optionalString setDefaultServerPath '' preInstall = lib.optionalString setDefaultServerPath ''
jq '.contributes.configuration.properties."rust-analyzer.server.path".default = $s' \ jq '.contributes.configuration.properties."rust-analyzer.server.path".default = $s' \
@ -86,9 +95,11 @@ vscode-utils.buildVscodeExtension {
meta = { meta = {
description = "An alternative rust language server to the RLS"; description = "An alternative rust language server to the RLS";
homepage = "https://github.com/rust-lang/rust-analyzer"; homepage = "https://github.com/rust-lang/rust-analyzer";
license = [ lib.licenses.mit lib.licenses.asl20 ]; license = [
lib.licenses.mit
lib.licenses.asl20
];
maintainers = [ ]; maintainers = [ ];
platforms = lib.platforms.all; platforms = lib.platforms.all;
}; };
} }

View File

@ -1,6 +1,7 @@
{ lib {
, vscode-utils lib,
, lua-language-server vscode-utils,
lua-language-server,
}: }:
vscode-utils.buildVscodeMarketplaceExtension { vscode-utils.buildVscodeMarketplaceExtension {

View File

@ -1,39 +1,43 @@
# Updates the vscode setting file base on a nix expression # Updates the vscode setting file base on a nix expression
# should run from the workspace root. # should run from the workspace root.
{ writeShellScriptBin {
, lib writeShellScriptBin,
, jq lib,
jq,
}: }:
##User Input ##User Input
{ settings ? {} {
# if marked as true will create an empty json file if does not exist settings ? { },
, createIfDoesNotExists ? true # if marked as true will create an empty json file if does not exist
, vscodeSettingsFile ? ".vscode/settings.json" createIfDoesNotExists ? true,
, userSettingsFolder ? "" vscodeSettingsFile ? ".vscode/settings.json",
, symlinkFromUserSetting ? false userSettingsFolder ? "",
symlinkFromUserSetting ? false,
}: }:
let let
updateVSCodeSettingsCmd = '' updateVSCodeSettingsCmd = ''
( (
echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...' echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...'
oldSettings=$(cat ${vscodeSettingsFile}) oldSettings=$(cat ${vscodeSettingsFile})
echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile} echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile}
)''; )'';
createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}''; createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}'';
fileName = builtins.baseNameOf vscodeSettingsFile; fileName = builtins.baseNameOf vscodeSettingsFile;
symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting ''&& mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
'' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" '';
in in
writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' (
(lib.optionalString (settings != {}) lib.optionalString (settings != { }) (
(if createIfDoesNotExists then '' if createIfDoesNotExists then
[ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd} ''
${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd}
'' ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} ''
'' else
) ''
[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd}
''
) )
)

View File

@ -1,5 +1,5 @@
with import <nixpkgs>{}; with import <nixpkgs> { };
callPackage (import ./updateSettings.nix) {} { callPackage (import ./updateSettings.nix) { } {
settings = { settings = {
a = "fdsdf"; a = "fdsdf";
}; };

View File

@ -1,5 +1,20 @@
{ pkgs, lib, stdenv, fetchFromGitHub, runCommand, rustPlatform, makeWrapper, llvmPackages {
, buildNpmPackage, cmake, nodejs, unzip, python3, pkg-config, libsecret, darwin pkgs,
lib,
stdenv,
fetchFromGitHub,
runCommand,
rustPlatform,
makeWrapper,
llvmPackages,
buildNpmPackage,
cmake,
nodejs,
unzip,
python3,
pkg-config,
libsecret,
darwin,
}: }:
assert lib.versionAtLeast python3.version "3.5"; assert lib.versionAtLeast python3.version "3.5";
let let
@ -31,9 +46,7 @@ let
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
env = lib.optionalAttrs stdenv.isDarwin { env = lib.optionalAttrs stdenv.isDarwin { NIX_LDFLAGS = "-llldb -lc++abi"; };
NIX_LDFLAGS = "-llldb -lc++abi";
};
buildAndTestSubdir = "adapter"; buildAndTestSubdir = "adapter";
@ -76,12 +89,15 @@ let
pkg-config pkg-config
]; ];
buildInputs = [ buildInputs =
libsecret [ libsecret ]
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ ++ lib.optionals stdenv.isDarwin (
Security with darwin.apple_sdk.frameworks;
AppKit [
]); Security
AppKit
]
);
dontNpmBuild = true; dontNpmBuild = true;
@ -103,14 +119,25 @@ let
"/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver" "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver"
else else
"${lldb.out}/bin/lldb-server"; "${lldb.out}/bin/lldb-server";
in
in stdenv.mkDerivation { stdenv.mkDerivation {
pname = "vscode-extension-${publisher}-${pname}"; pname = "vscode-extension-${publisher}-${pname}";
inherit src version vscodeExtUniqueId vscodeExtPublisher vscodeExtName; inherit
src
version
vscodeExtUniqueId
vscodeExtPublisher
vscodeExtName
;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}"; installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
nativeBuildInputs = [ cmake nodejs unzip makeWrapper ]; nativeBuildInputs = [
cmake
nodejs
unzip
makeWrapper
];
patches = [ ./cmake-build-extension-only.patch ]; patches = [ ./cmake-build-extension-only.patch ];
@ -120,12 +147,14 @@ in stdenv.mkDerivation {
--replace "1.9.2" ${version} --replace "1.9.2" ${version}
''; '';
postConfigure = '' postConfigure =
cp -r ${nodeDeps}/lib/node_modules . ''
'' + lib.optionalString stdenv.isDarwin '' cp -r ${nodeDeps}/lib/node_modules .
export HOME="$TMPDIR/home" ''
mkdir $HOME + lib.optionalString stdenv.isDarwin ''
''; export HOME="$TMPDIR/home"
mkdir $HOME
'';
cmakeFlags = [ cmakeFlags = [
# Do not append timestamp to version. # Do not append timestamp to version.

View File

@ -1,5 +1,9 @@
# Patched lldb for Rust language support. # Patched lldb for Rust language support.
{ fetchFromGitHub, runCommand, llvmPackages }: {
fetchFromGitHub,
runCommand,
llvmPackages,
}:
let let
llvmSrc = fetchFromGitHub { llvmSrc = fetchFromGitHub {
owner = "vadimcn"; owner = "vadimcn";
@ -8,8 +12,9 @@ let
rev = "4c267c83cbb55fedf2e0b89644dc1db320fdfde7"; rev = "4c267c83cbb55fedf2e0b89644dc1db320fdfde7";
hash = "sha256-jM//ej6AxnRYj+8BAn4QrxHPT6HiDzK5RqHPSg3dCcw="; hash = "sha256-jM//ej6AxnRYj+8BAn4QrxHPT6HiDzK5RqHPSg3dCcw=";
}; };
in (llvmPackages.lldb.overrideAttrs (oldAttrs: rec { in
passthru = (oldAttrs.passthru or {}) // { (llvmPackages.lldb.overrideAttrs (oldAttrs: rec {
passthru = (oldAttrs.passthru or { }) // {
inherit llvmSrc; inherit llvmSrc;
}; };
@ -23,7 +28,8 @@ in (llvmPackages.lldb.overrideAttrs (oldAttrs: rec {
echo "'lldb --version' returns: $versionOutput" echo "'lldb --version' returns: $versionOutput"
echo "$versionOutput" | grep -q 'rust-enabled' echo "$versionOutput" | grep -q 'rust-enabled'
''; '';
})).override({ })).override
monorepoSrc = llvmSrc; ({
libllvm = llvmPackages.libllvm.override({ monorepoSrc = llvmSrc; }); monorepoSrc = llvmSrc;
}) libllvm = llvmPackages.libllvm.override ({ monorepoSrc = llvmSrc; });
})

View File

@ -1,77 +1,101 @@
{ stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }: {
stdenv,
lib,
buildEnv,
writeShellScriptBin,
fetchurl,
vscode,
unzip,
jq,
}:
let let
buildVscodeExtension = a@{ buildVscodeExtension =
name, a@{
src, name,
# Same as "Unique Identifier" on the extension's web page. src,
# For the moment, only serve as unique extension dir. # Same as "Unique Identifier" on the extension's web page.
vscodeExtPublisher, # For the moment, only serve as unique extension dir.
vscodeExtName, vscodeExtPublisher,
vscodeExtUniqueId, vscodeExtName,
configurePhase ? '' vscodeExtUniqueId,
runHook preConfigure configurePhase ? ''
runHook postConfigure runHook preConfigure
'', runHook postConfigure
buildPhase ?'' '',
runHook preBuild buildPhase ? ''
runHook postBuild runHook preBuild
'', runHook postBuild
dontPatchELF ? true, '',
dontStrip ? true, dontPatchELF ? true,
nativeBuildInputs ? [], dontStrip ? true,
passthru ? { }, nativeBuildInputs ? [ ],
... passthru ? { },
}: ...
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // { }:
stdenv.mkDerivation (
(removeAttrs a [ "vscodeExtUniqueId" ])
// {
name = "vscode-extension-${name}"; name = "vscode-extension-${name}";
passthru = passthru // { passthru = passthru // {
inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId; inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
}; };
inherit configurePhase buildPhase dontPatchELF dontStrip; inherit
configurePhase
buildPhase
dontPatchELF
dontStrip
;
# Some .vsix files contain other directories (e.g., `package`) that we don't use. # Some .vsix files contain other directories (e.g., `package`) that we don't use.
# If other directories are present but `sourceRoot` is unset, the unpacker phase fails. # If other directories are present but `sourceRoot` is unset, the unpacker phase fails.
sourceRoot = "extension"; sourceRoot = "extension";
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}"; installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs; nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
mkdir -p "$out/$installPrefix" mkdir -p "$out/$installPrefix"
find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/" find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
runHook postInstall runHook postInstall
''; '';
}
);
}); fetchVsixFromVscodeMarketplace =
mktplcExtRef: fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef);
fetchVsixFromVscodeMarketplace = mktplcExtRef: buildVscodeMarketplaceExtension =
fetchurl (import ./mktplcExtRefToFetchArgs.nix mktplcExtRef); a@{
name ? "",
buildVscodeMarketplaceExtension = a@{ src ? null,
name ? "", vsix ? null,
src ? null, mktplcRef,
vsix ? null, ...
mktplcRef, }:
... assert "" == name;
}: assert "" == name; assert null == src; assert null == src;
buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // { buildVscodeExtension (
name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; (removeAttrs a [
version = mktplcRef.version; "mktplcRef"
src = if (vsix != null) "vsix"
then vsix ])
else fetchVsixFromVscodeMarketplace mktplcRef; // {
vscodeExtPublisher = mktplcRef.publisher; name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
vscodeExtName = mktplcRef.name; version = mktplcRef.version;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; src = if (vsix != null) then vsix else fetchVsixFromVscodeMarketplace mktplcRef;
}); vscodeExtPublisher = mktplcRef.publisher;
vscodeExtName = mktplcRef.name;
vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
}
);
mktplcRefAttrList = [ mktplcRefAttrList = [
"name" "name"
@ -82,14 +106,18 @@ let
"arch" "arch"
]; ];
mktplcExtRefToExtDrv = ext: mktplcExtRefToExtDrv =
buildVscodeMarketplaceExtension (removeAttrs ext mktplcRefAttrList // { ext:
mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext; buildVscodeMarketplaceExtension (
}); removeAttrs ext mktplcRefAttrList
// {
mktplcRef = builtins.intersectAttrs (lib.genAttrs mktplcRefAttrList (_: null)) ext;
}
);
extensionFromVscodeMarketplace = mktplcExtRefToExtDrv; extensionFromVscodeMarketplace = mktplcExtRefToExtDrv;
extensionsFromVscodeMarketplace = mktplcExtRefList: extensionsFromVscodeMarketplace =
builtins.map extensionFromVscodeMarketplace mktplcExtRefList; mktplcExtRefList: builtins.map extensionFromVscodeMarketplace mktplcExtRefList;
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { vscodeWithConfiguration = import ./vscodeWithConfiguration.nix {
inherit lib extensionsFromVscodeMarketplace writeShellScriptBin; inherit lib extensionsFromVscodeMarketplace writeShellScriptBin;
@ -102,7 +130,13 @@ let
}; };
vscodeEnv = import ./vscodeEnv.nix { vscodeEnv = import ./vscodeEnv.nix {
inherit lib buildEnv writeShellScriptBin extensionsFromVscodeMarketplace jq; inherit
lib
buildEnv
writeShellScriptBin
extensionsFromVscodeMarketplace
jq
;
vscodeDefault = vscode; vscodeDefault = vscode;
}; };
@ -139,9 +173,16 @@ let
toExtensionJson = extensions: builtins.toJSON (map toExtensionJsonEntry extensions); toExtensionJson = extensions: builtins.toJSON (map toExtensionJsonEntry extensions);
in in
{ {
inherit fetchVsixFromVscodeMarketplace buildVscodeExtension inherit
buildVscodeMarketplaceExtension extensionFromVscodeMarketplace fetchVsixFromVscodeMarketplace
extensionsFromVscodeMarketplace buildVscodeExtension
vscodeWithConfiguration vscodeExts2nix vscodeEnv buildVscodeMarketplaceExtension
toExtensionJsonEntry toExtensionJson; extensionFromVscodeMarketplace
extensionsFromVscodeMarketplace
vscodeWithConfiguration
vscodeExts2nix
vscodeEnv
toExtensionJsonEntry
toExtensionJson
;
} }

View File

@ -1,47 +1,58 @@
#Use vscodeWithConfiguration and vscodeExts2nix to create a vscode executable. When the executable exits, it updates the mutable extension file, which is imported when evaluated by Nix later. #Use vscodeWithConfiguration and vscodeExts2nix to create a vscode executable. When the executable exits, it updates the mutable extension file, which is imported when evaluated by Nix later.
{ lib {
, buildEnv lib,
, writeShellScriptBin buildEnv,
, extensionsFromVscodeMarketplace writeShellScriptBin,
, vscodeDefault extensionsFromVscodeMarketplace,
, jq vscodeDefault,
jq,
}: }:
##User input ##User input
{ vscode ? vscodeDefault {
, nixExtensions ? [] vscode ? vscodeDefault,
, vscodeExtsFolderName ? ".vscode-exts" nixExtensions ? [ ],
# will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file vscodeExtsFolderName ? ".vscode-exts",
, settings ? {} # will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file
, createSettingsIfDoesNotExists ? true settings ? { },
, launch ? {} createSettingsIfDoesNotExists ? true,
, createLaunchIfDoesNotExists ? true launch ? { },
# will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file createLaunchIfDoesNotExists ? true,
, keybindings ? {} # will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
, createKeybindingsIfDoesNotExists ? true keybindings ? { },
, user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'' createKeybindingsIfDoesNotExists ? true,
# if file exists will use it and import the extensions in it into this derivation else will use empty extensions list user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'',
# this file will be created/updated by vscodeExts2nix when vscode exists # if file exists will use it and import the extensions in it into this derivation else will use empty extensions list
, mutableExtensionsFile # this file will be created/updated by vscodeExts2nix when vscode exists
mutableExtensionsFile,
}: }:
let let
mutableExtensionsFilePath = toString mutableExtensionsFile; mutableExtensionsFilePath = toString mutableExtensionsFile;
mutableExtensions = lib.optionals (builtins.pathExists mutableExtensionsFile) (import mutableExtensionsFilePath); mutableExtensions = lib.optionals (builtins.pathExists mutableExtensionsFile) (
vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { import mutableExtensionsFilePath
inherit lib writeShellScriptBin extensionsFromVscodeMarketplace; );
vscodeDefault = vscode; vscodeWithConfiguration =
} import ./vscodeWithConfiguration.nix
{ {
inherit nixExtensions mutableExtensions vscodeExtsFolderName user-data-dir; inherit lib writeShellScriptBin extensionsFromVscodeMarketplace;
}; vscodeDefault = vscode;
}
{
inherit
nixExtensions
mutableExtensions
vscodeExtsFolderName
user-data-dir
;
};
updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; }; updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; };
userSettingsFolder = "${ user-data-dir }/User"; userSettingsFolder = "${user-data-dir}/User";
updateSettingsCmd = updateSettings { updateSettingsCmd = updateSettings {
settings = { settings = {
"extensions.autoCheckUpdates" = false; "extensions.autoCheckUpdates" = false;
"extensions.autoUpdate" = false; "extensions.autoUpdate" = false;
"update.mode" = "none"; "update.mode" = "none";
} // settings; } // settings;
inherit userSettingsFolder; inherit userSettingsFolder;
createIfDoesNotExists = createSettingsIfDoesNotExists; createIfDoesNotExists = createSettingsIfDoesNotExists;
@ -62,14 +73,16 @@ let
symlinkFromUserSetting = (user-data-dir != ""); symlinkFromUserSetting = (user-data-dir != "");
}; };
vscodeExts2nix = import ./vscodeExts2nix.nix { vscodeExts2nix =
inherit lib writeShellScriptBin; import ./vscodeExts2nix.nix
vscodeDefault = vscodeWithConfiguration; {
} inherit lib writeShellScriptBin;
{ vscodeDefault = vscodeWithConfiguration;
extensionsToIgnore = nixExtensions; }
extensions = mutableExtensions; {
}; extensionsToIgnore = nixExtensions;
extensions = mutableExtensions;
};
code = writeShellScriptBin "code" '' code = writeShellScriptBin "code" ''
${updateSettingsCmd}/bin/vscodeNixUpdate-settings ${updateSettingsCmd}/bin/vscodeNixUpdate-settings
${updateLaunchCmd}/bin/vscodeNixUpdate-launch ${updateLaunchCmd}/bin/vscodeNixUpdate-launch
@ -81,5 +94,11 @@ let
in in
buildEnv { buildEnv {
name = "vscodeEnv"; name = "vscodeEnv";
paths = [ code vscodeExts2nix updateSettingsCmd updateLaunchCmd updateKeybindingsCmd ]; paths = [
code
vscodeExts2nix
updateSettingsCmd
updateLaunchCmd
updateKeybindingsCmd
];
} }

View File

@ -1,11 +1,13 @@
with import <nixpkgs>{}; with import <nixpkgs> { };
callPackage (import ./vscodeEnv.nix) { callPackage (import ./vscodeEnv.nix)
extensionsFromVscodeMarketplace = vscode-utils.extensionsFromVscodeMarketplace; {
vscodeDefault = vscode; extensionsFromVscodeMarketplace = vscode-utils.extensionsFromVscodeMarketplace;
} { vscodeDefault = vscode;
mutableExtensionsFile = ./extensions.nix; }
settings = { {
a = "fdsdf"; mutableExtensionsFile = ./extensions.nix;
t = "test"; settings = {
}; a = "fdsdf";
} t = "test";
};
}

View File

@ -1,14 +1,16 @@
# based on the passed vscode will stdout a nix expression with the installed vscode extensions # based on the passed vscode will stdout a nix expression with the installed vscode extensions
{ lib {
, vscodeDefault lib,
, writeShellScriptBin vscodeDefault,
writeShellScriptBin,
}: }:
##User input ##User input
{ vscode ? vscodeDefault {
, extensionsToIgnore ? [] vscode ? vscodeDefault,
# will use those extensions to get sha256 if still exists when executed. extensionsToIgnore ? [ ],
, extensions ? [] # will use those extensions to get sha256 if still exists when executed.
extensions ? [ ],
}: }:
let let
mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix; mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix;
@ -17,22 +19,32 @@ writeShellScriptBin "vscodeExts2nix" ''
echo '[' echo '['
for line in $(${vscode}/bin/code --list-extensions --show-versions \ for line in $(${vscode}/bin/code --list-extensions --show-versions \
${lib.optionalString (extensionsToIgnore != []) '' ${
| grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : "${e.publisher}.${e.name}") extensionsToIgnore}\)' lib.optionalString (extensionsToIgnore != [ ]) ''
''} | grep -v -i '^\(${
lib.concatMapStringsSep "\\|" (e: "${e.publisher}.${e.name}") extensionsToIgnore
}\)'
''
}
) ; do ) ; do
[[ $line =~ ([^.]*)\.([^@]*)@(.*) ]] [[ $line =~ ([^.]*)\.([^@]*)@(.*) ]]
name=''${BASH_REMATCH[2]} name=''${BASH_REMATCH[2]}
publisher=''${BASH_REMATCH[1]} publisher=''${BASH_REMATCH[1]}
version=''${BASH_REMATCH[3]} version=''${BASH_REMATCH[3]}
extensions="${lib.concatMapStringsSep "." (e : "${e.publisher}${e.name}@${e.sha256}") extensions}" extensions="${lib.concatMapStringsSep "." (e: "${e.publisher}${e.name}@${e.sha256}") extensions}"
reCurrentExt=$publisher$name"@([^.]*)" reCurrentExt=$publisher$name"@([^.]*)"
if [[ $extensions =~ $reCurrentExt ]]; then if [[ $extensions =~ $reCurrentExt ]]; then
sha256=''${BASH_REMATCH[1]} sha256=''${BASH_REMATCH[1]}
else else
sha256=$( sha256=$(
nix-prefetch-url "${(mktplcExtRefToFetchArgs {publisher = ''"$publisher"''; name = ''"$name"''; version = ''"$version"'';}).url}" 2> /dev/null nix-prefetch-url "${
(mktplcExtRefToFetchArgs {
publisher = ''"$publisher"'';
name = ''"$name"'';
version = ''"$version"'';
}).url
}" 2> /dev/null
) )
fi fi

View File

@ -1,54 +1,61 @@
# wrapper over vscode to control extensions per project (extensions folder will be created in execution path) # wrapper over vscode to control extensions per project (extensions folder will be created in execution path)
{ lib {
, writeShellScriptBin lib,
, extensionsFromVscodeMarketplace writeShellScriptBin,
, vscodeDefault extensionsFromVscodeMarketplace,
vscodeDefault,
}: }:
## User input ## User input
{ vscode ? vscodeDefault {
# extensions to be symlinked into the project's extensions folder vscode ? vscodeDefault,
, nixExtensions ? [] # extensions to be symlinked into the project's extensions folder
# extensions to be copied into the project's extensions folder nixExtensions ? [ ],
, mutableExtensions ? [] # extensions to be copied into the project's extensions folder
, vscodeExtsFolderName ? ".vscode-exts" mutableExtensions ? [ ],
, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"'' vscodeExtsFolderName ? ".vscode-exts",
user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"'',
}: }:
let let
nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions; nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions;
mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions; mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions;
mutableExtsPaths = lib.forEach mutExtsDrvs ( e: mutableExtsPaths = lib.forEach mutExtsDrvs (e: {
{
origin = "${e}/share/vscode/extensions/${e.vscodeExtUniqueId}"; origin = "${e}/share/vscode/extensions/${e.vscodeExtUniqueId}";
target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: "${ext.publisher}.${ext.name}" == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version}''; target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${
} (lib.findSingle (
); ext: "${ext.publisher}.${ext.name}" == e.vscodeExtUniqueId
) "" "m" mutableExtensions).version
}'';
});
#removed not defined extensions #removed not defined extensions
rmExtensions = lib.optionalString (nixExtensions++mutableExtensions != []) '' rmExtensions = lib.optionalString (nixExtensions ++ mutableExtensions != [ ]) ''
find ${vscodeExtsFolderName} -mindepth 1 -maxdepth 1 ${ find ${vscodeExtsFolderName} -mindepth 1 -maxdepth 1 ${
lib.concatMapStringsSep " " (e : "! -iname ${e.publisher}.${e.name} ") nixExtensions lib.concatMapStringsSep " " (e: "! -iname ${e.publisher}.${e.name} ") nixExtensions
+ + lib.concatMapStringsSep " " (
lib.concatMapStringsSep " " (e : "! -iname ${e.publisher}.${e.name}-${e.version} ") mutableExtensions e: "! -iname ${e.publisher}.${e.name}-${e.version} "
} -exec rm -rf {} \; ) mutableExtensions
} -exec rm -rf {} \;
''; '';
#copy mutable extension out of the nix store #copy mutable extension out of the nix store
cpExtensions = '' cpExtensions = ''
${lib.concatMapStringsSep "\n" (e : "ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/") nixExtsDrvs} ${lib.concatMapStringsSep "\n" (
${lib.concatMapStringsSep "\n" (ePath : '' e: "ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/"
) nixExtsDrvs}
${lib.concatMapStringsSep "\n" (ePath: ''
if [ ! -d ${ePath.target} ]; then if [ ! -d ${ePath.target} ]; then
cp -a ${ePath.origin} ${ePath.target} cp -a ${ePath.origin} ${ePath.target}
chmod -R u+rwx ${ePath.target} chmod -R u+rwx ${ePath.target}
fi fi
'') mutableExtsPaths} '') mutableExtsPaths}
''; '';
in in
writeShellScriptBin "code" '' writeShellScriptBin "code" ''
if ! [[ "$@" =~ "--list-extension" ]]; then if ! [[ "$@" =~ "--list-extension" ]]; then
mkdir -p "${vscodeExtsFolderName}" mkdir -p "${vscodeExtsFolderName}"
${rmExtensions} ${rmExtensions}
${cpExtensions} ${cpExtensions}
fi fi
${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${ ${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${
lib.optionalString (user-data-dir != "") "--user-data-dir ${user-data-dir}" lib.optionalString (user-data-dir != "") "--user-data-dir ${user-data-dir}"
} "$@" } "$@"
'' ''