Apply `replaceDependency` on all packages


#1

Context: I use macbookpro and the libinput should be patched to let palm injection, etc, to work. So I have this in my configuration:

  nixpkgs.overlays = [
    (self: super: {
      libinput = super.libinput.overrideAttrs (attrs: {
        patches = (attrs.patches or []) ++ [ ./Patches/udev-Add-Apple-SPI-Keyboard-and-Touchpad.patch ];
        }
      );
    })
  ];

But there are so much packages depend on libinput, every time I want to update my system I have to rebuild the world, which takes tons of time. Recently I found replaceDependency which may solve my problem, but it patches single derivation.

So my question is: is there a way to apply replaceDependency on all packages introduced by the system configuration? Or can I apply it on the final system derivation when I run nixos-rebuild ?


#2

You can try something like (untested)

nixpkgs.overlays = [
  (self: super: super.lib.mapAttrs (_: v:
    if super.lib.isDerivation v
    then super.replaceDependency {
      drv = v;
      oldDependency = super.libinput;
      newDependency = super.libinput.overrideAttrs (attrs: {
        patches = (attrs.patches or []) ++ [ ./Patches/udev-Add-Apple-SPI-Keyboard-and-Touchpad.patch ];
      });
    }
    else v
  ) super)
];

You should likely turn on store optimization after having done that, in
order for your store not to double in size.


#3

infinite recursion encountered…


#4

So I need to avoid apply on dependencies of libinput, seem not practical…


#5

Is there any reason not to just upstream the necessary patch?


#6

But it’s still painful if sometimes I want to test various patches.


#7

Check out system.replaceRuntimeDependencies: https://github.com/NixOS/nixpkgs/blob/1b769de74c5b7c4708e1a4aa8f46beca58ace5d8/nixos/modules/system/activation/top-level.nix#L237


#8

:nix_parrot: Aha, that’s it, thanks!