npmDepsHash override, what am I missing please

Hi again :slight_smile:

I am trying to override a package version with the following snippet, and have added lib.fakeHash as the initial error kindly suggested.

Unfortunately it seems to loop with the same error and the suggested fix does not appear to work.

Am I missing something? (apart from npm deps being a challenge already :))

  modifications = final: prev: {
    netbird-dashboard = prev.netbird-dashboard.overrideAttrs (_old: rec {
      pname = "netbird-dashboard";
      version = "2.5.0";
      src = prev.fetchFromGitHub {
        owner = "netbirdio";
        repo = "dashboard";
        rev = "v${version}";
        hash = "sha256-PissALQ/3gARnm2hiURABFqF2OKkFITMKf2Rww56hEM=";
      };
      npmDepsHash = lib.fakeHash;
    });
};
error: builder for '/nix/store/x9h0n8k0gg6cl9p0xlk5b7n8c3jch00l-netbird-dashboard-2.5.0.drv' failed with exit code 1;
       last 25 log lines:
       > >       }
       > >     },
       > 6679,6690d6346
       > <       }
       > <     },
       > <     "node_modules/react-virtuoso": {
       > <       "version": "4.10.0",
       > <       "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-4.10.0.tgz",
       > <       "integrity": "sha512-CyxU5TYMH4bw2cybH0bNqN/yIg2q2Vd0kbs92tQc5ResZALAIzIVJY4JL6BHgJFQjwrLhCYrFwKq0p+lvBgA0w==",
       > <       "engines": {
       > <         "node": ">=10"
       > <       },
       > <       "peerDependencies": {
       > <         "react": ">=16 || >=17 || >= 18",
       > <         "react-dom": ">=16 || >=17 || >= 18"
       >
       > ERROR: npmDepsHash is out of date
       >
       > The package-lock.json in src is not the same as the in /nix/store/sqrf7y8p3q75d1gp2c3m0qr48h6r9fr8-netbird-dashboard-2.3.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
       >
       For full logs, run 'nix log /nix/store/x9h0n8k0gg6cl9p0xlk5b7n8c3jch00l-netbird-dashboard-2.5.0.drv'.
ERROR: npmDepsHash is out of date

The package-lock.json in src is not the same as the in /nix/store/sqrf7y8p3q75d1gp2c3m0qr48h6r9fr8-netbird-dashboard-2.3.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

Clear out this hash. Use an empty string as the value. And then when that fails, you copy-paste the “got” one into the literal value.

Hey thanks

That fetchFromGitHub is correct from already doing exactly what you describe.

Without that it will not progress to the npmDepsHash at all.

You can’t override npmDepsHash that way, overrideAttrs only applies to args of mkDerivation, not the args of other builders.

    netbird-dashboard = prev.netbird-dashboard.overrideAttrs (_old: rec {
      pname = "netbird-dashboard";
      version = "2.5.0";
      src = final.fetchFromGitHub {
        owner = "netbirdio";
        repo = "dashboard";
        rev = "v${version}";
        hash = "sha256-PissALQ/3gARnm2hiURABFqF2OKkFITMKf2Rww56hEM=";
      };
      npmDepsHash = "";
      npmDeps = final.fetchNpmDeps {
        inherit src;
        name = "${pname}-${version}-npm-deps";
        hash = npmDepsHash;
      };
    });

Build that and get your hash.

Couple other points:

  • You seem to be writing an overlay, always prefer final over prev unless it’s unavoidable to use prev (due to infrec)
  • Avoid overlays, if you can, just use the override in-place for leaf packages
  • If the following attrs were defined in the original expression, you’d also want to put inherit (_old) forceGitDeps forceEmptyCache sourceRoot prePatch patches postPatch; in the fetchNpmDeps call (though in this case, none of them are defined, I think.)
2 Likes

I see, I didn’t realise that overrideAttrs only applies to args of mkDerivation, thanks for the info.

Apologies, I had missed out the modifications = final: prev: { … } surrounding the code snippet.

Not entirely sure what ‘override in-place for leaf packages’ means but will look further on that.

Your last bullet it seems not as the derivation is building now fine and the hash was given no problem.

Thanks for your time :slight_smile:

If you have (for example):

  pkgs.whatever

in a package list (environment.systemPackages, home.packages, a packages list for a mkShell derivation, etc.), and you want to change whatever, you don’t need an overlay, simply

(pkgs.whatever.overrideAttrs { ... }) will do (replacing ... as applicable).

The override and overrideAttrs functions themselves return a package, was my point, and overlays are slower to eval (and possibly harder to debug) in general than simple overrides.

Overlays are moreso meant for replacing every instance of a package within an overall nixpkgs instance; this is most useful for updating libraries that are dependencies of other packages, but will naturally result in a mass rebuild for the dep itself and all the packages that depend on it. They’re also sometimes used when a NixOS module doesn’t provide a .package option to override the package directly.

1 Like

Okay, yes I understand now, thank you for taking the time to explain further, much appreciated.