nix-community / nixos-vscode-server

Visual Studio Code Server support in NixOS
MIT License
419 stars 76 forks source link

Unable to install extensions #82

Closed Guusvanmeerveld closed 2 weeks ago

Guusvanmeerveld commented 5 months ago

I have been using this flake for a while and its been working great, except I cannot seem to install server-sided extensions. Every time I try to install one I get an error of the following form:

Unable to write file '/home/guus/.vscodium-server/extensions/.a88d889b-1e75-4d34-af54-73606f9b151f/package.json' (EntryWriteLocked (FileSystemError): Error: EACCES: permission denied, open '/home/guus/.vscodium-server/extensions/.a88d889b-1e75-4d34-af54-73606f9b151f/package.json')

Did I mess up something while setting up my config? I am using the following config:

services.vscode-server = {
      enable = true;
      installPath = "$HOME/.vscodium-server";
};

I am using VSCodium version 1.88.1

codgician commented 3 months ago

Experiencing the same here. Are you managing local VSCodium extensions with Nix and have immutable extensions directory enabled?

Guusvanmeerveld commented 3 months ago

Yep, you can find my local vscode configuration here

Cryolitia commented 3 weeks ago

I got this, too. Is there any progress?

Ten0 commented 3 weeks ago

I do not have this issue with official Vscode and with mutable extensions directory. Feel free to open a PR that fixes this if you can figure out why it happens.

codgician commented 2 weeks ago

If I enable immutable extensions directory on client side, I noticed:

I tried to observe the extracted directory for what is happening when I try to install a locally installed extension, and found that package.json is missing in the uploaded extension causing the error. I have also confirmed that package.json is missing in the unextracted file from the beginning.

image

My guess is, if immutable extensions directory is enabled, due to extensions are managed by Nix vscode is having a different behavior for installing extensions. This might have resulted in partial upload of the locally installed content.

A workaround I found is to add extension's unique identifier into vscode settings remote.SSH.defaultExtensions (link to doc), because the default extensions are downloaded from marketplace on server side instead of uploading from local.

At this point, I suspect the underlying issue is not related to this project at all. If I have more time I may try to look further into why package.json is not present in the uploaded extension.

Guusvanmeerveld commented 2 weeks ago

Personally, to get around this issue, I copied the code that home-manager uses to install extensions with an immutable extensions directory:

{
  config,
  lib,
  pkgs,
  ...
}: let
  extensions = config.services.vscode-server-extensions;
  cfg = config.services.vscode-server;

  extensionDir = cfg.installPath;

  extensionPath = "${extensionDir}/extensions";

  extensionJson = pkgs.vscode-utils.toExtensionJson extensions;
  extensionJsonFile = pkgs.writeTextFile {
    name = "extensions-json";
    destination = "/share/vscode/extensions/extensions.json";
    text = extensionJson;
  };
in {
  options = {
    services.vscode-server-extensions = lib.mkOption {
      type = lib.types.listOf lib.types.package;
      default = [];
    };
  };

  config = lib.mkIf cfg.enable {
    home.file = {
      "${extensionPath}".source = (
        let
          subDir = "share/vscode/extensions";
          combinedExtensionsDrv = pkgs.buildEnv {
            name = "vscode-extensions";
            paths =
              extensions
              ++ lib.singleton extensionJsonFile;
          };
        in "${combinedExtensionsDrv}/${subDir}"
      );
    };
  };
}

This is a bit of a crude solution, as this does mean that I have to specify all of the extensions that I want to twice, once on my client and once on my server, but for my use case, this is perfectly fine.