1{
2 lib,
3 stdenv,
4 stdenvNoCC,
5 callPackage,
6 fetchurl,
7 nixosTests,
8 srcOnly,
9 isInsiders ? false,
10 # sourceExecutableName is the name of the binary in the source archive over
11 # which we have no control and it is needed to run the insider version as
12 # documented in https://wiki.nixos.org/wiki/Visual_Studio_Code#Insiders_Build
13 # On MacOS the insider binary is still called code instead of code-insiders as
14 # of 2023-08-06.
15 sourceExecutableName ?
16 "code" + lib.optionalString (isInsiders && stdenv.hostPlatform.isLinux) "-insiders",
17 commandLineArgs ? "",
18 useVSCodeRipgrep ? stdenv.hostPlatform.isDarwin,
19}:
20
21let
22 inherit (stdenv.hostPlatform) system;
23 throwSystem = throw "Unsupported system: ${system}";
24
25 plat =
26 {
27 x86_64-linux = "linux-x64";
28 x86_64-darwin = "darwin";
29 aarch64-linux = "linux-arm64";
30 aarch64-darwin = "darwin-arm64";
31 armv7l-linux = "linux-armhf";
32 }
33 .${system} or throwSystem;
34
35 archive_fmt = if stdenv.hostPlatform.isDarwin then "zip" else "tar.gz";
36
37 hash =
38 {
39 x86_64-linux = "sha256-EbgP2CjUBiC+2G7TkGyuxaqr35sTArls4lbDNTH1Pmc=";
40 x86_64-darwin = "sha256-OrDuzSaPxuedhS21Hx1PNTbp6eQpfFfUbO05gIu5Ou8=";
41 aarch64-linux = "sha256-V0aEGqBRf3qVKvPYNypQ9hYWovqQIC3kQq2goq/hVjA=";
42 aarch64-darwin = "sha256-29i/+mz0NCU0ZCO+tzlbSl1iKx5/H89bGQTvRR5/PuA=";
43 armv7l-linux = "sha256-VSsn4d9ztFgGXVZeCeTSHDD5n3aTBbHF/xx2JvTGOeQ=";
44 }
45 .${system} or throwSystem;
46
47 # Please backport all compatible updates to the stable release.
48 # This is important for the extension ecosystem.
49 version = "1.102.3";
50
51 # This is used for VS Code - Remote SSH test
52 rev = "488a1f239235055e34e673291fb8d8c810886f81";
53in
54callPackage ./generic.nix {
55 pname = "vscode" + lib.optionalString isInsiders "-insiders";
56
57 executableName = "code" + lib.optionalString isInsiders "-insiders";
58 longName = "Visual Studio Code" + lib.optionalString isInsiders " - Insiders";
59 shortName = "Code" + lib.optionalString isInsiders " - Insiders";
60 inherit
61 version
62 rev
63 commandLineArgs
64 useVSCodeRipgrep
65 sourceExecutableName
66 ;
67
68 src = fetchurl {
69 name = "VSCode_${version}_${plat}.${archive_fmt}";
70 url = "https://update.code.visualstudio.com/${version}/${plat}/stable";
71 inherit hash;
72 };
73
74 # We don't test vscode on CI, instead we test vscodium
75 tests = { };
76
77 sourceRoot = "";
78
79 # As tests run without networking, we need to download this for the Remote SSH server
80 vscodeServer = srcOnly {
81 name = "vscode-server-${rev}.tar.gz";
82 src = fetchurl {
83 name = "vscode-server-${rev}.tar.gz";
84 url = "https://update.code.visualstudio.com/commit:${rev}/server-linux-x64/stable";
85 hash = "sha256-xVYG/EJRPRJBj3BSarTwpX9F1UM/OI+7ci6vQa64iWI=";
86 };
87 stdenv = stdenvNoCC;
88 };
89
90 tests = { inherit (nixosTests) vscode-remote-ssh; };
91
92 updateScript = ./update-vscode.sh;
93
94 # Editing the `code` binary within the app bundle causes the bundle's signature
95 # to be invalidated, which prevents launching starting with macOS Ventura, because VS Code is notarized.
96 # See https://eclecticlight.co/2022/06/17/app-security-changes-coming-in-ventura/ for more information.
97 dontFixup = stdenv.hostPlatform.isDarwin;
98
99 hasVsceSign = true;
100
101 meta = {
102 description = "Code editor developed by Microsoft";
103 mainProgram = "code";
104 longDescription = ''
105 Code editor developed by Microsoft. It includes support for debugging,
106 embedded Git control, syntax highlighting, intelligent code completion,
107 snippets, and code refactoring. It is also customizable, so users can
108 change the editor's theme, keyboard shortcuts, and preferences
109 '';
110 homepage = "https://code.visualstudio.com/";
111 downloadPage = "https://code.visualstudio.com/Updates";
112 license = lib.licenses.unfree;
113 maintainers = with lib.maintainers; [
114 eadwu
115 synthetica
116 bobby285271
117 johnrtitor
118 jefflabonte
119 ];
120 platforms = [
121 "x86_64-linux"
122 "x86_64-darwin"
123 "aarch64-darwin"
124 "aarch64-linux"
125 "armv7l-linux"
126 ];
127 };
128}