nh icon indicating copy to clipboard operation
nh copied to clipboard

feature request: execute sudo commands at once instead of separately

Open acid-bong opened this issue 10 months ago • 1 comments

Related to #221 (but i'm still not proficient enough in Rust to write a PR).

Current state: sudo switch-to-configuration test, sudo nix-env ... and sudo switch-to-configuration boot are executed each with a separate sudo invocation: https://github.com/nix-community/nh/blob/9e9a4590b38b62b28f07a1fae973ce7b6ca0687a/src/nixos.rs#L129-L160

Problems:

  1. when one of them times out, nh doesn't exit and continues to the next one
  2. if someone were to use a different elevation tool, that doesn't support persistence and subshells (like run0, or doas in default configuration), this would ask for a password as many times as there are elevations

Proposal: generate commands as strings and concat them together, preferably with &&, and pass the generated concat to a single sudo invocation like this:

$ sudo sh -c ${generated stuff}

This is supposed to solve the abovementioned problems:

  1. if this single sudo times out, nothing gets executed and nh exits as well
  2. since it's called only once, it can be used with non-persistent run0 and doas

acid-bong avatar Apr 22 '25 16:04 acid-bong

If we are generating a bash script to pass to sudo sh, might as well rewrite nh in bash...

I think there might be a better way to do this, like having an elevated nh that listens for commands from the interactive nh. But I haven't looked at this at all.

Related #203

viperML avatar Apr 22 '25 17:04 viperML