about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/vscode
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/editors/vscode')
-rw-r--r--nixpkgs/pkgs/applications/editors/vscode/generic.nix96
-rwxr-xr-xnixpkgs/pkgs/applications/editors/vscode/update.sh41
-rw-r--r--nixpkgs/pkgs/applications/editors/vscode/vscode.nix57
-rw-r--r--nixpkgs/pkgs/applications/editors/vscode/vscodium.nix60
-rw-r--r--nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix75
5 files changed, 329 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/applications/editors/vscode/generic.nix b/nixpkgs/pkgs/applications/editors/vscode/generic.nix
new file mode 100644
index 000000000000..57bd73d60192
--- /dev/null
+++ b/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
+
+# 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 ];
+
+    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/nixpkgs/pkgs/applications/editors/vscode/update.sh b/nixpkgs/pkgs/applications/editors/vscode/update.sh
new file mode 100755
index 000000000000..c030e38a70a0
--- /dev/null
+++ b/nixpkgs/pkgs/applications/editors/vscode/update.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl gnugrep gnused gawk
+
+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
+if [ ! -f "$ROOT/vscodium.nix" ]; then
+  echo "ERROR: cannot find vscodium.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"
+
+# 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/nixpkgs/pkgs/applications/editors/vscode/vscode.nix b/nixpkgs/pkgs/applications/editors/vscode/vscode.nix
new file mode 100644
index 000000000000..a99cba67d3cf
--- /dev/null
+++ b/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 = "1kgvwcwkdvywsiyg86srfzcq6jcas6hyi9ds4qvndsnd64j0fgkn";
+    x86_64-darwin = "03jci05psxkknpjrrgjpdxsii2xyf5cfpkhrp5nnfafb5acfvs1x";
+  }.${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.49.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/nixpkgs/pkgs/applications/editors/vscode/vscodium.nix b/nixpkgs/pkgs/applications/editors/vscode/vscodium.nix
new file mode 100644
index 000000000000..d311e644a293
--- /dev/null
+++ b/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 = "10v13j1zg1bpgmr99vqhs1gwcipvnbkln0w6yphwn9440fw9fyp4";
+    x86_64-darwin = "1mgi2awrqsm11l1yb8rgmfrxvjfn9z3qvp5np76vgbaibq2ihh0k";
+  }.${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.49.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/nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix b/nixpkgs/pkgs/applications/editors/vscode/with-extensions.nix
new file mode 100644
index 000000000000..c30b52782ef3
--- /dev/null
+++ b/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"
+  ''}
+''