-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmkExtension.nix
More file actions
186 lines (164 loc) · 5.73 KB
/
mkExtension.nix
File metadata and controls
186 lines (164 loc) · 5.73 KB
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
# The result of this function is an attrset where
# each `${publisher}.${name}` maps to a function `{ mktplcRef, vsix } -> (Derivation | { publisher })`
# Each Derivation is produced via the overridable `buildVscodeMarketplaceExtension` function (defined below).
# The `{ publisher }` attrset is provided for compatibility with `groupBy`.
# Custom fixes are loaded via `mkExtensionLocal`.
{
pkgs,
pkgsWithFixes,
system,
}:
let
inherit (pkgs) lib;
makeOverridable =
f: args:
lib.customisation.makeOverridable f (
if builtins.isFunction args then
let
x = args (f x);
in
x
else
args
);
buildVscodeMarketplaceExtension = makeOverridable pkgs.vscode-utils.buildVscodeMarketplaceExtension;
buildVscodeExtension = makeOverridable pkgs.vscode-utils.buildVscodeExtension;
# We don't modify callPackage because extensions
# may use its original version
pkgs' = pkgs // {
vscode-utils = pkgs.vscode-utils // {
inherit buildVscodeMarketplaceExtension buildVscodeExtension;
};
};
applyMkExtension = builtins.mapAttrs (
publisher: builtins.mapAttrs (name: f: { mktplcRef, vsix }@extensionConfig: f extensionConfig)
);
mkExtensionLocal = applyMkExtension (import ../extensions { pkgs = pkgs'; });
extensionsRemoved = (import ./removed.nix).${system} or [ ];
# Similar to callPackageWith/callPackage, but without makeOverridable.
#
# In `nixpkgs`, `pkgs.lib.callPackageWith` uses `pkgs.lib.makeOverridable`.
# We need `callPackageWith` to use a custom `makeOverridable`
# to handle the case when in an expression for an extension in `nixpkgs`,
# `pkgs.vscode-utils.buildVscodeMarketplaceExtension`
# takes a function, not an attrset.
#
# Adapted from
# https://github.com/NixOS/nixpkgs/blob/b044ad6e5e92e70d7a7723864b0ab7a6c25bafda/pkgs/development/beam-modules/lib.nix#L9
callPackageWith =
autoArgs: fn: args:
let
f = if lib.isFunction fn then fn else import fn;
auto = builtins.intersectAttrs (lib.functionArgs f) autoArgs;
in
f (auto // args);
callPackage = callPackageWith pkgs';
# TODO find a cleaner way to get the store path of nixpkgs from given pkgs
pathNixpkgs =
if pkgsWithFixes ? outPath then
pkgsWithFixes.outPath
else
lib.trivial.pipe pkgsWithFixes.hello.inputDerivation._derivation_original_args [
builtins.tail
builtins.head
builtins.dirOf
builtins.dirOf
builtins.dirOf
builtins.dirOf
];
extensionsNixpkgs = callPackage (
pathNixpkgs + "/pkgs/applications/editors/vscode/extensions/default.nix"
) { config.allowAliases = false; };
extensionsProblematic = [
# Problem:
# Some arguments of the function that produces a derivation
# are provided in the `let .. in` expression before the call to that function
# TODO make a PR to nixpkgs to simplify overriding for these extensions
"anweber.vscode-httpyac"
"chenglou92.rescript-vscode"
# Wait for https://github.com/NixOS/nixpkgs/pull/383013 to be merged
"vadimcn.vscode-lldb"
"rust-lang.rust-analyzer"
# In Nixpkgs, these packages are constructed
# using the `buildVscodeExtension` function.
#
# Their expressions don't provide any meaningful fixes.
#
# Find all such extensions:
# https://github.com/search?q=repo%3ANixOS%2Fnixpkgs%20buildVscodeExtension&type=code
"eamodio.gitlens"
"google.gemini-cli-vscode-ide-companion"
"kilocode.kilo-code"
"ms-vscode.js-debug-companion"
"ms-vscode.vscode-js-profile-table"
"prettier.prettier-vscode"
"rooveterinaryinc.roo-cline"
"vscode-icons-team.vscode-icons"
];
pathSpecial = {
ms-ceintl = "language-packs.nix";
wakatime = "WakaTime.vscode-wakatime";
};
mkExtensionNixpkgs = builtins.mapAttrs (
publisher:
builtins.mapAttrs (
name: extension:
let
extensionId = "${publisher}.${name}";
in
if builtins.elem extensionId extensionsRemoved then
_: { vscodeExtPublisher = publisher; }
else
let
subPath = pathSpecial.${publisher} or extensionId;
path = pathNixpkgs + "/pkgs/applications/editors/vscode/extensions/${subPath}";
extension' =
if builtins.pathExists path then
let
extension'' = callPackage path { };
in
if publisher == "ms-ceintl" then extension''.${name} else extension''
else
extension;
in
{ mktplcRef, vsix }@extensionConfig:
if builtins.elem extensionId extensionsProblematic then
buildVscodeMarketplaceExtension (
extensionConfig // (if extension' ? meta then { meta = extension'.meta; } else { })
)
else
(extension'.override
or (abort "The extension '${publisher}.${name}' doesn't have an 'override' attribute.")
)
extensionConfig
)
) extensionsNixpkgs;
chooseMkExtension =
self:
{
mktplcRef,
vsix,
engineVersion,
platform,
isRelease,
}@extensionConfig:
let
mkExtension =
(self.${mktplcRef.publisher} or { }).${mktplcRef.name} or (
if builtins.elem "${mktplcRef.publisher}.${mktplcRef.name}" extensionsRemoved then
# In `./nix/overlay.nix`, there is a check whether the result is a derivation.
_: { vscodeExtPublisher = mktplcRef.publisher; }
else
buildVscodeMarketplaceExtension
);
extension = (mkExtension { inherit mktplcRef vsix; }) // {
passthru = extensionConfig;
};
in
extension;
in
builtins.foldl' lib.attrsets.recursiveUpdate { } [
mkExtensionNixpkgs
mkExtensionLocal
{ __functor = chooseMkExtension; }
]