Quickly open terminal, sudo, cd /etc/nixos

Every time I want to edit and/or rebuild my nixos configuration, I find myself performing the same sequence of actions:

  • open a terminal
  • run sudo -i
  • enter password
  • run cd /etc/nixos

I was playing around with ways to script this so that I could bind it to a key in my xmonad config, and came up with this little composition:

alacritty -e bash -c 'sudo --login bash -c "cd /etc/nixos ; exec bash"'

Alternative would be making the directory owned and writable by your user.

Or even moving it out of /etc/nixos altogether:

4 Likes

Have you tried sudo -e/sudoedit?

Alternatively move it so some other location that you have easy RW access and then use nixos-config as an entry for NIX_PATH or -I that points to the exact entrypoint file you want to use.