[Plex] Overwriting mpv library used in lib directory

I’m trying to patch the plex-desktop package to use a newer version of the mpv library libmpv, but I’m failing to create an overlay correctly. The updated mpv library is necessary in order to use Ashyni’s dynamic-crop script that auto-crops black bars in movies.

What I want is for the /nix/store/...-plex-desktop-1.101.0/lib/libmpv.so.2 file to be replaced with the one from /nix/store/...-mpv-with-scripts-0.39.0/lib/libmpv.so.2.

So far, I’ve tried creating an overlay and using it like this:

{
  pkgs,
  lib,
  config,
  ...
}: let
  patchedMpvPlex = pkgs.plex-desktop.overrideAttrs (previousAttrs: {
    postInstall = ''
      ${previousAttrs.postInstall or ""}

      # Remove built-in libmvp (save backup of it),
      # then symlink to updated libmpv
      ln --backup --force --symbolic --target-directory=${pkgs.plex-desktop}/lib ${pkgs.mpv}/lib/libmvp.so.2
    '';
  });
in {
  options = {
    plex-desktop.enable = lib.mkEnableOption "Enables Plex Desktop";
  };

  config = lib.mkIf config.plex-desktop.enable {
    home.packages = [
      patchedMpvPlex
    ];

    xdg.dataFile."plex/mpv.conf".text = ''
      vf=help

      # For HDR content
      vo=gpu-next
      target-colorspace-hint

      gpu-api=d3d11
      gpu-context=wayland

      # Required for the dynamic-crop script
      hwdec=no
    '';

    # Script that auto-crops black bars.
    xdg.dataFile."plex/scripts/dynamic-crop.lua".source = ./dynamic-crop.lua;
  };
}

but, judging from the plex logs, it doesn’t appear to do anything. I also tried putting gibberish inside the postInstall string and I got no error, which makes me wonder whether it’s even running at all.

I’m new to Nix/NixOS so I may very well be misunderstanding how this works.


System info:
Nix Flake on github:nixos/nixpkgs/nixos-24.11

❯ nixos-version                                                                                                                               
24.11.20250219.36864ed (Vicuna)