How to override a library without recompile its dependency

I want to use freetype2-macos instead of freetype2 in the nixpkgs to improve the rendering of the system. However, if I use pkgs.freetype.override to patch my freetype, all its dependencies will need to be recompiled, which is basically the whole system. This is not feasible. Any idea how to achieve this? Thank you.

This is not trivially possible. The fact that any modification in the dependency tree produces an entirely different result is quite fundamental to how Nix works.

There are some hacks like replaceRuntimeDependencies but they are indeed just hacks.

replaceRuntimeDependencies looks promising! What is the drawback of doing such hack?

It’s impure and fundamentally is an “incorrect deployment”.
Practically this means anything linked against the older lib may break when doing this, if the library versions are ABI incompatible.

1 Like

This is not a concern to me since I know what I patched, and I know the ABI is exactly the same. I think I can also make the new package “auto-upgrade” with the official nixpkgs to avoid linking against the older lib.