Override npmDepsHash for ui in sunshine package

I’d like to test a patch to sunshine on my current NixOS setup, but given it modifies the projects package-lock.json, I’ve temporarily committed the file into a branch on my fork. However, I can’t seem to override npmDepsHash for the ui derivation nested within the sunshine package:

  services.sunshine = {
    enable = true;
    package = pkgs.sunshine.overrideAttrs (old: {
      src = pkgs.fetchFromGitHub {
        owner = "ruffsl";
        repo = "Sunshine";
        rev = "7f15276cf2e6a7d51db202f362afa520dcb71db7";
        hash = "sha256-dSBsbFJ5gMUNEKcwvkWqpSrv1may/CofdjqQSuszEwI=";
        fetchSubmodules = true;
      };
      ui = old.ui.overrideAttrs (_: {
        npmDepsHash = lib.fakeHash;
        postPatch = "";
      });
    });
  };
ruffsl@box ~/nix-config (main)> time sudo nixos-rebuild test --flake .#box --show-trace
building the system configuration...
error: builder for '/nix/store/pkqvrw25kzv9ygs986hpm2r6jpnpbs29-sunshine-ui-2025.628.4510.drv' failed with exit code 1;
       last 25 log lines:
       > <     "node_modules/yallist": {
       > <       "version": "3.1.1",
       > <       "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
       > <       "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
       > <       "dev": true,
       > <       "license": "ISC"
       > <     },
       > 5840,5842c2463,2465
       > <       "version": "3.25.76",
       > <       "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
       > <       "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
       > ---
       > >       "version": "3.25.67",
       > >       "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.67.tgz",
       > >       "integrity": "sha512-idA2YXwpCdqUSKRCACDE6ItZD9TZzy3OZMtpfLoh6oPR47lipysRrJfjzMqFxQ3uJuUPyUeWe1r9vLH33xO/Qw==",
       >
       > ERROR: npmDepsHash is out of date
       >
       > The package-lock.json in src is not the same as the in /nix/store/gx0mzsiiibli3bqnd295sl20s3sv75g8-sunshine-ui-2025.628.4510-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/pkqvrw25kzv9ygs986hpm2r6jpnpbs29-sunshine-ui-2025.628.4510.drv
error: 1 dependencies of derivation '/nix/store/0z8gqn88pxjawr5phx2axwzscak3wb4q-sunshine-2025.628.4510.drv' failed to build
error: 1 dependencies of derivation '/nix/store/c6yi76fdfv3la5kdb0ss8m0chdy38vmz-ensure-all-wrappers-paths-exist.drv' failed to build
error: 1 dependencies of derivation '/nix/store/q2dzm4gszkrpax4p5b8qvns05dzqzqn3-hwdb.bin.drv' failed to build
error: 1 dependencies of derivation '/nix/store/sjdfjpn124qfr6s5pf1ycsbisbs3xj7v-security-wrapper-sunshine-x86_64-unknown-linux-musl.drv' failed to build
error: 1 dependencies of derivation '/nix/store/x01ijzph56r5088hnh1q5bhgbikgf28q-sunshine-2025.628.4510_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j6l3hzlmc6a7gwdx2r15sxfl833ni7yf-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/v0gkldwh2x2lamwyzsy311y1cqs8wmfi-udev-rules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/2la39wxrg1sqv9m944l0imvrkzw6rdb6-nixos-system-box-25.11.20250921.554be64.drv' failed to build
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '/home/ruffsl/Documents/nix-config#nixosConfigurations."box".config.system.build.toplevel' --show-trace --no-link' returned non-zero exit status 1.

________________________________________________________
Executed in    2.61 secs      fish           external
   usr time    4.57 millis  917.00 micros    3.65 millis
   sys time    5.53 millis  918.00 micros    4.61 millis

I suspect I’m either incorrectly overriding npmDepsHash, or perhaps encountering a similar upstream issue that may have been fixed in nixos-unstable, which my flake is already using (rev 554be64):


For completeness, here is the patch I’m attempting to test with:

You need to override postPatch in the ui attribute.

Isn’t that what line 13 in my snippet should be doing?

Overriding/unsetting the old command that normally copies the lock file from nixpkgs, to instead just reuse the lock file I committed into the root of the sunshine source tree? Or is the working director of said postPatch command not allready the root of the sunshine source tree checkout?

I should’ve been more specific - the fact that the package-lock.json is being overridden in the original nix expression indicates the upstream lockfile is likely broken (which is not uncommon for some js projects).
So you would likely need to delete and regenerate the lockfile yourself in a clone of the upstream repo (or you can copy src to a writeable dir), and then override the postPatch to use that generated lockfile.
I don’t think an empty postPatch is the correct move here (though I’m not at the pc to test it in more detail in any case…)

Don’t know if it was ever broken, but is now missing from the HEAD of master branch upstream.

Done. I’ve generated and updated lockfile as permalinked from my downstream fork above.

So PWD for postPatch is not src checkout?
Anyway, cp from the src override still fails to suggest the correct npmDepsHash:

{ pkgs, lib, ... }:
let
  mySrc = pkgs.fetchFromGitHub {
    owner = "ruffsl";
    repo = "Sunshine";
    rev = "7f15276cf2e6a7d51db202f362afa520dcb71db7";
    hash = "sha256-dSBsbFJ5gMUNEKcwvkWqpSrv1may/CofdjqQSuszEwI=";
    fetchSubmodules = true;
  };
in
{
  services.sunshine = {
    enable = true;
    autoStart = true;
    capSysAdmin = true;
    openFirewall = true;
    package = pkgs.sunshine.overrideAttrs (old: {
      src = mySrc;
      ui = old.ui.overrideAttrs (_: {
        npmDepsHash = lib.fakeHash;
        postPatch = ''
          cp ${mySrc}/package-lock.json ./package-lock.json
        '';
      });
    });
  };
}
ruffsl@box ~/nix-config (main)> time sudo nixos-rebuild test --flake .#box
building the system configuration...
error: builder for '/nix/store/ba0rx4vxnw9z2lawgk6d7chmk49y4isz-sunshine-ui-2025.628.4510.drv' failed with exit code 1;
       last 25 log lines:
       > <     "node_modules/yallist": {
       > <       "version": "3.1.1",
       > <       "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
       > <       "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
       > <       "dev": true,
       > <       "license": "ISC"
       > <     },
       > 5840,5842c2463,2465
       > <       "version": "3.25.76",
       > <       "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
       > <       "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==",
       > ---
       > >       "version": "3.25.67",
       > >       "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.67.tgz",
       > >       "integrity": "sha512-idA2YXwpCdqUSKRCACDE6ItZD9TZzy3OZMtpfLoh6oPR47lipysRrJfjzMqFxQ3uJuUPyUeWe1r9vLH33xO/Qw==",
       >
       > ERROR: npmDepsHash is out of date
       >
       > The package-lock.json in src is not the same as the in /nix/store/gx0mzsiiibli3bqnd295sl20s3sv75g8-sunshine-ui-2025.628.4510-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/ba0rx4vxnw9z2lawgk6d7chmk49y4isz-sunshine-ui-2025.628.4510.drv
error: 1 dependencies of derivation '/nix/store/akzfh20nnmrqfd6ph6si02lcqs44aj7x-sunshine-2025.628.4510.drv' failed to build
error: 1 dependencies of derivation '/nix/store/06f6mv4dda77jl77fhp2d8y1dfypgj31-ensure-all-wrappers-paths-exist.drv' failed to build
error: 1 dependencies of derivation '/nix/store/fi68w7z8k0r83kjrmf5fh8cl9wyn4aia-hwdb.bin.drv' failed to build
error: 1 dependencies of derivation '/nix/store/fapqp8xp8yp9v1565sccbvnkchncdn0i-security-wrapper-sunshine-x86_64-unknown-linux-musl.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ff469xjyrmvw35d8nx7scrvj7zis6d2g-sunshine-2025.628.4510_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/r6wqx9g6na5h7rxi4ljsw45q2qi736hv-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/2y2941q9irasqmbwrnch89kvzyyd0xaf-udev-rules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/zya1n7qhyz5q5w7g3740d1cgdpdydmd1-nixos-system-box-25.11.20250921.554be64.drv' failed to build
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '/home/ruffsl/Documents/nix-config#nixosConfigurations."box".config.system.build.toplevel' --no-link' returned non-zero exit status 1.

________________________________________________________
Executed in    2.63 secs      fish           external
   usr time    8.36 millis    6.16 millis    2.21 millis
   sys time    8.42 millis    3.14 millis    5.28 millis

Inspecting the store path derived from the “overriden” npmDepsHash still seems to contain the same package-lock.json file from the nixpkgs repo, rather than the one from my downstream fork:

   > The package-lock.json in src is not the same as the in /nix/store/gx0mzsiiibli3bqnd295sl20s3sv75g8-sunshine-ui-2025.628.4510-npm-deps.
ruffsl@box ~> sha256sum /nix/store/gx0mzsiiibli3bqnd295sl20s3sv75g8-sunshine-ui-2025.628.4510-npm-deps/package-lock.json
1a7e8143395e8a2a28cb3d29d04d31320de8de18f7f7e1cee964f732234318b8  /nix/store/gx0mzsiiibli3bqnd295sl20s3sv75g8-sunshine-ui-2025.628.4510-npm-deps/package-lock.json
ruffsl@box ~> , wget -qO- https://github.com/NixOS/nixpkgs/raw/554be6495561ff07b6c724047bdd7e0716aa7b46/pkgs/by-name/su/sunshine/package-lock.json | sha256sum
1a7e8143395e8a2a28cb3d29d04d31320de8de18f7f7e1cee964f732234318b8  -
ruffsl@box ~> , wget -qO- https://github.com/ruffsl/Sunshine/raw/7f15276cf2e6a7d51db202f362afa520dcb71db7/package-lock.json | sha256sum
d18799d7e9a7e8315d80b54be7668f3dac37f1e91d8e21e8fe8e421049fc438b  -

So I don’t think the syntax for my override of npmDepsHash is working as expected here…

Try to generate the lockfile yourself, this is still the upstream lockfile. Okay I missed that it’s a fork. I’ll try it out myself.

1 Like

I did generate an updated package-lock.json, and committed it onto of my downstream fork of sunshine, in an effort to avoid having to fork the nixpks as well using an override approach.


One thing I just realized what the src is being inherited into buildNpmPackage, so I also tried:

      ui = old.ui.overrideAttrs (_: {
+        src = mySrc;
        npmDepsHash = lib.fakeHash;
        postPatch = "";
      });

But still no luck, as the expected store path for *-npm-deps remains unchanged by the override.

1 Like

Apparently I already looked into this before :slight_smile: you may need to override npmDeps as well. I’m not sure if this applies with the finalAttrs pattern though. If it does, I’d file that as a bug with nixpkgs. EDIT: the buildNpmPackage is not using the finalAttrs pattern (not sure if it’s even supported), so you’ll still have to override npmDeps for sure.

1 Like

Ah, I linked to that thread above in the top OP, but didn’t comprehend where/how final. came into scope, so wasn’t sure how to apply that syntax. Overriding the value of npmDeps via return of a custom call to pkgs.fetchNpmDeps provided an expected build error that included the proper hash!

  services.sunshine = {
    enable = true;
    package = pkgs.sunshine.overrideAttrs (old: rec {
      src = pkgs.fetchFromGitHub {
        owner = "ruffsl";
        repo = "Sunshine";
        rev = "7f15276cf2e6a7d51db202f362afa520dcb71db7";
        hash = "sha256-dSBsbFJ5gMUNEKcwvkWqpSrv1may/CofdjqQSuszEwI=";
        fetchSubmodules = true;
      };
      ui = old.ui.overrideAttrs (_: rec {
        inherit src;
        npmDepsHash = lib.fakeHash;
        postPatch = "";
        npmDeps = pkgs.fetchNpmDeps {
          inherit src;
          hash = npmDepsHash;
        };
      });
    });
  };
ruffsl@box ~/D/nix-config (main)> time sudo nixos-rebuild test --flake .#box
building the system configuration...
error: hash mismatch in fixed-output derivation '/nix/store/vr390blvhwxgi0v8nxar7p57k3h73a3f-npm-deps.drv':
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-EvJXkE9vPMSHitPc5EbWFqUlnDwZQ9XPDaqH0CXyQjk=
error: 1 dependencies of derivation '/nix/store/0c145m3iqf4bjl5a00043yr75879a9sj-sunshine-ui-2025.628.4510.drv' failed to build
error: 1 dependencies of derivation '/nix/store/s8q27h3wy3d37pw1rjvf02jqpqmwwp20-sunshine-2025.628.4510.drv' failed to build
error: 1 dependencies of derivation '/nix/store/br9ynb54pj8hzp6rgnvhdmdjyag9jsp1-ensure-all-wrappers-paths-exist.drv' failed to build
error: 1 dependencies of derivation '/nix/store/4knmp5l5sqmjm166s33nj05yps3318fw-hwdb.bin.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6yywxq3zj3j5ych4bb5nh7xliakcaa6j-security-wrapper-sunshine-x86_64-unknown-linux-musl.drv' failed to build
error: 1 dependencies of derivation '/nix/store/8hqyb2b33jg5fra7pjf10arfmzybz79v-sunshine-2025.628.4510_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cfid3qj7vcpsjcwqsz2d3hfxwir3z1sa-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/dfygk5firmry4x2qhh1gbn5y4nvzbm5c-udev-rules.drv' failed to build
error: 1 dependencies of derivation '/nix/store/w47ld5ah0rjnsial8vacrndnarv1zshn-nixos-system-box-25.11.20250921.554be64.drv' failed to build
Command 'nix --extra-experimental-features 'nix-command flakes' build --print-out-paths '/home/ruffsl/Documents/nix-config#nixosConfigurations."box".config.system.build.toplevel' --no-link' returned non-zero exit status 1.

________________________________________________________
Executed in   16.85 secs      fish           external
   usr time   25.31 millis    0.00 millis   25.31 millis
   sys time   20.15 millis    1.90 millis   18.25 millis

As an aside, I attempted the same overrideAttrs pattern for npmDeps, but don’t understand why it doesn’t work as compared to prior snippet above:

         hash = "sha256-dSBsbFJ5gMUNEKcwvkWqpSrv1may/CofdjqQSuszEwI=";
         fetchSubmodules = true;
       };
-      ui = old.ui.overrideAttrs (_: rec {
+      ui = old.ui.overrideAttrs (old: rec {
         inherit src;
-        npmDepsHash = lib.fakeHash;
+        npmDepsHash = "sha256-EvJXkE9vPMSHitPc5EbWFqUlnDwZQ9XPDaqH0CXyQjk=";
         postPatch = "";
-        npmDeps = pkgs.fetchNpmDeps {
+        npmDeps = old.npmDeps.overrideAttrs (old: rec {
           inherit src;
           hash = npmDepsHash;
-        };
+        });
       });
     });
   };

Because at the end of the day overrideAttrs is overriding the attributes of mkDerivation.
fetchNpmDeps. Which means the implementation details of how fetchNpmDeps calls mkDerivation are in fact relevant (especially since that also doesn’t support the finalAttrs pattern).

In this case it’s a FOD, so if you’re overriding anything, it’d have to be outputHash, not hash (or if you still want to use hash, you override the function args, i.e. use .override). src appears to be passed through to the underlying mkDerivation and would likely work with .overrideAttrs or .override in this case.

TLDR if you use npmDeps = old.npmDeps.override { ... }, it’d likely work.

1 Like

I gave that a quick try, but I guess old.npmDeps is a “plain derivation”(?) or a fixed-output derivation (FOD?) that does not expose .override?

       error: attribute 'override' missing
       at /nix/store/nmf9mjc8fxcgmk420wrmqb0rl1d3rq13-source/modules/nixos/streaming.nix:37:19:
           36|         postPatch = "";
           37|         npmDeps = old.npmDeps.override {
             |                   ^
           38|           inherit src;

Thanks for all the help @waffle8946 , appreciate teaching a fellow how to fish! :fishing_pole_and_fish:

Let me know if you’d recommend any good learning resources on these topics. I just re-read the nix manual for these functions, but still a little vague on mkDerivation.