Overriding vscode version

I’m trying to override the vscode version in my configuration.nix.

I have the following in my environment.SystemPackages to install vscode 1.60.0 (I’m on the nixos-21.05 channel). When I open vscode it still reports the version as 1.57.1 with no extensions installed.

(vscode-with-extensions.overrideAttrs(old: rec {
      vscode = pkgs.vscode.overrideAttrs(old: rec {
        name = "vscode";
        version = "1.60.0";
        src = fetchurl {
          name = "VSCode_${version}_linux-x64.tar.gz";
          url = "https://update.code.visualstudio.com/${version}/linux-x64/stable";
          sha256 = "0g49765pnimh107pw3q7dlgd6jcmr5gagsvxrdx8i93mbxb0xm0c";
        };
      });
      vscodeExtensions = (with vscode-extensions; [
        vadimcn.vscode-lldb
        usernamehw.errorlens
        ms-vscode.cpptools
        jnoortheen.nix-ide
      ]);
    }))
  ];

You need to change the hash to trigger a rebuild. If you don’t know the new hash, you can trigger a rebuild and let nix tell you the correct hash (it will complain about hash mismatch). You can achieve this by changing sha256 to lib.fakeSha256 or changing a single character of the current hash.

Which hash? That is the correct hash for the VSCode_1.60.0_linux-x86.tar.gz file.

Sorry, you are right. It was not about the hash. I just assumed it was that because it is a common mistake. But that wouldn’t explain the missing extensions anyway.

Can you try something like this:

let
  vscode = pkgs.vscode.overrideAttrs(old: rec {
    version = "1.60.0";
    src = fetchurl {
      name = "VSCode_${version}_linux-x64.tar.gz";
      url = "https://update.code.visualstudio.com/${version}/linux-x64/stable";
      sha256 = "0g49765pnimh107pw3q7dlgd6jcmr5gagsvxrdx8i93mbxb0xm0c";
    };
  });
  vscodeExtensions = with pkgs.vscode-extensions; [
    vadimcn.vscode-lldb
    usernamehw.errorlens
    ms-vscode.cpptools
    jnoortheen.nix-ide
  ];
  vscode-with-extensions = pkgs.vscode-with-extensions.override {
    inherit vscode vscodeExtensions;
  };
in
{
  config = {
    environment.systemPackages = [
      vscode-with-extensions
    ];
  };
}

I think the problem was using overrideAttrs^1 instead of override^2. overrideAttrs is modifying the set passed to stdenv.mkDerivation but we need to modify the values before that so that variables in here refer to the values we want, which is possible with override.

I tried building the above derivation; VSCode was showing the correct version and the extensions was also successfully installed.