Is there a way to use replaceRuntimeDependencies in Home Manager?

After using NixOS sporadically for infrastructure, I’m leaping head-first into using it on my desktop!

I’d like to use a small internal patch I have for a library that is rather unlikely ever to be upstreamed, and I don’t want to constantly recompile everything that depends on that library. Perfect case for system.replaceRuntimeDependencies, as I understand it… except I’m on a desktop now, and learning to use Home Manager for the software I frequently tinker with. The library I want to patch isn’t used at all by any of the packages I’ve installed via /etc/nixos/configuration.nix, so when I rebuild the system I’m told that my system derivation doesn’t depend on the patched package, and nothing seems to happen with any downstream applications. Is there an equivalent option for Home Manager? Or another recommended approach for impurely patching Home Manager-managed packages?

Thanks!

If you just want the patched library for a single service, then you could just make an overlay which patches the library, names it something new. Then override the program to use the new patched library.

Most services usually expose an package option (if it doesn’t then, I would send in a PR to add it).

Example

nix.overlays = [
  (prev: final:
    myPatchedLib = myLib.overrideAttrs (oldAttrs: rec {
        patches = (oldAttrs.patches or []) ++ [
          (fetchurl { ... })
        ];
      });

    myPatchedProgram = myProgram.override {
      myLib = final.myPatchedLib;
    };
  )];

service.myService.package = pkgs.myPatchedProgram;

That’s a good tip, but unfortunately I’m patching a GUI library, and I want all the GUI applications that depend on it to use the patched library.

Either do something like above and selectively do the gui applications that you care about.

Or just do:

nix.overlays = [
  (prev: final:
    myLib = myLib.overrideAttrs (oldAttrs: rec {
        patches = (oldAttrs.patches or []) ++ [
          (fetchurl { ... })
        ];
      });
  )];

And wait forever for it to build everything : /

AFAIK, there’s no way to tell nix which it should or shouldn’t care about.

Thanks, appreciate the response. If that’s the best I can do, so be it. But the system.replaceRuntimeDependencies option is better than that if I’m configuring everything globally. I’m not yet familiar enough with how the global NixOS configuration and the Home Manager configuration interact to know if there’s a reason why an equivalent option couldn’t exist for Home Manager, but it sure would be nice. Otherwise, I might just go back to managing everything as root, rather than effectively living in a source-only Linux distribution.

No, HM doesn’t really have any particularly convenient way to perform the equivalent of system.replaceRuntimeDependencies. In principle it shouldn’t be particularly difficult to add this functionality. I imagine it would be very similar to how it is done in NixOS but instead of modifying baseSystem it would modify activationPackage.

I won’t have time to work on this myself but welcome any contribution. One thing to keep in mind is that I at some point in the future would like to place the HM generation inside the NixOS generation when used as a NixOS module. Right now HM will generate it’s own profile links even when used as a NixOS module and I think that is somewhat unclean. My first impressions is that this should play nicely with a hypothetical home.replaceRuntimeDependencies but it may be good to think over it more carefully.

1 Like