How to add a symlink to `/usr/local/opt` post-install

I’m on Darwin, and the relevant parts of my Nix setup are nix-dotfiles/darwin-configuration.nix at 72e4884436c80dab81ccf43b698f8150290fb09b · Smaug123/nix-dotfiles · GitHub lines 3 and 25, and nix-dotfiles/config.nix at 72e4884436c80dab81ccf43b698f8150290fb09b · Smaug123/nix-dotfiles · GitHub .

The problem I am having is that Lean (as installed via elan, which is itself installed by Nix) dynamically loads /usr/local/opt/gmp/lib/libgmp.10.dylib. I’ve used Nix to install gmp, but of course it doesn’t put that symlink there.

How do I amend the gmp install process to put a symlink in /usr/local/opt? I’ve tried the following (which is the contents of the config.nix file I link above):

{
  packageOverrides = pkgs: {
    gmp = pkgs.gmp.override { postInstall = ''
      echo hello
      ln -s /usr/local/opt/gmp/lib/libgmp.10.dylib $out/lib/libgmp.10.dylib
      '';
    };
  };
}

But as far as I can tell, this does nothing at all; hello is not printed, and the symlink is not created.

Nix-darwin does have environment.etc, but that only lets you put things in /etc; I tried with "../usr/local/opt" and the environment.etc again appeared to do nothing.

Pretty basic, but this did the job: Fix up gmp · Smaug123/nix-dotfiles@e25e363 · GitHub

pkgs.runCommandLocal "gmp-symlink" {} ''
dest="/usr/local/opt/gmp/lib/libgmp.10.dylib"
existing=$(readlink "$dest")
if [ $? -eq 1 ]; then
  ln -s ${pkgs.gmp}/lib/libgmp.10.dylib "$dest" && mkdir -p $out && touch $out/done.txt
else
  if [[ "$existing" == /nix/store/* ]]; then
    ln -fs ${pkgs.gmp}/lib/libgmp.10.dylib "$dest" && mkdir -p $out && touch $out/done.txt
  else
    echo "Existing symlink is $existing, refusing to overwrite"
    exit 1
  fi
fi
''