Unverified Commit b08ed152 authored by maxine's avatar maxine Committed by GitHub
Browse files

Merge pull request #259654 from Artturin/vscodefixfhsoverride

vscode: fix using the fhs with overrideAttrs
parents 52e75cf0 5eb0c82c
Loading
Loading
Loading
Loading
+189 −157
Original line number Diff line number Diff line
{ stdenv, lib, makeDesktopItem
, unzip, libsecret, libXScrnSaver, libxshmfence, buildPackages
, at-spi2-atk, autoPatchelfHook, alsa-lib, mesa, nss, nspr, xorg
, systemd, fontconfig, libdbusmenu, glib, buildFHSEnv, wayland
, libglvnd, libkrb5
{ stdenv
, lib
, makeDesktopItem
, unzip
, libsecret
, libXScrnSaver
, libxshmfence
, buildPackages
, at-spi2-atk
, autoPatchelfHook
, alsa-lib
, mesa
, nss
, nspr
, xorg
, systemd
, fontconfig
, libdbusmenu
, glib
, buildFHSEnv
, wayland
, libglvnd
, libkrb5

  # Populate passthru.tests
, tests

  # needed to fix "Save as Root"
, asar, bash
, asar
, bash

  # Attributes inherit from specific versions
, version, src, meta, sourceRoot, commandLineArgs
, executableName, longName, shortName, pname, updateScript
, version
, src
, meta
, sourceRoot
, commandLineArgs
, executableName
, longName
, shortName
, pname
, updateScript
, dontFixup ? false
, rev ? null, vscodeServer ? null
, rev ? null
, vscodeServer ? null
, sourceExecutableName ? executableName
, useVSCodeRipgrep ? false
, ripgrep
}:

stdenv.mkDerivation (finalAttrs:
let
  unwrapped = stdenv.mkDerivation {

  # Vscode and variants allow for users to download and use extensions
  # which often include the usage of pre-built binaries.
  # This has been an on-going painpoint for many users, as
  # a full extension update cycle has to be done through nixpkgs
  # in order to create or update extensions.
  # See: #83288 #91179 #73810 #41189
  #
  # buildFHSEnv allows for users to use the existing vscode
  # extension tooling without significant pain.
  fhs = { additionalPkgs ? pkgs: [ ] }: buildFHSEnv {
    # also determines the name of the wrapped command
    name = executableName;

    # additional libraries which are commonly needed for extensions
    targetPkgs = pkgs: (with pkgs; [
      # ld-linux-x86-64-linux.so.2 and others
      glibc

      # dotnet
      curl
      icu
      libunwind
      libuuid
      lttng-ust
      openssl
      zlib

      # mono
      krb5
    ]) ++ additionalPkgs pkgs;

    extraBwrapArgs = [
      "--bind-try /etc/nixos/ /etc/nixos/"
    ];

    # symlink shared assets, including icons and desktop entries
    extraInstallCommands = ''
      ln -s "${finalAttrs.finalPackage}/share" "$out/"
    '';

    runScript = "${finalAttrs.finalPackage}/bin/${executableName}";

    # vscode likes to kill the parent so that the
    # gui application isn't attached to the terminal session
    dieWithParent = false;

    passthru = {
      inherit executableName;
      inherit (finalAttrs.finalPackage) pname version; # for home-manager module
    };

    meta = meta // {
      description = ''
        Wrapped variant of ${pname} which launches in a FHS compatible environment.
        Should allow for easy usage of extensions without nix-specific modifications.
      '';
    };
  };
in
{

  inherit pname version src sourceRoot dontFixup;

@@ -141,82 +230,25 @@ let
    # and the window immediately closes which renders VSCode unusable
    # see https://github.com/NixOS/nixpkgs/issues/152939 for full log
    ln -rs "$unpacked" "$packed"
    '' + (let
      vscodeRipgrep = if stdenv.isDarwin then
  '' + (
    let
      vscodeRipgrep =
        if stdenv.isDarwin then
          "Contents/Resources/app/node_modules.asar.unpacked/@vscode/ripgrep/bin/rg"
        else
          "resources/app/node_modules/@vscode/ripgrep/bin/rg";
    in if !useVSCodeRipgrep then ''
    in
    if !useVSCodeRipgrep then ''
      rm ${vscodeRipgrep}
      ln -s ${ripgrep}/bin/rg ${vscodeRipgrep}
    '' else ''
      chmod +x ${vscodeRipgrep}
    '');
    ''
  );

  postFixup = lib.optionalString stdenv.isLinux ''
    patchelf --add-needed ${libglvnd}/lib/libGLESv2.so.2 $out/lib/vscode/${executableName}
  '';

  inherit meta;
  };

  # Vscode and variants allow for users to download and use extensions
  # which often include the usage of pre-built binaries.
  # This has been an on-going painpoint for many users, as
  # a full extension update cycle has to be done through nixpkgs
  # in order to create or update extensions.
  # See: #83288 #91179 #73810 #41189
  #
  # buildFHSEnv allows for users to use the existing vscode
  # extension tooling without significant pain.
  fhs = { additionalPkgs ? pkgs: [] }: buildFHSEnv {
    # also determines the name of the wrapped command
    name = executableName;

    # additional libraries which are commonly needed for extensions
    targetPkgs = pkgs: (with pkgs; [
      # ld-linux-x86-64-linux.so.2 and others
      glibc

      # dotnet
      curl
      icu
      libunwind
      libuuid
      lttng-ust
      openssl
      zlib

      # mono
      krb5
    ]) ++ additionalPkgs pkgs;

    extraBwrapArgs = [
      "--bind-try /etc/nixos/ /etc/nixos/"
    ];

    # symlink shared assets, including icons and desktop entries
    extraInstallCommands = ''
      ln -s "${unwrapped}/share" "$out/"
    '';

    runScript = "${unwrapped}/bin/${executableName}";

    # vscode likes to kill the parent so that the
    # gui application isn't attached to the terminal session
    dieWithParent = false;

    passthru = {
      inherit executableName;
      inherit (unwrapped) pname version; # for home-manager module
    };

    meta = meta // {
      description = ''
        Wrapped variant of ${pname} which launches in a FHS compatible environment.
        Should allow for easy usage of extensions without nix-specific modifications.
      '';
    };
  };
in
  unwrapped
})