nix-community / nixvim

Configure Neovim with Nix! [maintainers=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.82k stars 286 forks source link

[BUG] Sudoedit Won't Use The Right Executable #2319

Closed hftsai256 closed 2 months ago

hftsai256 commented 2 months ago
Field Description
Plugin N/A
Nixpkgs unstable
Home Manager unstable

Description

By default settings in /etc/sudoers, the PATH is secured and will not pick up the one in ~/.nix-profile/bin; therefore, all the plugins cannot be loaded properly as the wrapping configurations are missing.

Minimal, Reproducible Example (MRE)

Run the sudoedit command with programs.nixvim.defaultEditor=true set in home-manager:

$ sudoedit /etc/sudoers
sudoedit: nvim: command not found
$ echo $EDITOR
nvim

I think this is working as expected referring to: https://github.com/nix-community/nixvim/blob/7bda0f1ce49e9da252bcee20b5f700e6dcd3cf8d/wrappers/hm.nix#L62

However, this wouldn't work because the PATH is restricted in /etc/sudoers. An easy workaround is to export (override) the EDITOR variable:

$ EDITOR=$(which nvim) sudoedit <file>

I may also override it in my zsh config:

programs.zsh.initExtra = ''
  export EDITOR=$(which nvim)
''

but I think this defeats the purpose of setting the nixvim.defaultEditor attribute.

Or I would have to edit /etc/sudoers to modify secure_path, which I don't think is a good idea.

BTW the neovim module from home-manager has the same issue. What is the best practice to handle this use case?

MattSturgeon commented 2 months ago

If using an absolute file path is all that's needed then we can do that fairly easily using lib.getExe.

I believe our defaultEditor implementation is the same as home-manager's though, so this issue likely isn't exclusive to nixvim.

We'd need to consider if there's any downsides to using an absolute path. I know there's been a push in nixpkgs for desktop entries to rely on PATH, for instance, but maybe that's for unrelated reasons. (https://github.com/NixOS/nixpkgs/issues/308324)

hftsai256 commented 2 months ago

Thanks for the insight. I remember sudoedit used to work flawlessly about a year ago with home-manager. Things started falling apart months ago but I didn't know there was such a push.

I have a discord thread on this issue but it attracts almost no attention. Maybe I'll override the EDITOR variable in zsh for now.