-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathflake.nix
285 lines (280 loc) · 10.4 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
{
description = "
`VS Code Marketplace` (~40K) and `Open VSX` (~3K) extensions as `Nix` expressions.
Learn more in the flake [repo](https://github.com/nix-community/nix-vscode-extensions).
";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
...
}:
let
inherit (nixpkgs) lib;
inherit (flake-utils.lib) eachDefaultSystem;
vscode-marketplace = "vscode-marketplace";
open-vsx = "open-vsx";
universal = "universal";
systemPlatform = {
"aarch64-darwin" = "darwin-arm64";
"x86_64-linux" = "linux-x64";
"aarch64-linux" = "linux-arm64";
"x86_64-darwin" = "darwin-x64";
};
in
{
overlays = {
default =
final: prev:
let
pkgs = nixpkgs.legacyPackages.${final.system};
utils = pkgs.vscode-utils;
currentPlatform = systemPlatform.${final.system};
isCompatibleVersion =
vscodeVersion: engineVersion:
if lib.strings.hasPrefix "^" engineVersion then
lib.versionAtLeast vscodeVersion (lib.strings.removePrefix "^" engineVersion)
else
vscodeVersion == engineVersion;
# version of VSCode or VSCodium
filterByPlatform =
{ checkVSCodeVersion, vscodeVersion }:
(builtins.filter (
x:
(x.platform == universal || x.platform == currentPlatform)
&& (if checkVSCodeVersion then (isCompatibleVersion vscodeVersion x.engineVersion) else true)
));
loadGenerated =
{
needLatest ? true,
checkVSCodeVersion ? false,
vscodeVersion ? "*",
site,
}:
lib.pipe site [
(x: ./data/cache/${site}${if needLatest then "-latest" else "-release"}.json)
builtins.readFile
builtins.fromJSON
(filterByPlatform { inherit checkVSCodeVersion vscodeVersion; })
(map (
extension@{
name,
publisher,
version,
platform,
...
}:
extension
// {
url =
if site == vscode-marketplace then
let
platformSuffix = if platform == universal then "" else "targetPlatform=${platform}";
in
"https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage?${platformSuffix}"
else
let
platformSuffix = if platform == universal then "" else "@${platform}";
platformInfix = if platform == universal then "" else "/${platform}";
in
"https://open-vsx.org/api/${publisher}/${name}${platformInfix}/${version}/file/${publisher}.${name}-${version}${platformSuffix}.vsix";
}
))
(
x:
x
++ filterByPlatform { inherit checkVSCodeVersion vscodeVersion; } (
pkgs.lib.attrsets.mapAttrsToList
(name: value: {
url = value.src.url;
sha256 = value.src.outputHash;
inherit (value)
publisher
name
version
platform
engineVersion
;
})
(
# append extra extensions fetched from elsewhere to overwrite site extensions
import ./data/extra-extensions/generated.nix {
inherit (pkgs)
fetchgit
fetchurl
fetchFromGitHub
dockerTools
;
}
)
)
)
# lowercase all names and publishers
(map (
extension@{ name, publisher, ... }:
extension
// {
name = lib.toLower name;
publisher = lib.toLower publisher;
}
))
(map (
{
name,
publisher,
version,
sha256,
url,
...
}:
let
override =
(
let
overrides = (import ./overrides.nix { inherit pkgs; });
in
overrides.publisher or { }
).name or (x: x);
in
{
inherit name;
value = utils.buildVscodeMarketplaceExtension (override {
vsix = prev.fetchurl {
inherit url sha256;
name = "${name}-${version}.zip";
};
mktplcRef = {
inherit name version publisher;
};
});
}
))
# group by publisher
(builtins.groupBy ({ value, ... }: value.vscodeExtPublisher))
# platform-specific extensions will overwrite universal extensions
# due to the sorting order of platforms in the Haskell script
(builtins.mapAttrs (_: builtins.foldl' (k: { name, value }: k // { ${name} = value; }) { }))
(
x:
builtins.foldl'
(
extensions: removedPublisherConfig:
if !(extensions ? ${removedPublisherConfig.publisher}) then
extensions
else
extensions
// {
"${removedPublisherConfig.publisher}" = builtins.foldl' (
publisherExtensions: extensionName:
publisherExtensions
// {
"${extensionName}" = builtins.throw ''
The extension '${removedPublisherConfig.publisher}.${extensionName}' was removed.
See '${./removed.nix}' for details.
'';
}
) extensions.${removedPublisherConfig.publisher} removedPublisherConfig.extensions;
}
)
x
(
pkgs.lib.attrsets.mapAttrsToList (publisher: extensions: {
inherit publisher extensions;
}) (import ./removed.nix)
)
)
];
mkSet =
attrs@{
checkVSCodeVersion ? false,
vscodeVersion ? "*",
}:
{
vscode-marketplace = loadGenerated (attrs // { site = vscode-marketplace; });
open-vsx = loadGenerated (attrs // { site = open-vsx; });
vscode-marketplace-release = loadGenerated (
attrs
// {
needLatest = false;
site = vscode-marketplace;
}
);
open-vsx-release = loadGenerated (
attrs
// {
needLatest = false;
site = open-vsx;
}
);
};
res = (mkSet { }) // {
forVSCodeVersion =
vscodeVersion:
mkSet {
checkVSCodeVersion = true;
inherit vscodeVersion;
};
};
in
res;
};
templates = {
default = {
path = ./template;
description = "VSCodium with extensions";
};
};
}
// (eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
extensions = self.overlays.default pkgs pkgs;
packages = {
default =
pkgs.lib.trivial.pipe
(pkgs.vscode-with-extensions.override {
vscode = pkgs.vscodium;
vscodeExtensions = with self.extensions.${system}.vscode-marketplace; [
golang.go
vlanguage.vscode-vlang
rust-lang.rust-analyzer
vadimcn.vscode-lldb
];
})
[
(
x:
pkgs.lib.attrsets.recursiveUpdate x {
meta = {
longDescription = ''
This is a sample overridden VSCodium (FOSS fork of VS Code) with a couple extensions.
You can override this package and set `vscodeExtensions` to a list of extension
derivations, namely those provided by this flake.
The [repository] provides ~40K extensions from [Visual Studio Marketplace]
and another ~3K from [Open VSX Registry].
[repository]: https://github.com/nix-community/nix-vscode-extensions
[Visual Studio Marketplace]: https://marketplace.visualstudio.com/vscode
[Open VSX Registry]: https://open-vsx.org/
'';
};
}
)
(x: x // { meta = builtins.removeAttrs x.meta [ "description" ]; })
];
};
formatter = pkgs.nixfmt-rfc-style;
}
));
}