Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a workaround to support VS Code's Remote WSL extension (fix #238) #324

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
nix-ld-rs.url = "github:nix-community/nix-ld-rs";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
outputs = inputs@{ self, nixpkgs, flake-utils, nix-ld-rs, ... }:
with nixpkgs.lib;
{

Expand All @@ -21,6 +22,7 @@

({ ... }: {
wsl.version.rev = mkIf (self ? rev) self.rev;
wsl.vscodeRemoteWslExtensionWorkaround.nix-ld-rs = nix-ld-rs;
})
];
};
Expand Down
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
./welcome.nix
./wsl-conf.nix
./wsl-distro.nix
./vscode-remote-wsl-extension-workaround.nix

(lib.mkRemovedOptionModule [ "wsl" "docker-native" ]
"Additional workarounds are no longer required for Docker to work. Please use the standard `virtualisation.docker` NixOS options.")
Expand Down
37 changes: 37 additions & 0 deletions modules/vscode-remote-wsl-extension-workaround.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ lib, config, pkgs, ... }:
{
options.wsl.vscodeRemoteWslExtensionWorkaround = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Workaround for VSCode's Remote WSL extension";
};
nix-ld-rs = lib.mkOption {
type = lib.types.raw;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be type package.

description = "The flake input to use for `nix-ld-rs`";
};
};

config =
let
cfg = config.wsl.vscodeRemoteWslExtensionWorkaround;
in
lib.mkIf cfg.enable {
wsl.extraBin = [
# Required by VS Code's Remote WSL extension
{ src = "${pkgs.coreutils}/bin/dirname"; }
{ src = "${pkgs.coreutils}/bin/readlink"; }
{ src = "${pkgs.coreutils}/bin/uname"; }
];
programs.nix-ld = {
enable = true;
libraries = [
# Required by NodeJS installed by VS Code's Remote WSL extension
pkgs.stdenv.cc.cc
];

# Use `nix-ld-rs` instead of `nix-ld`, because VS Code's Remote WSL extension launches a non-login non-interactive shell, which is not supported by `nix-ld`, while `nix-ld-rs` works in non-login non-interactive shells.
package = cfg.nix-ld-rs.packages.${pkgs.system}.nix-ld-rs;
};
};
}