feature request: execute sudo commands at once instead of separately
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:
- when one of them times out,
nhdoesn't exit and continues to the next one - if someone were to use a different elevation tool, that doesn't support persistence and subshells (like
run0, ordoasin 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:
- if this single
sudotimes out, nothing gets executed andnhexits as well - since it's called only once, it can be used with non-persistent
run0anddoas
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