diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-10-31 19:35:09 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-10-31 19:35:09 +0100 |
commit | c4625b175f8200f643fd6e11010932ea44c78433 (patch) | |
tree | bce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/applications/editors/vscode | |
parent | 49f735974dd103039ddc4cb576bb76555164a9e7 (diff) | |
parent | d661aa56a8843e991261510c1bb28fdc2f6975ae (diff) |
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie
git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7
git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/applications/editors/vscode')
6 files changed, 345 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/generic.nix b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/generic.nix new file mode 100644 index 000000000000..d0933905bcd1 --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/generic.nix @@ -0,0 +1,96 @@ +{ stdenv, lib, makeDesktopItem +, unzip, libsecret, libXScrnSaver, wrapGAppsHook +, gtk2, atomEnv, at-spi2-atk, autoPatchelfHook +, systemd, fontconfig, libdbusmenu + +# Attributes inherit from specific versions +, version, src, meta, sourceRoot +, executableName, longName, shortName, pname +}: + +let + inherit (stdenv.hostPlatform) system; +in + stdenv.mkDerivation { + + inherit pname version src sourceRoot; + + passthru = { + inherit executableName; + }; + + desktopItem = makeDesktopItem { + name = executableName; + desktopName = longName; + comment = "Code Editing. Redefined."; + genericName = "Text Editor"; + exec = "${executableName} %U"; + icon = "code"; + startupNotify = "true"; + categories = "Utility;TextEditor;Development;IDE;"; + mimeType = "text/plain;inode/directory;"; + extraEntries = '' + StartupWMClass=${shortName} + Actions=new-empty-window; + Keywords=vscode; + + [Desktop Action new-empty-window] + Name=New Empty Window + Exec=${executableName} --new-window %F + Icon=code + ''; + }; + + urlHandlerDesktopItem = makeDesktopItem { + name = executableName + "-url-handler"; + desktopName = longName + " - URL Handler"; + comment = "Code Editing. Redefined."; + genericName = "Text Editor"; + exec = executableName + " --open-url %U"; + icon = "code"; + startupNotify = "true"; + categories = "Utility;TextEditor;Development;IDE;"; + mimeType = "x-scheme-handler/vscode;"; + extraEntries = '' + NoDisplay=true + Keywords=vscode; + ''; + }; + + buildInputs = (if stdenv.isDarwin + then [ unzip ] + else [ gtk2 at-spi2-atk wrapGAppsHook ] ++ atomEnv.packages) + ++ [ libsecret libXScrnSaver ]; + + runtimeDependencies = lib.optional (stdenv.isLinux) [ (lib.getLib systemd) fontconfig.lib libdbusmenu ]; + + nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook; + + dontBuild = true; + dontConfigure = true; + + installPhase = + if system == "x86_64-darwin" then '' + mkdir -p "$out/Applications/${longName}.app" $out/bin + cp -r ./* "$out/Applications/${longName}.app" + ln -s "$out/Applications/${longName}.app/Contents/Resources/app/bin/code" $out/bin/${executableName} + '' else '' + mkdir -p $out/lib/vscode $out/bin + cp -r ./* $out/lib/vscode + + ln -s $out/lib/vscode/bin/${executableName} $out/bin + + mkdir -p $out/share/applications + ln -s $desktopItem/share/applications/${executableName}.desktop $out/share/applications/${executableName}.desktop + ln -s $urlHandlerDesktopItem/share/applications/${executableName}-url-handler.desktop $out/share/applications/${executableName}-url-handler.desktop + + mkdir -p $out/share/pixmaps + cp $out/lib/vscode/resources/app/resources/linux/code.png $out/share/pixmaps/code.png + + # Override the previously determined VSCODE_PATH with the one we know to be correct + sed -i "/ELECTRON=/iVSCODE_PATH='$out/lib/vscode'" $out/bin/${executableName} + grep -q "VSCODE_PATH='$out/lib/vscode'" $out/bin/${executableName} # check if sed succeeded + ''; + + inherit meta; + } diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscode.sh b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscode.sh new file mode 100755 index 000000000000..4974eb7e4367 --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscode.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnugrep gnused gawk + +# Update script for the vscode versions and hashes. +# Usually doesn't need to be called by hand, +# but is called by a bot: https://github.com/samuela/nixpkgs-upkeep/actions +# Call it by hand if the bot fails to automatically update the versions. + +set -eou pipefail + +ROOT="$(dirname "$(readlink -f "$0")")" +if [ ! -f "$ROOT/vscode.nix" ]; then + echo "ERROR: cannot find vscode.nix in $ROOT" + exit 1 +fi + +# VSCode + +VSCODE_VER=$(curl -s -L "https://code.visualstudio.com/Download" | grep "is now available" | awk -F'</span>' '{print $1}' | awk -F'>' '{print $NF}') +VSCODE_VER=$(curl -s -L "https://code.visualstudio.com/updates/v${VSCODE_VER/./_}" | grep "Downloads:" | awk -F'code.visualstudio.com/' '{print $2}' | awk -F'/' '{print $1}') +sed -i "s/version = \".*\"/version = \"${VSCODE_VER}\"/" "$ROOT/vscode.nix" + +VSCODE_LINUX_URL="https://vscode-update.azurewebsites.net/${VSCODE_VER}/linux-x64/stable" +VSCODE_LINUX_SHA256=$(nix-prefetch-url ${VSCODE_LINUX_URL}) +sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODE_LINUX_SHA256}\"/" "$ROOT/vscode.nix" + +VSCODE_DARWIN_URL="https://vscode-update.azurewebsites.net/${VSCODE_VER}/darwin/stable" +VSCODE_DARWIN_SHA256=$(nix-prefetch-url ${VSCODE_DARWIN_URL}) +sed -i "s/x86_64-darwin = \".\{52\}\"/x86_64-darwin = \"${VSCODE_DARWIN_SHA256}\"/" "$ROOT/vscode.nix" diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscodium.sh b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscodium.sh new file mode 100755 index 000000000000..0ddab6063cad --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/update-vscodium.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnugrep gnused gawk + +# Update script for the vscode versions and hashes. +# Usually doesn't need to be called by hand, +# but is called by a bot: https://github.com/samuela/nixpkgs-upkeep/actions +# Call it by hand if the bot fails to automatically update the versions. + +set -eou pipefail + +ROOT="$(dirname "$(readlink -f "$0")")" +if [ ! -f "$ROOT/vscodium.nix" ]; then + echo "ERROR: cannot find vscodium.nix in $ROOT" + exit 1 +fi + +# VSCodium + +VSCODIUM_VER=$(curl -Ls -w %{url_effective} -o /dev/null https://github.com/VSCodium/vscodium/releases/latest | awk -F'/' '{print $NF}') +sed -i "s/version = \".*\"/version = \"${VSCODIUM_VER}\"/" "$ROOT/vscodium.nix" + +VSCODIUM_LINUX_URL="https://github.com/VSCodium/vscodium/releases/download/${VSCODIUM_VER}/VSCodium-linux-x64-${VSCODIUM_VER}.tar.gz" +VSCODIUM_LINUX_SHA256=$(nix-prefetch-url ${VSCODIUM_LINUX_URL}) +sed -i "s/x86_64-linux = \".\{52\}\"/x86_64-linux = \"${VSCODIUM_LINUX_SHA256}\"/" "$ROOT/vscodium.nix" + +VSCODIUM_DARWIN_URL="https://github.com/VSCodium/vscodium/releases/download/${VSCODIUM_VER}/VSCodium-darwin-${VSCODIUM_VER}.zip" +VSCODIUM_DARWIN_SHA256=$(nix-prefetch-url ${VSCODIUM_DARWIN_URL}) +sed -i "s/x86_64-darwin = \".\{52\}\"/x86_64-darwin = \"${VSCODIUM_DARWIN_SHA256}\"/" "$ROOT/vscodium.nix" diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscode.nix b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscode.nix new file mode 100644 index 000000000000..528a0496d915 --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscode.nix @@ -0,0 +1,57 @@ +{ stdenv, lib, callPackage, fetchurl, isInsiders ? false }: + +let + inherit (stdenv.hostPlatform) system; + + plat = { + x86_64-linux = "linux-x64"; + x86_64-darwin = "darwin"; + }.${system}; + + archive_fmt = if system == "x86_64-darwin" then "zip" else "tar.gz"; + + sha256 = { + x86_64-linux = "0mpb4641icr3z89y2rlh5anli40p1f48sl5xagr7h3nb5c84k10x"; + x86_64-darwin = "1azmc79zf72007qc1xndp9wdkd078mvqgv35hf231q7kdi6wzxcp"; + }.${system}; +in + callPackage ./generic.nix rec { + # The update script doesn't correctly change the hash for darwin, so please: + # nixpkgs-update: no auto update + + # Please backport all compatible updates to the stable release. + # This is important for the extension ecosystem. + version = "1.50.1"; + pname = "vscode"; + + executableName = "code" + lib.optionalString isInsiders "-insiders"; + longName = "Visual Studio Code" + lib.optionalString isInsiders " - Insiders"; + shortName = "Code" + lib.optionalString isInsiders " - Insiders"; + + src = fetchurl { + name = "VSCode_${version}_${plat}.${archive_fmt}"; + url = "https://vscode-update.azurewebsites.net/${version}/${plat}/stable"; + inherit sha256; + }; + + sourceRoot = ""; + + meta = with stdenv.lib; { + description = '' + Open source source code editor developed by Microsoft for Windows, + Linux and macOS + ''; + longDescription = '' + Open source source code editor developed by Microsoft for Windows, + Linux and macOS. It includes support for debugging, embedded Git + control, syntax highlighting, intelligent code completion, snippets, + and code refactoring. It is also customizable, so users can change the + editor's theme, keyboard shortcuts, and preferences + ''; + homepage = "https://code.visualstudio.com/"; + downloadPage = "https://code.visualstudio.com/Updates"; + license = licenses.unfree; + maintainers = with maintainers; [ eadwu synthetica ]; + platforms = [ "x86_64-linux" "x86_64-darwin" ]; + }; + } diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscodium.nix b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscodium.nix new file mode 100644 index 000000000000..650e88a260b4 --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/vscodium.nix @@ -0,0 +1,60 @@ +{ stdenv, callPackage, fetchurl }: + +let + inherit (stdenv.hostPlatform) system; + + plat = { + x86_64-linux = "linux-x64"; + x86_64-darwin = "darwin"; + }.${system}; + + archive_fmt = if system == "x86_64-darwin" then "zip" else "tar.gz"; + + sha256 = { + x86_64-linux = "1sarih1yah69ympp12bmgyb0y9ybrxasppb47l58w05iz1wpn6v0"; + x86_64-darwin = "1pj041kccj2i77v223i86xxqj9bg88k0sfbshm7qiynwyj9p05ji"; + }.${system}; + + sourceRoot = { + x86_64-linux = "."; + x86_64-darwin = ""; + }.${system}; +in + callPackage ./generic.nix rec { + inherit sourceRoot; + # The update script doesn't correctly change the hash for darwin, so please: + # nixpkgs-update: no auto update + + # Please backport all compatible updates to the stable release. + # This is important for the extension ecosystem. + version = "1.50.1"; + pname = "vscodium"; + + executableName = "codium"; + longName = "VSCodium"; + shortName = "vscodium"; + + src = fetchurl { + url = "https://github.com/VSCodium/vscodium/releases/download/${version}/VSCodium-${plat}-${version}.${archive_fmt}"; + inherit sha256; + }; + + meta = with stdenv.lib; { + description = '' + Open source source code editor developed by Microsoft for Windows, + Linux and macOS (VS Code without MS branding/telemetry/licensing) + ''; + longDescription = '' + Open source source code editor developed by Microsoft for Windows, + Linux and macOS. It includes support for debugging, embedded Git + control, syntax highlighting, intelligent code completion, snippets, + and code refactoring. It is also customizable, so users can change the + editor's theme, keyboard shortcuts, and preferences + ''; + homepage = "https://github.com/VSCodium/vscodium"; + downloadPage = "https://github.com/VSCodium/vscodium/releases"; + license = licenses.mit; + maintainers = with maintainers; [ synthetica turion ]; + platforms = [ "x86_64-linux" "x86_64-darwin" ]; + }; + } diff --git a/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix new file mode 100644 index 000000000000..c30b52782ef3 --- /dev/null +++ b/infra/libkookie/nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix @@ -0,0 +1,75 @@ +{ lib, runCommand, buildEnv, vscode, makeWrapper +, vscodeExtensions ? [] }: + +/* + `vscodeExtensions` + : A set of vscode extensions to be installed alongside the editor. Here's a an + example: + + ~~~ + vscode-with-extensions.override { + + # When the extension is already available in the default extensions set. + vscodeExtensions = with vscode-extensions; [ + bbenoist.Nix + ] + + # Concise version from the vscode market place when not available in the default set. + ++ vscode-utils.extensionsFromVscodeMarketplace [ + { + name = "code-runner"; + publisher = "formulahendry"; + version = "0.6.33"; + sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0"; + } + ]; + } + ~~~ + + This expression should fetch + - the *nix* vscode extension from whatever source defined in the + default nixpkgs extensions set `vscodeExtensions`. + + - the *code-runner* vscode extension from the marketplace using the + following url: + + ~~~ + https://bbenoist.gallery.vsassets.io/_apis/public/gallery/publisher/bbenoist/extension/nix/1.0.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage + ~~~ + + The original `code` executable will be wrapped so that it uses the set of pre-installed / unpacked + extensions as its `--extensions-dir`. +*/ + +let + + inherit (vscode) executableName; + wrappedPkgVersion = lib.getVersion vscode; + wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name; + + combinedExtensionsDrv = buildEnv { + name = "vscode-extensions"; + paths = vscodeExtensions; + }; + +in + +# When no extensions are requested, we simply redirect to the original +# non-wrapped vscode executable. +runCommand "${wrappedPkgName}-with-extensions-${wrappedPkgVersion}" { + buildInputs = [ vscode makeWrapper ]; + dontPatchELF = true; + dontStrip = true; + meta = vscode.meta; +} '' + mkdir -p "$out/bin" + mkdir -p "$out/share/applications" + mkdir -p "$out/share/pixmaps" + + ln -sT "${vscode}/share/pixmaps/code.png" "$out/share/pixmaps/code.png" + ln -sT "${vscode}/share/applications/${executableName}.desktop" "$out/share/applications/${executableName}.desktop" + ln -sT "${vscode}/share/applications/${executableName}-url-handler.desktop" "$out/share/applications/${executableName}-url-handler.desktop" + makeWrapper "${vscode}/bin/${executableName}" "$out/bin/${executableName}" ${lib.optionalString (vscodeExtensions != []) '' + --add-flags "--extensions-dir ${combinedExtensionsDrv}/share/vscode/extensions" + ''} +'' |