-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmkExtension.nix
149 lines (130 loc) · 4.5 KB
/
mkExtension.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
# Each `${publisher}.${name}` MUST provide a function `{ mktplcRef, vsix } -> Derivation`
# Each Derivation MUST be produced via overridable `buildVscodeMarketplaceExtension` (see below)
# Custom fixes are loaded via `mkExtensionLocal`
{ pkgs, pkgsWithFixes }:
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).${pkgs.system} or [ ];
callPackage = pkgs.beam.beamLib.callPackageWith pkgs';
# TODO find a cleaner way to get the store path of nixpkgs from given pkgs
pathNixpkgs = 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 =
# 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"
]
++
# Have old fixes
[
# Doesn't build due to the patch
# https://github.com/NixOS/nixpkgs/tree/a3cd526f08839bd963e7d106b7869694b0579a94/pkgs/applications/editors/vscode/extensions/hashicorp.terraform
# TODO newer fix
"hashicorp.terraform"
];
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
else
(extension'.override
or (abort "The extension '${publisher}.${name}' doesn't have an 'override' attribute.")
)
extensionConfig
)
) extensionsNixpkgs;
chooseMkExtension =
self:
{
mktplcRef,
vsix,
engineVersion,
}@extensionConfig:
let
mkExtension = (
(self.${mktplcRef.publisher} or { }).${mktplcRef.name} or (
if builtins.elem "${mktplcRef.publisher}.${mktplcRef.name}" extensionsRemoved then
# In `flake.nix`, there is a check whether the result is a derivation.
_: { vscodeExtPublisher = mktplcRef.publisher; }
else
buildVscodeMarketplaceExtension
)
);
in
# TODO fix on macOS after enabling
# (mkExtension { inherit mktplcRef vsix engineVersion; }).overrideAttrs (prev: {
# passthru = prev.passthru // extensionConfig;
# })
mkExtension { inherit mktplcRef vsix; };
in
builtins.foldl' lib.attrsets.recursiveUpdate { } [
mkExtensionNixpkgs
mkExtensionLocal
{ __functor = chooseMkExtension; }
]