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’
I encounted the same problem, both nix-env and flake don’t work after building nix with custom store path. I have changed the path of nix store, but nix still refer to /nix/store while evaluating nix-expr.
The blog in @rohit post is confusing and not helpful for me.It only list lots of steps but doesn’t explain why I need to them, such as patching the souce code and adding a configuration file in ~/.config/nix/nixpkgs
Generally running nix with different store path than /nix/store is quite difficult, as all the paths encoded in binaries etc… refer to there. You basically won’t ever hit the binary cache and have to rebuild everything. https://github.com/NixOS/nix/issues/1971