Vscode extension overlay with home-manager

Hi there,

I’m trying to use overlay with home-manager. but the following doesn’t work. The vscode extensions are not using the overlay. why is that?

{ config, ... }:
let 

  commitRev = "82b54d490663b6d87b7b34b9cfc0985df8b49c7d"; # unstable on 06-03-2020

  nixpkgs = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs-channels/archive/${commitRev}.tar.gz";
    sha256 = "12gpsif48g5b4ys45x36g4vdf0srgal4c96351m7gd2jsgvdllyf";
  };

  pkgs = import nixpkgs { config = {allowUnfree = true;}; };  


  commitRev_vscode = "be80721e747b3ea3d89b3a945cb85669f4f8ddce"; # unstable on 06-03-2020

  nixpkgs_vscode = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs-channels/archive/${commitRev}.tar.gz";
    sha256 = "12gpsif48g5b4ys45x36g4vdf0srgal4c96351m7gd2jsgvdllyf"; 
  };

  pkgs_vscode = import nixpkgs_vscode { config = {allowUnfree = true;}; };

  
  vscode-overlay = self: super:
  {
    inherit (pkgs_vscode) vscode vscode-utils;

    vscode-extensions = super.vscode-extensions.override{
      scala-lang.scala = self.vscode-utils.buildVscodeMarketplaceExtension {
        mktplcRef = {
          name = "scala";
          publisher = "scala-lang";
          version = "0.3.9";
          sha256 = "0l6zrpp2klqdym977zygmbzf0478lbqmivcxa2xmqyi34c9vwli7";
        };
      meta = {
        license = self.stdenv.lib.licenses.mit;
      };

      scalameta.metals =
        self.vscode-utils.buildVscodeMarketplaceExtension {
          mktplcRef = {
            name = "metals";
            publisher = "scalameta";
            version = "1.8.0";
            sha256 = "0r1r96xclr8c3rjgs944zdim9rjq6hfajvv7yh3hn75cy684bck5";
          };
        meta = {
          license = self.stdenv.lib.licenses.asl20;
        };
      };
    };
    
  };


  };

in
{
  nixpkgs.config.allowUnfree = true;
  
  nixpkgs.overlays = [ vscode-overlay ];

  home.packages = with pkgs; [
    brave # browser
    openjdk11
    sbt
  ];

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

  services.lorri.enable = true;

  programs.vscode = with pkgs; {
    enable = true;
    userSettings = {
      "window.zoomLevel" = 0;
      "git.autofetch" = false;
      "diffEditor.ignoreTrimWhitespace" = true;
      "gitlens.advanced.messages" = {
        "suppressFileNotUnderSourceControlWarning" = true;
      };
      "files.exclude" = {
        "**/.classpath" = true;
        "**/.project" = true;
        "**/.settings" = true;
        "**/.factorypath" = true;
      };
      "remote.SSH.defaultExtensions" = [
        "eamodio.gitlens"
        "latest_scala_lang"
        "latest_scalameta_metals"
      ];
      "metals.javaHome" = "/home/zhenhao/.nix-profile";
    };
    extensions = with vscode-extensions; [
      bbenoist.Nix
      scala-lang.scala
      scalameta.metals #scalameta.metals
      ms-vscode-remote.remote-ssh
    ];
  };

}

pkgs is a direct import from the channel without overlays.

You need to add the overlays when you import it, or avoid the pinned import and rely on the passed in pkgs.

I have not yet found a good way to pin nixpkgs for home-manager :frowning: And even @rycee did not answer/see my follow up question in an earlier discussion on this forum.

Thanks! @NobbZ
I made it simpler after your advice.

{ config, ... }:
let 

  commitRev = "82b54d490663b6d87b7b34b9cfc0985df8b49c7d"; # unstable on 06-03-2020

  nixpkgs = builtins.fetchTarball {
    url = "https://github.com/NixOS/nixpkgs-channels/archive/${commitRev}.tar.gz";
    sha256 = "12gpsif48g5b4ys45x36g4vdf0srgal4c96351m7gd2jsgvdllyf"; 
  };
  
  vscode-overlay = self: super:
  {
    vscode-extensions = super.vscode-extensions.override{
      
      scala-lang.scala = 
        super.vscode-utils.buildVscodeMarketplaceExtension {
          mktplcRef = {
            name = "scala";
            publisher = "scala-lang";
            version = "0.3.9";
            sha256 = "0l6zrpp2klqdym977zygmbzf0478lbqmivcxa2xmqyi34c9vwli7";
          };
          meta = {
            license = super.stdenv.lib.licenses.mit;
          };
        };

      scalameta.metals =
        super.vscode-utils.buildVscodeMarketplaceExtension {
          mktplcRef = {
            name = "metals";
            publisher = "scalameta";
            version = "1.8.0";
            sha256 = "0r1r96xclr8c3rjgs944zdim9rjq6hfajvv7yh3hn75cy684bck5";
          };
          meta = {
            license = super.stdenv.lib.licenses.asl20;
          };
        };
    
    };
  };

  pkgs = import nixpkgs { 
    config = {allowUnfree = true;}; 
    overlays = [ vscode-overlay ];
  };  
in
{
  nixpkgs.config.allowUnfree = true;
  
  nixpkgs.overlays = [ vscode-overlay ];

  home.packages = with pkgs; [
    brave # browser
    openjdk11
    sbt
  ];

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

  services.lorri.enable = true;

  programs.vscode = with pkgs; {
    enable = true;
    userSettings = {
      "window.zoomLevel" = 0;
      "git.autofetch" = false;
      "diffEditor.ignoreTrimWhitespace" = true;
      "gitlens.advanced.messages" = {
        "suppressFileNotUnderSourceControlWarning" = true;
      };
      "files.exclude" = {
        "**/.classpath" = true;
        "**/.project" = true;
        "**/.settings" = true;
        "**/.factorypath" = true;
      };
      "remote.SSH.defaultExtensions" = [
        "eamodio.gitlens"
        "latest_scala_lang"
        "latest_scalameta_metals"
      ];
      "metals.javaHome" = "/home/zhenhao/.nix-profile";
    };
    extensions = with vscode-extensions; [
      bbenoist.Nix
      #scala-lang.scala
      scalameta.metals #scalameta.metals
      ms-vscode-remote.remote-ssh
    ];
  };

}

however, now I get error

error: anonymous function at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/pkgs/misc/vscode-extensions/default.nix:1:1 called with unexpected argument 'scala-lang', at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/lib/customisation.nix:69:16

Is this file vscode-extension/default.nix or customisation.nix?

this is my ~/.config/nixpkgs/home.nix file.
That’s why I am confused by the error

Ah, okay, the error shows something in your downloaded nixpkgs snapshot…

Perhaps use --sow-trace to get a full trace.

Not sure beyond that, I don’t use vscode declaratively.

I’m using it imperatively for quickly hacking stuff when I don’t want to change my config for emacs but still need some language tools.

the trace is:

error: while evaluating the attribute 'buildCommand' of the derivation 'home-manager-generation' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/pkgs/build-support/trivial-builders.nix:7:14:
while evaluating the attribute 'text' of the derivation 'activation-script' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/pkgs/build-support/trivial-builders.nix:7:14:
while evaluating 'mkCmd' at /home/zhenhao/.nix-defexpr/channels/home-manager/modules/home-environment.nix:395:17, called from undefined position:
while evaluating the attribute 'data' at /home/zhenhao/.nix-defexpr/channels/home-manager/modules/lib/dag.nix:91:37:
while evaluating the attribute 'data' at /home/zhenhao/.nix-defexpr/channels/home-manager/modules/lib/dag.nix:85:9:
while evaluating the attribute 'data' at undefined position:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:75:45, called from undefined position:
while evaluating the attribute 'value' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:336:9:
while evaluating the option `home.activation.checkFilesChanged.data':
while evaluating the attribute 'isDefined' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:373:5:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:362:9:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:456:7:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:28, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:17:
while evaluating 'dischargeProperties' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:415:25, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:349:62:
while evaluating the attribute 'value' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:234:44:
while evaluating 'concatMapStrings' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/strings.nix:31:25, called from /home/zhenhao/.nix-defexpr/channels/home-manager/modules/files.nix:213:12:
while evaluating the attribute 'home.file' at undefined position:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:75:45, called from undefined position:
while evaluating the attribute 'value' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:336:9:
while evaluating the option `home.file':
while evaluating the attribute 'isDefined' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:373:5:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:362:9:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:456:7:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:28, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:17:
while evaluating 'dischargeProperties' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:415:25, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:349:62:
while evaluating 'dischargeProperties' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:415:25, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:421:11:
while evaluating the attribute 'content' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:500:14:
while evaluating 'foldr' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/lists.nix:52:20, called from /home/zhenhao/.nix-defexpr/channels/home-manager/modules/programs/vscode.nix:91:9:
while evaluating 'fold'' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/lists.nix:55:15, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/lists.nix:59:8:
while evaluating the attribute 'extensions' at undefined position:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:75:45, called from undefined position:
while evaluating the attribute 'value' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:336:9:
while evaluating the option `programs.vscode.extensions':
while evaluating the attribute 'mergedValue' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:368:5:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:368:32, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:368:19:
while evaluating 'merge' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/types.nix:256:20, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:371:8:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/types.nix:257:35, called from undefined position:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/lists.nix:116:29, called from undefined position:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/types.nix:259:23, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/lists.nix:116:32:
while evaluating the attribute 'optionalValue' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:375:5:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:362:9:
while evaluating the attribute 'values' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:456:7:
while evaluating anonymous function at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:28, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:348:17:
while evaluating 'dischargeProperties' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:415:25, called from /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/modules.nix:349:62:
while evaluating the attribute 'value' at /nix/store/x8vj04ycchwckh0xqlhnrzx9k0g7m6ih-nixos-19.09.2229.d7843c8add6/nixos/lib/types.nix:263:40:
while evaluating anonymous function at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/lib/customisation.nix:77:32, called from /home/zhenhao/.config/nixpkgs/home.nix:13:25:
while evaluating 'makeOverridable' at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/lib/customisation.nix:67:24, called from /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/lib/customisation.nix:77:41:
anonymous function at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/pkgs/misc/vscode-extensions/default.nix:1:1 called with unexpected argument 'scala-lang', at /nix/store/8x90sd5m33zhz96z72zgydgy11nc6wb2-source/lib/customisation.nix:69:16

I will try to install it via the OS to see if the overlay works

Late to the party, but I think this all breaks because .override only supports the arguments to the function that produces the attrset known as vscode-extensions. scalameta and friends aren’t arguments, they’re just attributes of the attrset returned from the fun, so we can override them as we usually would on these - with // or lib.recursiveUpdate.

I stumbled on this thread while trying to solve this exact problem and I’m going with this overlay:

self: super: {
  vscode-extensions = self.lib.recursiveUpdate super.vscode-extensions {
    scalameta.metals = self.vscode-utils.extensionFromVscodeMarketplace {
      name = "metals";
      publisher = "scalameta";
      version = "1.9.10";
      sha256 = "0v599yssvk358gxfxnyzzkyk0y5krsbp8n4rkp9wb2ncxqsqladr";
    };
    # any other overrides here
  };
};

It seems to work.

1 Like