Set path for flake.nix file?

I switched to flakes, and now my config files, including flake.nix, live in
~/nixos-config
I understand that to rebuild, the proper command would be

sudo nixos-rebuild switch --flake .

But it is not finding the flake.nix file, because it says

path '/home/shmuel' does not contain a 'flake.nix', searching up
error: could not find a flake.nix file

It does not seem to be looking up the correct path.

Hey @shmu26 ,

I think you have 2 options.

  1. Run your sudo nixos-rebuild command inside your new flake directory (~/nixos-config): cd ~/nixos-config && sudo nixos-rebuild switch --flake .
  2. Specify the flake directory with the --flake parameter: sudo nixos-rebuild switch --flake ~/nixos-config

KR

2 Additions (for myself ;)):

  1. @1. “cd ~/nixos-config && sudo nixos-rebuild switch” works the same
  2. @2.
    1. nixos-rebuild switch --use-remote-sudo --flake ~/nixos-config” should do the same (without calling nix with sudo)
    2. sudo nixos-rebuild switch --flake ~/nixos-config/” (mention the trailing slash /), if ~/nixos-config is a symlink