Built with custom store, every package install fails with error: path is not in the Nix store

I cannot use /nix for various reasons so I built Nix from source using --with-store-dir=/opt/nix/store and --localstatedir=/opt/nix/var.

Although the install succeeded, anything I try to install errors with BadStorePath and NotInStore. The message is error: path ‘[thepath] is not in the Nix store’

You need a bit more than that, see this post for an example.