Overlay to change buildNpmPackage version with flakes

I want to override the version of the vscode-js-debug package in nixos-24.11 from 1.94.0 to 1.76.1.

My Approach

I’ve set up a flake.nix and an overlay as follows:

./flake.nix

{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

  outputs = {nixpkgs, ...}: {
    defaultPackage.x86_64-linux = let
      pkgs = import nixpkgs {
        overlays = [(import ./overlay.nix)];
        system = "x86_64-linux";
      };
    in
      pkgs.vscode-js-debug;
  };
}

./overlay.nix

final: prev: {
  vscode-js-debug = prev.vscode-js-debug.overrideAttrs (_: rec {
    version = "1.76.1";
    src = final.fetchFromGitHub {
      owner = "microsoft";
      repo = "vscode-js-debug";
      rev = "v${version}";
      hash = "sha256-YGMIzGcjQhz/H6DpxQSOwV6eXVNDXX7mFN56FejDcXo=";
    };
    npmDepsHash = "sha256-lDoj/94tjJd4ZGU9WgrMOqNSmdpeCljU4c6jGX+TSDY=";
  });
}

The Problem

When I attempt to build, it fails with the following error:

ERROR: npmDepsHash is out of date

The package-lock.json in src is not the same as in /nix/store/h7zr17lmh19dpwgd8zjhnprp12x98by7-vscode-js-debug-1.94.0-npm-deps.

To fix the issue:
1. Use `lib.fakeHash` as the npmDepsHash value
2. Build the derivation and wait for it to fail with a hash mismatch
3. Copy the 'got: sha256-' value back into the npmDepsHash field

What I’ve Tried

  1. I set npmDepsHash to lib.fakeHash as recommended.
  2. After the build failed, I checked the logs, but I could not find the real hash.
  3. I used prefetch-npm-deps to calculate the npmDepsHash for the package-lock.json of both versions (1.76.1 and 1.94.0):

Despite these steps, I still get the same error, and it appears to be fetching the original 1.94.0 version instead of 1.76.1.

Question

How can I correctly override vscode-js-debug to use version 1.76.1?

Overlay is overkill, just override at point-of-use.

You have the right idea almost, problem is overrideAttrs overrides args of stdenv.mkDerivation, not buildNpmPackage (the builder that this package uses). So you have to know the impl details of buildNpmPackage and override accordingly. In this case you must set npmDeps:

(vscode-js-debug.overrideAttrs (
  finalAttrs: prevAttrs: {
    version = "1.76.1";

    src = prevAttrs.src.override {
      rev = "v${finalAttrs.version}";
      hash = "sha256-YGMIzGcjQhz/H6DpxQSOwV6eXVNDXX7mFN56FejDcXo=";
    };

    npmDepsHash = "sha256-lDoj/94tjJd4ZGU9WgrMOqNSmdpeCljU4c6jGX+TSDY=";

    npmDeps = fetchNpmDeps {
      inherit (finalAttrs) src;
      name = "${finalAttrs.pname}-${finalAttrs.version}-npm-deps";
      hash = finalAttrs.npmDepsHash;
    };
  }
))

There are still some new errors to resolve, but I don’t know enough about the hell that is nodejs to advise further.

1 Like

Thank you. This brings me a step closer. As you mentioned, new errors have arisen, but at least it is starting to build.

I assume there are significant differences between these two versions, which is likely why the build step of the derivation needs further modification.

Were you able to resolve this? I’m fighting with something that seems to be exactly the same issue

Resolve what? If you have an issue, create a topic, post your code and the full error.