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"'
committed 02:52PM - 24 Apr 21 UTC
Provide a keybinding to open a terminal, switch to the superuser, and cd
to /etc… /nixos. I commonly run this sequence of actions in order to edit
my nixos config.
2 Likes
Alternative would be making the directory owned and writable by your user.
Or even moving it out of /etc/nixos
altogether:
I cloned my config repo into Projects directory in my home directory and have been running nixos-rebuild switch -I nixpkgs=$HOME/Projects/nixpkgs -I nixos-config=$HOME/Projects/nixfiles/hosts/$(hostname)/configuration.nix.¹
I do not even have /etc/nixos on my computer, and the nixfiles directory is completely anonymous – I can move it anywhere and, since I actually use relative paths in the rebuild command, I will not even have to change anything.
Some other tools like nixos-option might requi…
5 Likes
NobbZ
April 26, 2021, 7:20am
3
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