diff --git a/pkgs/applications/editors/vscode/generic.nix b/pkgs/applications/editors/vscode/generic.nix index 1c22a86b7dac2..36917ed70beb3 100644 --- a/pkgs/applications/editors/vscode/generic.nix +++ b/pkgs/applications/editors/vscode/generic.nix @@ -7,11 +7,10 @@ makeDesktopItem, unzip, libsecret, - libXScrnSaver, - libxshmfence, buildPackages, at-spi2-atk, autoPatchelfHook, + buildFHSEnv, alsa-lib, libgbm, nss, @@ -19,22 +18,21 @@ xorg, systemdLibs, fontconfig, + imagemagick, libdbusmenu, glib, - buildFHSEnv, wayland, libglvnd, - libkrb5, openssl, webkitgtk_4_1, - - # Populate passthru.tests - tests, + ripgrep, # needed to fix "Save as Root" asar, bash, +}: +{ # Attributes inherit from specific versions version, vscodeVersion ? version, @@ -54,10 +52,17 @@ vscodeServer ? null, sourceExecutableName ? executableName, useVSCodeRipgrep ? false, - ripgrep, hasVsceSign ? false, patchVSCodePath ? true, - imagemagick, + + # Populate passthru.tests + tests, + + extraNativeBuildInputs ? [ ], + + # Customize FHS environment + # Function that takes default buildFHSEnv arguments and returns modified arguments + customizeFHSEnv ? args: args, }: stdenv.mkDerivation ( @@ -77,82 +82,86 @@ stdenv.mkDerivation ( { additionalPkgs ? pkgs: [ ], }: - buildFHSEnv { - # also determines the name of the wrapped command - pname = executableName; - inherit version; - - # 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 - - # Needed for headless browser-in-vscode based plugins such as - # anything based on Puppeteer https://pptr.dev . - # e.g. Roo Code - glib - nspr - nss - dbus - at-spi2-atk - cups - expat - libxkbcommon - xorg.libX11 - xorg.libXcomposite - xorg.libXdamage - xorg.libxcb - xorg.libXext - xorg.libXfixes - xorg.libXrandr - cairo - pango - alsa-lib - libgbm - udev - libudev0-shim - ]) - ++ additionalPkgs pkgs; - - extraBwrapArgs = [ - "--bind-try /etc/nixos/ /etc/nixos/" - "--ro-bind-try /etc/xdg/ /etc/xdg/" - ]; + let + defaultArgs = { + # also determines the name of the wrapped command + pname = executableName; + inherit version; - # symlink shared assets, including icons and desktop entries - extraInstallCommands = '' - ln -s "${finalAttrs.finalPackage}/share" "$out/" - ''; + # additional libraries which are commonly needed for extensions + targetPkgs = + pkgs: + (with pkgs; [ + # ld-linux-x86-64-linux.so.2 and others + glibc - runScript = "${finalAttrs.finalPackage}/bin/${executableName}"; + # dotnet + curl + icu + libunwind + libuuid + lttng-ust + openssl + zlib - # vscode likes to kill the parent so that the - # gui application isn't attached to the terminal session - dieWithParent = false; + # mono + krb5 - passthru = { - inherit executableName; - inherit (finalAttrs.finalPackage) pname version; # for home-manager module - }; + # Needed for headless browser-in-vscode based plugins such as + # anything based on Puppeteer https://pptr.dev . + # e.g. Roo Code + glib + nspr + nss + dbus + at-spi2-atk + cups + expat + libxkbcommon + xorg.libX11 + xorg.libXcomposite + xorg.libXdamage + xorg.libxcb + xorg.libXext + xorg.libXfixes + xorg.libXrandr + cairo + pango + alsa-lib + libgbm + udev + libudev0-shim + ]) + ++ additionalPkgs pkgs; + + extraBwrapArgs = [ + "--bind-try /etc/nixos/ /etc/nixos/" + "--ro-bind-try /etc/xdg/ /etc/xdg/" + ]; + + # 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"; + 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"; + }; }; - }; + customizedArgs = customizeFHSEnv defaultArgs; + in + buildFHSEnv customizedArgs; in { @@ -225,13 +234,10 @@ stdenv.mkDerivation ( buildInputs = [ libsecret - libXScrnSaver - libxshmfence ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [ alsa-lib at-spi2-atk - libkrb5 libgbm nss nspr @@ -252,6 +258,7 @@ stdenv.mkDerivation ( unzip imagemagick ] + ++ extraNativeBuildInputs ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook asar diff --git a/pkgs/applications/editors/vscode/vscode.nix b/pkgs/applications/editors/vscode/vscode.nix index 259614e37fb40..f7d67e8d8baf3 100644 --- a/pkgs/applications/editors/vscode/vscode.nix +++ b/pkgs/applications/editors/vscode/vscode.nix @@ -2,7 +2,7 @@ lib, stdenv, stdenvNoCC, - callPackage, + buildVscode, fetchurl, nixosTests, srcOnly, @@ -51,7 +51,7 @@ let # This is used for VS Code - Remote SSH test rev = "585eba7c0c34fd6b30faac7c62a42050bfbc0086"; in -callPackage ./generic.nix { +buildVscode { pname = "vscode" + lib.optionalString isInsiders "-insiders"; executableName = "code" + lib.optionalString isInsiders "-insiders"; diff --git a/pkgs/applications/editors/vscode/vscodium.nix b/pkgs/applications/editors/vscode/vscodium.nix index 97158b30c9641..e305001a7a01f 100644 --- a/pkgs/applications/editors/vscode/vscodium.nix +++ b/pkgs/applications/editors/vscode/vscodium.nix @@ -1,7 +1,7 @@ { lib, stdenv, - callPackage, + buildVscode, fetchurl, nixosTests, commandLineArgs ? "", @@ -38,7 +38,7 @@ let sourceRoot = lib.optionalString (!stdenv.hostPlatform.isDarwin) "."; in -callPackage ./generic.nix rec { +buildVscode rec { inherit sourceRoot commandLineArgs useVSCodeRipgrep; # Please backport all compatible updates to the stable release. diff --git a/pkgs/by-name/an/antigravity/package.nix b/pkgs/by-name/an/antigravity/package.nix index ca56db0b01cbd..1c6b5427ea998 100644 --- a/pkgs/by-name/an/antigravity/package.nix +++ b/pkgs/by-name/an/antigravity/package.nix @@ -1,11 +1,9 @@ { lib, stdenv, - callPackage, - vscode-generic, + buildVscode, fetchurl, jq, - buildFHSEnv, writeShellScript, coreutils, commandLineArgs ? "", @@ -19,7 +17,7 @@ let information.sources."${hostPlatform.system}" or (throw "antigravity: unsupported system ${hostPlatform.system}"); in -(callPackage vscode-generic { +(buildVscode { inherit commandLineArgs useVSCodeRipgrep; inherit (information) version vscodeVersion; pname = "antigravity"; @@ -34,31 +32,29 @@ in sourceRoot = if hostPlatform.isDarwin then "Antigravity.app" else "Antigravity"; + tests = { }; + updateScript = ./update.js; + # When running inside an FHS environment, try linking Google Chrome or Chromium # to the hardcoded Playwright search path: /opt/google/chrome/chrome - buildFHSEnv = + customizeFHSEnv = args: - buildFHSEnv ( - args - // { - extraBuildCommands = (args.extraBuildCommands or "") + '' - mkdir -p "$out/opt/google/chrome" - ''; - extraBwrapArgs = (args.extraBwrapArgs or [ ]) ++ [ "--tmpfs /opt/google/chrome" ]; - runScript = writeShellScript "antigravity-wrapper" '' - for candidate in google-chrome-stable google-chrome chromium-browser chromium; do - if target=$(command -v "$candidate"); then - ${coreutils}/bin/ln -sf "$target" /opt/google/chrome/chrome - break - fi - done - exec ${args.runScript} "$@" - ''; - } - ); - - tests = { }; - updateScript = ./update.js; + args + // { + extraBwrapArgs = (args.extraBwrapArgs or [ ]) ++ [ "--tmpfs /opt/google/chrome" ]; + extraBuildCommands = (args.extraBuildCommands or "") + '' + mkdir -p "$out/opt/google/chrome" + ''; + runScript = writeShellScript "antigravity-wrapper" '' + for candidate in google-chrome-stable google-chrome chromium-browser chromium; do + if target=$(command -v "$candidate"); then + ${coreutils}/bin/ln -sf "$target" /opt/google/chrome/chrome + break + fi + done + exec ${args.runScript} "$@" + ''; + }; meta = { mainProgram = "antigravity"; diff --git a/pkgs/by-name/co/code-cursor/package.nix b/pkgs/by-name/co/code-cursor/package.nix index 126a7929ef38d..edff54ed19886 100644 --- a/pkgs/by-name/co/code-cursor/package.nix +++ b/pkgs/by-name/co/code-cursor/package.nix @@ -1,8 +1,7 @@ { lib, stdenv, - callPackage, - vscode-generic, + buildVscode, fetchurl, appimageTools, undmg, @@ -24,7 +23,7 @@ let source = sources.${hostPlatform.system}; in -(callPackage vscode-generic rec { +buildVscode rec { inherit useVSCodeRipgrep; inherit (sourcesJson) version vscodeVersion; commandLineArgs = finalCommandLineArgs; @@ -46,6 +45,9 @@ in else source; + # for unpacking the DMG + extraNativeBuildInputs = lib.optionals hostPlatform.isDarwin [ undmg ]; + sourceRoot = if hostPlatform.isLinux then "${pname}-${version}-extracted/usr/share/cursor" else "Cursor.app"; @@ -66,7 +68,7 @@ in homepage = "https://cursor.com"; changelog = "https://cursor.com/changelog"; license = lib.licenses.unfree; - sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; maintainers = with lib.maintainers; [ aspauldingcode prince213 @@ -79,12 +81,4 @@ in ++ lib.platforms.darwin; mainProgram = "cursor"; }; -}).overrideAttrs - (oldAttrs: { - nativeBuildInputs = - (oldAttrs.nativeBuildInputs or [ ]) ++ lib.optionals hostPlatform.isDarwin [ undmg ]; - - passthru = (oldAttrs.passthru or { }) // { - inherit sources; - }; - }) +} diff --git a/pkgs/by-name/ki/kiro/package.nix b/pkgs/by-name/ki/kiro/package.nix index 41235eda4bc1e..ff46dff52ecba 100644 --- a/pkgs/by-name/ki/kiro/package.nix +++ b/pkgs/by-name/ki/kiro/package.nix @@ -1,8 +1,7 @@ { lib, stdenv, - callPackage, - vscode-generic, + buildVscode, fetchurl, extraCommandLineArgs ? "", useVSCodeRipgrep ? stdenv.hostPlatform.isDarwin, @@ -11,7 +10,7 @@ let sources = (lib.importJSON ./sources.json).${stdenv.hostPlatform.system}; in -(callPackage vscode-generic { +(buildVscode { inherit useVSCodeRipgrep; commandLineArgs = extraCommandLineArgs; diff --git a/pkgs/by-name/wi/windsurf/package.nix b/pkgs/by-name/wi/windsurf/package.nix index c2138ae24d314..6f5e6c97c769a 100644 --- a/pkgs/by-name/wi/windsurf/package.nix +++ b/pkgs/by-name/wi/windsurf/package.nix @@ -1,8 +1,7 @@ { lib, stdenv, - callPackage, - vscode-generic, + buildVscode, fetchurl, nixosTests, commandLineArgs ? "", @@ -13,7 +12,7 @@ let (lib.importJSON ./info.json)."${stdenv.hostPlatform.system}" or (throw "windsurf: unsupported system ${stdenv.hostPlatform.system}"); in -callPackage vscode-generic { +buildVscode { inherit commandLineArgs useVSCodeRipgrep; inherit (info) version vscodeVersion; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 62ad433444971..5c948b946b564 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11856,6 +11856,8 @@ with pkgs; vscode-fhs = vscode.fhs; vscode-fhsWithPackages = vscode.fhsWithPackages; + buildVscode = callPackage ../applications/editors/vscode/generic.nix { }; + vscode-with-extensions = callPackage ../applications/editors/vscode/with-extensions.nix { }; vscode-utils = callPackage ../applications/editors/vscode/extensions/vscode-utils.nix { }; @@ -11870,25 +11872,11 @@ with pkgs; vscodium-fhs = vscodium.fhs; vscodium-fhsWithPackages = vscodium.fhsWithPackages; - antigravity = callPackage ../by-name/an/antigravity/package.nix { - vscode-generic = ../applications/editors/vscode/generic.nix; - }; antigravity-fhs = antigravity.fhs; antigravity-fhsWithPackages = antigravity.fhsWithPackages; - code-cursor = callPackage ../by-name/co/code-cursor/package.nix { - vscode-generic = ../applications/editors/vscode/generic.nix; - }; code-cursor-fhs = code-cursor.fhs; code-cursor-fhsWithPackages = code-cursor.fhsWithPackages; - - windsurf = callPackage ../by-name/wi/windsurf/package.nix { - vscode-generic = ../applications/editors/vscode/generic.nix; - }; - - kiro = callPackage ../by-name/ki/kiro/package.nix { - vscode-generic = ../applications/editors/vscode/generic.nix; - }; kiro-fhs = kiro.fhs; kiro-fhsWithPackages = kiro.fhsWithPackages;