2020-04-24 23:36:52 +00:00
|
|
|
{ stdenv, lib, makeDesktopItem
|
2023-01-11 07:51:40 +00:00
|
|
|
, unzip, libsecret, libXScrnSaver, libxshmfence, buildPackages
|
2023-10-09 19:29:22 +00:00
|
|
|
, at-spi2-atk, autoPatchelfHook, alsa-lib, mesa, nss, nspr, xorg
|
2023-04-29 16:46:19 +00:00
|
|
|
, systemd, fontconfig, libdbusmenu, glib, buildFHSEnv, wayland
|
2023-08-10 07:59:29 +00:00
|
|
|
, libglvnd, libkrb5
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-13 14:23:35 +00:00
|
|
|
# Populate passthru.tests
|
|
|
|
, tests
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
# needed to fix "Save as Root"
|
2023-10-09 19:29:22 +00:00
|
|
|
, asar, bash
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# Attributes inherit from specific versions
|
2022-09-09 14:08:57 +00:00
|
|
|
, version, src, meta, sourceRoot, commandLineArgs
|
2021-05-28 09:39:13 +00:00
|
|
|
, executableName, longName, shortName, pname, updateScript
|
2022-10-30 15:09:59 +00:00
|
|
|
, dontFixup ? false
|
2023-07-15 17:15:38 +00:00
|
|
|
, rev ? null, vscodeServer ? null
|
2021-07-03 03:11:41 +00:00
|
|
|
, sourceExecutableName ? executableName
|
2023-05-24 13:37:59 +00:00
|
|
|
, useVSCodeRipgrep ? false
|
|
|
|
, ripgrep
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-05-03 20:48:10 +00:00
|
|
|
unwrapped = stdenv.mkDerivation {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
inherit pname version src sourceRoot dontFixup;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
passthru = {
|
2021-08-11 14:56:57 +00:00
|
|
|
inherit executableName longName tests updateScript;
|
2021-05-03 20:48:10 +00:00
|
|
|
fhs = fhs {};
|
|
|
|
fhsWithPackages = f: fhs { additionalPkgs = f; };
|
2023-07-15 17:15:38 +00:00
|
|
|
} // lib.optionalAttrs (vscodeServer != null) {
|
|
|
|
inherit rev vscodeServer;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
desktopItem = makeDesktopItem {
|
|
|
|
name = executableName;
|
|
|
|
desktopName = longName;
|
|
|
|
comment = "Code Editing. Redefined.";
|
|
|
|
genericName = "Text Editor";
|
2020-11-24 20:58:05 +00:00
|
|
|
exec = "${executableName} %F";
|
2023-08-04 22:07:22 +00:00
|
|
|
icon = "vs${executableName}";
|
2022-03-05 16:20:37 +00:00
|
|
|
startupNotify = true;
|
|
|
|
startupWMClass = shortName;
|
|
|
|
categories = [ "Utility" "TextEditor" "Development" "IDE" ];
|
|
|
|
mimeTypes = [ "text/plain" "inode/directory" ];
|
|
|
|
keywords = [ "vscode" ];
|
|
|
|
actions.new-empty-window = {
|
|
|
|
name = "New Empty Window";
|
|
|
|
exec = "${executableName} --new-window %F";
|
2023-08-04 22:07:22 +00:00
|
|
|
icon = "vs${executableName}";
|
2022-03-05 16:20:37 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
urlHandlerDesktopItem = makeDesktopItem {
|
|
|
|
name = executableName + "-url-handler";
|
|
|
|
desktopName = longName + " - URL Handler";
|
|
|
|
comment = "Code Editing. Redefined.";
|
|
|
|
genericName = "Text Editor";
|
|
|
|
exec = executableName + " --open-url %U";
|
2023-08-04 22:07:22 +00:00
|
|
|
icon = "vs${executableName}";
|
2022-03-05 16:20:37 +00:00
|
|
|
startupNotify = true;
|
|
|
|
categories = [ "Utility" "TextEditor" "Development" "IDE" ];
|
|
|
|
mimeTypes = [ "x-scheme-handler/vscode" ];
|
|
|
|
keywords = [ "vscode" ];
|
|
|
|
noDisplay = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-19 17:17:44 +00:00
|
|
|
buildInputs = [ libsecret libXScrnSaver libxshmfence ]
|
2023-10-09 19:29:22 +00:00
|
|
|
++ lib.optionals (!stdenv.isDarwin) [ alsa-lib at-spi2-atk libkrb5 mesa nss nspr systemd xorg.libxkbfile ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-22 20:05:09 +00:00
|
|
|
runtimeDependencies = lib.optionals stdenv.isLinux [ (lib.getLib systemd) fontconfig.lib libdbusmenu wayland libsecret ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
nativeBuildInputs = [ unzip ]
|
|
|
|
++ lib.optionals stdenv.isLinux [
|
|
|
|
autoPatchelfHook
|
2023-10-09 19:29:22 +00:00
|
|
|
asar
|
2023-01-11 07:51:40 +00:00
|
|
|
# override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651
|
|
|
|
(buildPackages.wrapGAppsHook.override { inherit (buildPackages) makeWrapper; })
|
2022-05-18 14:49:53 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
dontBuild = true;
|
|
|
|
dontConfigure = true;
|
2022-03-30 09:31:56 +00:00
|
|
|
noDumpEnvVars = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-15 00:37:46 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2021-07-14 22:03:04 +00:00
|
|
|
'' + (if stdenv.isDarwin then ''
|
2021-10-28 06:52:43 +00:00
|
|
|
mkdir -p "$out/Applications/${longName}.app" "$out/bin"
|
2021-04-15 00:37:46 +00:00
|
|
|
cp -r ./* "$out/Applications/${longName}.app"
|
2021-10-28 06:52:43 +00:00
|
|
|
ln -s "$out/Applications/${longName}.app/Contents/Resources/app/bin/${sourceExecutableName}" "$out/bin/${executableName}"
|
2021-04-15 00:37:46 +00:00
|
|
|
'' else ''
|
2021-10-28 06:52:43 +00:00
|
|
|
mkdir -p "$out/lib/vscode" "$out/bin"
|
|
|
|
cp -r ./* "$out/lib/vscode"
|
2021-04-15 00:37:46 +00:00
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
ln -s "$out/lib/vscode/bin/${sourceExecutableName}" "$out/bin/${executableName}"
|
2021-04-15 00:37:46 +00:00
|
|
|
|
2021-10-28 06:52:43 +00:00
|
|
|
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"
|
2021-04-15 00:37:46 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
# These are named vscode.png, vscode-insiders.png, etc to match the name in upstream *.deb packages.
|
2021-10-28 06:52:43 +00:00
|
|
|
mkdir -p "$out/share/pixmaps"
|
2023-08-04 22:07:22 +00:00
|
|
|
cp "$out/lib/vscode/resources/app/resources/linux/code.png" "$out/share/pixmaps/vs${executableName}.png"
|
2021-04-15 00:37:46 +00:00
|
|
|
|
|
|
|
# Override the previously determined VSCODE_PATH with the one we know to be correct
|
2021-10-28 06:52:43 +00:00
|
|
|
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
|
2023-07-15 17:15:38 +00:00
|
|
|
|
|
|
|
# Remove native encryption code, as it derives the key from the executable path which does not work for us.
|
|
|
|
# The credentials should be stored in a secure keychain already, so the benefit of this is questionable
|
|
|
|
# in the first place.
|
|
|
|
rm -rf $out/lib/vscode/resources/app/node_modules/vscode-encrypt
|
2021-04-15 00:37:46 +00:00
|
|
|
'') + ''
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
preFixup = ''
|
|
|
|
gappsWrapperArgs+=(
|
|
|
|
# Add gio to PATH so that moving files to the trash works when not using a desktop environment
|
|
|
|
--prefix PATH : ${glib.bin}/bin
|
2022-10-06 18:32:54 +00:00
|
|
|
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}"
|
2022-09-09 14:08:57 +00:00
|
|
|
--add-flags ${lib.escapeShellArg commandLineArgs}
|
2021-09-18 10:52:07 +00:00
|
|
|
)
|
|
|
|
'';
|
|
|
|
|
|
|
|
# See https://github.com/NixOS/nixpkgs/issues/49643#issuecomment-873853897
|
2021-09-26 12:46:18 +00:00
|
|
|
# linux only because of https://github.com/NixOS/nixpkgs/issues/138729
|
|
|
|
postPatch = lib.optionalString stdenv.isLinux ''
|
2021-09-18 10:52:07 +00:00
|
|
|
# this is a fix for "save as root" functionality
|
|
|
|
packed="resources/app/node_modules.asar"
|
|
|
|
unpacked="resources/app/node_modules"
|
2022-04-27 09:35:20 +00:00
|
|
|
asar extract "$packed" "$unpacked"
|
2021-12-19 01:06:50 +00:00
|
|
|
substituteInPlace $unpacked/@vscode/sudo-prompt/index.js \
|
2021-09-18 10:52:07 +00:00
|
|
|
--replace "/usr/bin/pkexec" "/run/wrappers/bin/pkexec" \
|
|
|
|
--replace "/bin/bash" "${bash}/bin/bash"
|
|
|
|
rm -rf "$packed"
|
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
# without this symlink loading JsChardet, the library that is used for auto encoding detection when files.autoGuessEncoding is true,
|
|
|
|
# fails to load with: electron/js2c/renderer_init: Error: Cannot find module 'jschardet'
|
|
|
|
# and the window immediately closes which renders VSCode unusable
|
|
|
|
# see https://github.com/NixOS/nixpkgs/issues/152939 for full log
|
|
|
|
ln -rs "$unpacked" "$packed"
|
2023-05-24 13:37:59 +00:00
|
|
|
'' + (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 ''
|
|
|
|
rm ${vscodeRipgrep}
|
|
|
|
ln -s ${ripgrep}/bin/rg ${vscodeRipgrep}
|
|
|
|
'' else ''
|
|
|
|
chmod +x ${vscodeRipgrep}
|
|
|
|
'');
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2023-08-22 20:05:09 +00:00
|
|
|
postFixup = lib.optionalString stdenv.isLinux ''
|
|
|
|
patchelf --add-needed ${libglvnd}/lib/libGLESv2.so.2 $out/lib/vscode/${executableName}
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit meta;
|
2021-05-03 20:48:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# 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
|
|
|
|
#
|
2023-04-29 16:46:19 +00:00
|
|
|
# buildFHSEnv allows for users to use the existing vscode
|
2021-05-03 20:48:10 +00:00
|
|
|
# extension tooling without significant pain.
|
2023-04-29 16:46:19 +00:00
|
|
|
fhs = { additionalPkgs ? pkgs: [] }: buildFHSEnv {
|
2021-05-03 20:48:10 +00:00
|
|
|
# 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
|
2023-01-11 07:51:40 +00:00
|
|
|
lttng-ust
|
2021-05-03 20:48:10 +00:00
|
|
|
openssl
|
|
|
|
zlib
|
|
|
|
|
|
|
|
# mono
|
|
|
|
krb5
|
|
|
|
]) ++ additionalPkgs pkgs;
|
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
extraBwrapArgs = [
|
|
|
|
"--bind-try /etc/nixos/ /etc/nixos/"
|
|
|
|
];
|
|
|
|
|
2022-02-10 20:34:41 +00:00
|
|
|
# symlink shared assets, including icons and desktop entries
|
2021-05-03 20:48:10 +00:00
|
|
|
extraInstallCommands = ''
|
2022-02-10 20:34:41 +00:00
|
|
|
ln -s "${unwrapped}/share" "$out/"
|
2021-05-03 20:48:10 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
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 = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
Wrapped variant of ${pname} which launches in a FHS compatible environment.
|
2021-05-03 20:48:10 +00:00
|
|
|
Should allow for easy usage of extensions without nix-specific modifications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
unwrapped
|