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"'

https://github.com/ivanbrennan/nixbox/commit/1e3e0b4337d03b310507de5d7d7b9f8b5fd6ccbf

2 Likes

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

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

5 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.

env -C can also be used to set up an initial working directory for a program, e.g. sudo -i env -C /etc/nixos bash.

1 Like