Apply `replaceDependency` on all packages

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 ?

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.

infinite recursion encountered…

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

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

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

Check out system.replaceRuntimeDependencies:


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

1 Like