about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/editors/vscode/generic.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/editors/vscode/generic.nix')
-rw-r--r--nixpkgs/pkgs/applications/editors/vscode/generic.nix19
1 files changed, 19 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/applications/editors/vscode/generic.nix b/nixpkgs/pkgs/applications/editors/vscode/generic.nix
index 4363f83ba037..7a3f34828ee2 100644
--- a/nixpkgs/pkgs/applications/editors/vscode/generic.nix
+++ b/nixpkgs/pkgs/applications/editors/vscode/generic.nix
@@ -7,6 +7,9 @@
 # Populate passthru.tests
 , tests
 
+# needed to fix "Save as Root"
+, nodePackages, bash
+
 # Attributes inherit from specific versions
 , version, src, meta, sourceRoot
 , executableName, longName, shortName, pname, updateScript
@@ -108,6 +111,22 @@ let
       )
     '';
 
+    # See https://github.com/NixOS/nixpkgs/issues/49643#issuecomment-873853897
+    # linux only because of https://github.com/NixOS/nixpkgs/issues/138729
+    postPatch = lib.optionalString stdenv.isLinux ''
+      # this is a fix for "save as root" functionality
+      packed="resources/app/node_modules.asar"
+      unpacked="resources/app/node_modules"
+      ${nodePackages.asar}/bin/asar extract "$packed" "$unpacked"
+      substituteInPlace $unpacked/sudo-prompt/index.js \
+        --replace "/usr/bin/pkexec" "/run/wrappers/bin/pkexec" \
+        --replace "/bin/bash" "${bash}/bin/bash"
+      rm -rf "$packed"
+
+      # this fixes bundled ripgrep
+      chmod +x resources/app/node_modules/vscode-ripgrep/bin/rg
+    '';
+
     inherit meta;
   };