How to override a package's input in configuration.nix?

For instance, I want yarn package to use pkgs.nodejs-10_x instead of pkgs.nodejs (currently point to 8.x).
In yarn’s source code, I see buildInputs = [ nodejs ];
so I have the following in my configuration.nix:

let
my-yarn = pkgs.yarn.override {nodejs=pkgs.nodejs-10_x;};
in
{
environment.systemPackages = [my-yarn ...];
}

but it doesn’t work. Did I misunderstand anything?

1 Like

Have you find a fix? I have been trying this:

      (pkgs.yarn.override {
        nodejs = nodejs_16;
        # nodejs = nodejs-18_x;
      })

Oh wait, I fixed it. I forgot that I had a security wrapper:

  security.wrappers = {
    # ...
    yarn = {
      owner = "root";
      group = "root";
      capabilities = "cap_net_bind_service=+ep";
      source = "${(pkgs.yarn.override {
        nodejs = pkgs.nodejs_16;
        # nodejs = nodejs-18_x;
      }).out}/bin/yarn";
    };
    # ...
  };