I wonder if I can automate it with smth like:
postInstall = ''
ln -s current.derivation.hash /nix/var/nix/gcroots/bar
''
However I assume it is impossible to get the hash since correct hash requires a successful build with the correct hash.
Nope: Heresy here.
An easier alternative is direnv. Store paths are symlinked to .direnv. Which prevents flakes from gc.