Does my Nixos flake NEED to go in /etc/nixos? Same question for home-manager in ~/.config/home-manger

Can I simply nixos-rebuild switch --flake .#etc.etc from within an arbitrary directory without ANY system issues? For example, if there was a default /etc/nixos/configuration.nix while nixos-rebuildinging from a different directory or even just rebuilding from a flake referenced from github.

Would Nix mess up on reboot because of a different /etc/nixos?
I don’t need to clear out /etc/nixos and hard link it to my arbitrary flake directory?

Functionally same questions for home-manager with a default ~/.config/home-manager/home.nix.

I wasn’t able to find this in any other posts unless I’m simply wording the question incorrectly.

You should have no trouble keeping your configuration somewhere else you choose :slight_smile:
I’ve had my configuration flake (which includes home-manager as well) in another location for over a year, and the configuration files in /etc/nixos haven’t changed or messed anything up since then.

If you configure system.autoUpgrade wrong it could decide to “update” you to an old config from /etc/nixos. Or you could accidentally forget the --flake arg while rebuilding manually. Those are the only ways I can think of this causing issues.

In either case, bringing up your boot loader and booting the previous generation will instantly fix a mistake like that.

I’d still personally just back up my /etc/nixos and then delete any flake.nix or configuration.nix in that directory if it’s not being used anyway, at best it wastes disk space.

Thank you for your response :pray:

Thank you I can use this :pray: