forked from nix-community/nix-vscode-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkExtension.nix
185 lines (167 loc) · 6.24 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
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
# Each ${publisher}.${name} MUST provide a function { mktplcRef, vsix } -> Derivation
# Each Derivation MUST be produced via overridable buildVscodeMarketplaceExtension
# Write custom fixes in mkExtensionLocal
{ pkgs, nixpkgs }:
let
inherit (pkgs) lib;
mkExtension = lib.customisation.makeOverridable pkgs.vscode-utils.buildVscodeMarketplaceExtension;
pkgs' = lib.attrsets.recursiveUpdate pkgs {
vscode-utils.buildVscodeMarketplaceExtension = mkExtension;
};
applyMkExtension = builtins.mapAttrs (
publisher:
builtins.mapAttrs (
name: f: ({ mktplcRef, vsix }@extensionConfig: mkExtension (extensionConfig // f extensionConfig))
)
);
mkExtensionLocal = applyMkExtension {
# Write your fixes here
# Each ${publisher}.${name} MUST provide a function { mktplcRef, vsix } -> Attrset
# Each Attrset must be a valid argument of mkExtension (see above)
# Use mkExtensionNixpkgs to override extensions from nixpkgs.
#
# Example:
#
# ```nix
# foo.bar = { mktplcRef, vsix }@arg: (mkExtensionNixpkgs.foo.bar arg).override { postInstall = "..."; };
# ```
# Credit to https://github.com/nix-community/nix-vscode-extensions/issues/52#issue-2129112776
vadimcn.vscode-lldb = _: {
postInstall = lib.optionalString pkgs.stdenv.isLinux ''
cd "$out/$installPrefix"
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" ./adapter/codelldb
patchelf --add-rpath "${lib.makeLibraryPath [ pkgs.zlib ]}" ./lldb/lib/liblldb.so
'';
};
ms-dotnettools.vscode-dotnet-runtime = _: {
postPatch = ''
chmod +x "$PWD/dist/install scripts/dotnet-install.sh"
'';
};
ms-vsliveshare.vsliveshare = _: {
# Similar to https://github.com/NixOS/nixpkgs/blob/6f5808c6534d514751d6de0e20aae83f45d9f798/pkgs/applications/editors/vscode/extensions/ms-vsliveshare.vsliveshare/default.nix#L15-L18
# Not sure it's necessary
postPatch = ''
substituteInPlace vendor.js \
--replace-fail '"xsel"' '"${pkgs.xsel}/bin/xsel"'
'';
};
};
extensionsRemoved = (import ./removed.nix).${pkgs.system} or [ ];
mkExtensionNixpkgs =
# apply fixes from nixpkgs
let
# TODO PR to nixpkgs to allow overriding mktplcRef and vsix
haveFixesNonOverridable = [
"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"
];
# extensions with fixes
# where mktplcRef and vsix are overridable
haveFixesOverridable = [
# have own directories in https://github.com/NixOS/nixpkgs/tree/555702214240ef048370f6c2fe27674ec73da765/pkgs/applications/editors/vscode/extensions
"asciidoctor.asciidoctor-vscode"
"azdavis.millet"
"b4dm4n.vscode-nixpkgs-fmt"
"betterthantomorrow.calva"
"charliermarsh.ruff"
"chrischinchilla.vscode-pandoc"
"contextmapper.context-mapper-vscode-extension"
"eugleo.magic-racket"
"foxundermoon.shell-format"
"hashicorp.terraform"
"jackmacwindows.craftos-pc"
"jebbs.plantuml"
"kamadorueda.alejandra"
"ms-dotnettools.csdevkit" # unfree
"ms-dotnettools.csharp"
"ms-python.python"
"ms-python.vscode-pylance" # unfree
"ms-toolsai.jupyter"
"ms-vscode-remote.remote-ssh" # unfree
"ms-vscode-remote.vscode-remote-extensionpack" # unfree
"ms-vscode.cpptools"
"ms-vsliveshare.vsliveshare"
"myriad-dreamin.tinymist"
"reditorsupport.r"
"sourcery.sourcery" # unfree
"sumneko.lua"
"tekumara.typos-vscode"
"timonwong.shellcheck"
"visualjj.visualjj" # unfree
"yzane.markdown-pdf"
# completely described in https://github.com/NixOS/nixpkgs/blob/555702214240ef048370f6c2fe27674ec73da765/pkgs/applications/editors/vscode/extensions/default.nix
"continue.continue"
"devsense.phptools-vscode" # unfree
"kddejong.vscode-cfn-lint"
"ms-dotnettools.vscodeintellicode-csharp" # unfree
"uloco.theme-bluloco-light"
"valentjn.vscode-ltex"
"zxh404.vscode-proto3"
];
extensionsNixpkgsPath = "${nixpkgs}/pkgs/applications/editors/vscode/extensions/default.nix";
callPackage = pkgs.beam.beamLib.callPackageWith pkgs';
extensionsNixpkgs = callPackage extensionsNixpkgsPath { };
fixed = lib.trivial.pipe haveFixesOverridable [
(builtins.filter (x: !(builtins.elem x extensionsRemoved)))
(builtins.map (
fullName:
let
fullNameList = lib.strings.splitString "." fullName;
publisher = lib.lists.head fullNameList;
name = lib.lists.last fullNameList;
in
{
inherit publisher name fullName;
}
))
(builtins.filter (
{
publisher,
name,
fullName,
}:
(extensionsNixpkgs.${publisher} or { }).${name} or { } != { }
))
(builtins.map (
{
publisher,
name,
fullName,
}:
let
path = "${nixpkgs}/pkgs/applications/editors/vscode/extensions/${fullName}";
extension =
if builtins.pathExists path then callPackage path { } else extensionsNixpkgs.${publisher}.${name};
in
{
${publisher}.${name} = { mktplcRef, vsix }@extensionConfig: extension.override extensionConfig;
}
))
(builtins.foldl' lib.attrsets.recursiveUpdate { })
];
in
fixed;
chooseMkExtension =
self:
{ mktplcRef, vsix }@extensionConfig:
((self.${mktplcRef.publisher} or { }).${mktplcRef.name} or (
if builtins.elem "${mktplcRef.publisher}.${mktplcRef.name}" extensionsRemoved then
builtins.throw ''
The extension '${mktplcRef.publisher}.${mktplcRef.name}' has been removed on ${pkgs.system}.
See '${./removed.nix}' for details.
''
else
mkExtension
)
)
extensionConfig;
in
builtins.foldl' lib.attrsets.recursiveUpdate { } [
mkExtensionNixpkgs
mkExtensionLocal
{ __functor = chooseMkExtension; }
]