Visual Studio Code: Difference between revisions
m add vscodium precision |
enhancement: general |
||
| Line 13: | Line 13: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Extensions can be managed using | Extensions can be managed using {{Nixpkg|pkgs/applications/editors/vscode/with-extensions.nix|vscode-with-extensions}} : | ||
<syntaxhighlight lang="nix">environment.systemPackages = with pkgs; [ | <syntaxhighlight lang="nix">environment.systemPackages = with pkgs; [ | ||
| Line 33: | Line 33: | ||
];</syntaxhighlight> | ];</syntaxhighlight> | ||
Some examples here: [https://github.com/search?q=extensionFromVscodeMarketplace&type | Some examples here: [https://github.com/search?type=code&q=language:Nix+"extensionFromVscodeMarketplace" GitHub Search - type:code language:Nix "extensionFromVscodeMarketplace"] | ||
Note | {{Note|For fetching the sha256 string you can use [https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-store-prefetch-file <code>nix store prefetch-file</code>] like so: | ||
< | |||
<syntaxhighlight lang="console">nix store prefetch-file marketplace.visualstudio.com/_apis/public/gallery/publishers/<publisher>/vsextensions/<extension>/<version>/vspackage</syntaxhighlight> | |||
Example: | |||
<syntaxhighlight lang="console">nix store prefetch-file https://marketplace.visualstudio.com/_apis/public/gallery/publishers/ms-vscode-remote/vsextensions/remote-ssh-edit/0.47.2/vspackage</syntaxhighlight>}} | |||
<code>extensionsFromVscodeMarketplace</code> is a manual way to fetch extensions. However, to keep updated from upstream, [https://github.com/nix-community/nix-vscode-extensions nix-community/nix-vscode-extensions] provides the Nix expressions for the majority of available extensions from Open VSX and VSCode Marketplace. A GitHub Action updates the extensions daily. Similarly, [https://github.com/nix-community/nix4vscode nix-community/nix4vscode] provides a Nix overlay for VSCode Marketplace and Open VSX extensions. | |||
=== Home Manager === | |||
<syntaxhighlight lang="nix">programs.vscode = { | <syntaxhighlight lang="nix">programs.vscode = { | ||
enable = true; | enable = true; | ||
| Line 53: | Line 58: | ||
* Search for extensions with configurations: [https://search.nixos.org/packages?type=packages&query=vscode-extensions NixOS Search: vscode-extensions] | * Search for extensions with configurations: [https://search.nixos.org/packages?type=packages&query=vscode-extensions NixOS Search: vscode-extensions] | ||
=== | === Nix-env === | ||
{{Warning|Use of nix-env is not recommended}}< | {{Warning|Use of nix-env is unreproducible and thus discouraged and not recommended}}<syntaxhighlight lang="console">nix-env -iA nixos.vscode</syntaxhighlight> | ||
</ | |||
== Use VS Code extensions without additional configuration == | |||
With {{Nixpkg|pkgs/applications/editors/vscode/generic.nix|vscode.fhs}}, the editor launches inside a [[wikipedia:Filesystem_Hierarchy_Standard|FHS]] compliant chroot environment using {{Manual|nixpkgs|sec-fhs-environments|<code>buildFHSEnv</code>}}. This reintroduces directories such as <code>/bin</code>, <code>/lib</code>, and <code>/usr</code>, which allows for extensions which ship pre-compiled binaries to work with little to no additional nixification. | |||
{{note|{{Manual|nixpkgs|sec-fhs-environments|<code>buildFHSEnv</code>}} allows for ease-of-use at the cost of impurity, non-reproducibility, and denied root access (you cannot use <code>sudo</code> in <code>.fhs</code> packages, also see [https://discourse.nixos.org/t/sudo-does-not-work-from-within-vscode-fhs/14227])}} | |||
=== NixOS === | |||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
environment.systemPackages = with pkgs; [ vscode.fhs ]; | environment.systemPackages = with pkgs; [ vscode.fhs ]; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Home | === Home Manager === | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
programs.vscode = { | programs.vscode = { | ||
| Line 90: | Line 92: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Insiders Build == | |||
If you need to test a recent code change, you can run the insiders build. It is designed to run alongside the main build, with a separate <code>code-insiders</code> command and a different config path, so you can leave your main VS Code instance installed/running. | If you need to test a recent code change, you can run the insiders build. It is designed to run alongside the main build, with a separate <code>code-insiders</code> command and a different config path, so you can leave your main VS Code instance installed/running. | ||
The following derivation | The following derivation builds a package with the latest insiders build (on NixOS in <code>environment.systemPackages</code>, or on Home Manager in <code>home.packages</code>) : | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
| Line 108: | Line 109: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
''[https://discourse.nixos.org/t/how-to-install-latest-vscode-insiders/7895/4 credits: @jnoortheen]'' | |||
=== Updating insiders placeholder <code>sha256</code> === | |||
You will need to update the placeholder <code>sha256</code> value for each new Insiders build. | You will need to update the placeholder <code>sha256</code> value for each new Insiders build. | ||
| Line 117: | Line 118: | ||
Put an arbitrary placeholder value in the <code>sha256</code> field, try to build and you'll get an error message regarding the sha256 value. | Put an arbitrary placeholder value in the <code>sha256</code> field, try to build and you'll get an error message regarding the sha256 value. | ||
=== Resolving the "hash mismatch" error === | |||
==== | ==== For <code>sha256:</code> ==== | ||
Example:<pre>//-- ... | |||
<pre> | |||
//-- ... | |||
error: hash mismatch in file downloaded from 'https://code.visualstudio.com/sha/download?build=insider&os=linux-x64': | error: hash mismatch in file downloaded from 'https://code.visualstudio.com/sha/download?build=insider&os=linux-x64': | ||
specified: sha256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | specified: sha256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | ||
got: sha256:16fzxqs6ql4p2apq9aw7l10h4ag1r7jwlfvknk5rd2zmkscwhn6z | got: sha256:16fzxqs6ql4p2apq9aw7l10h4ag1r7jwlfvknk5rd2zmkscwhn6z | ||
//-- ... | //-- ...</pre> | ||
</pre> | |||
Copy the "got" value (while stripping out the prepended "<code>sha256:</code>"), and paste it in your placeholder <code>sha256</code> value | |||
Resulting: "<code>16fzxqs6ql4p2apq9aw7l10h4ag1r7jwlfvknk5rd2zmkscwhn6z</code>" | |||
===== | ===== For <code>sha256-</code> ===== | ||
Example:<pre>//-- ... | |||
<pre> | |||
//-- ... | |||
error: hash mismatch in fixed-output derivation '/nix/store/path': | error: hash mismatch in fixed-output derivation '/nix/store/path': | ||
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | ||
got: sha256-aQvTtZdPU2F1UjkFxiLs4A+60A4qc9bXKwKriNsCDPg= | got: sha256-aQvTtZdPU2F1UjkFxiLs4A+60A4qc9bXKwKriNsCDPg= | ||
//-- ... | //-- ...</pre> | ||
</ | |||
Copy the "got" value (while stripping out the prepended "<code>sha256-</code>") | |||
Then, run the following python script: | |||
< | <syntaxhighlight lang="python"> | ||
import base64 | import base64 | ||
text = b'aQvTtZdPU2F1UjkFxiLs4A+60A4qc9bXKwKriNsCDPg=' # Replace the string in between ' with the according hash | |||
text = b'aQvTtZdPU2F1UjkFxiLs4A+60A4qc9bXKwKriNsCDPg=' | |||
print(base64.decodebytes(text).hex()) | print(base64.decodebytes(text).hex()) | ||
</ | </syntaxhighlight> | ||
Its output should be pasted in your placeholder <code>sha256</code> value | |||
== Creating development environments using nix-shell == | == Creating development environments using nix-shell == | ||
| Line 163: | Line 161: | ||
== Wayland == | == Wayland == | ||
To use VS Code under Wayland, set the environment variable <code>NIXOS_OZONE_WL=1</code>: | To use VS Code under Wayland, set the environment variable <code>NIXOS_OZONE_WL=1</code> ([https://github.com/NixOS/nixpkgs/commit/b2eb5f62a7fd94ab58acafec9f64e54f97c508a6 ''Source'']) | ||
=== Declaratively (permanent) === | |||
<syntaxHighlight lang=nix>environment.sessionVariables.NIXOS_OZONE_WL = "1";</syntaxHighlight> | |||
=== Imperatively (each time you launch VSCode) === | |||
<syntaxhighlight lang="console">NIXOS_OZONE_WL=1 code ...</syntaxhighlight> | |||
== Updating extension versions == | == Updating extension versions == | ||
| Line 179: | Line 175: | ||
=== Example output === | === Example output === | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console">curl -fsSL https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/applications/editors/vscode/extensions/update_installed_exts.sh | sh | ||
{ extensions = [ | { extensions = [ | ||
{ | { | ||