Closed becknik closed 10 months ago
That's how sudo works, it doesn't preserve envvars unless told to.
The behaviour you see is also consistent with the manpages, see https://www.mankier.com/1/systemctl#Environment-%24SYSTEMD_EDITOR:
If neither $SYSTEMD_EDITOR nor $EDITOR nor $VISUAL are present or if it is set to an empty string or if their execution failed, systemctl will try to execute well known editors in this order: editor(1), nano(1), vim(1), vi(1).
Okay then, thanks for your (fast) answer. I'm not that familiar with sudo.
This StackExchange answer to a user with the same question has a solution. Can't we just append Defaults:root,%wheel env_keep += "EDITOR"
to /etc/sudoers
to enable the pass-through of the default editor?
I (as a fairly new NixOS/ Linux user) think this is something the configuration should take care of implicitly when setting a default editor. It should include cases where sudo is a prepended - it's just more convenient and surely won't break anything to expose this one domain-specific environment variable. Seems like there similar cases with the following:
$ sudo cat /etc/sudoers
# ...
# Keep terminfo database for root and %wheel.
Defaults:root,%wheel env_keep+=TERMINFO_DIRS
Defaults:root,%wheel env_keep+=TERMINFO
What do you think?
This is definitely not something that should be done by default. Even opting in is somewhat questionable IMO, as just about anything can set envvars...
Okay, then I'll close this issue. Thanks again
Describe the bug
When trying to use the
sudo systemctl edit --runtime <nixos-upgrade>.service
the default editor (Neovim/nvim
in my case) set inconfiguration.nix
and theEDITOR
environment variable (alsonvim
) is ignored. This seems to only apply to the systemsystemd edit
command, the user-space withoutsudo
detects the default editor. However, my user-space uses home-manger & nixvim to manage my Neovim setup, so I don't think it's representative enough to be seen as reference...When using
sudo -E systemctl edit --runtime nixos-upgrade.service
however, my default editor is recognized correctly. This also applies when usingsudo -s
, and thensystemctl edit --runtime nixos-upgrade.service
.Steps To Reproduce
Steps to reproduce the behavior:
configurations.nix
:sudo systemctl edit --runtime nixos-upgrade.service
Expected behavior
The systemd service editor shows up in my nvim environemnt
Additional context
Home-managed shell config (pretty messy, sorry):
Notify maintainers
Systemd: @flokli @kloenk sudo: @delroth
Metadata
Add a :+1: reaction to issues you find important.