-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathmain.rs
More file actions
59 lines (48 loc) · 1.36 KB
/
main.rs
File metadata and controls
59 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
mod check;
mod clean;
mod commands;
mod completion;
mod darwin;
mod generations;
mod home;
mod installable;
mod interface;
mod json;
mod logging;
mod nixos;
mod search;
mod update;
mod util;
use color_eyre::Result;
use tracing::debug;
const NH_VERSION: &str = env!("CARGO_PKG_VERSION");
const NH_REV: Option<&str> = option_env!("NH_REV");
fn main() -> Result<()> {
let do_warn = check::setup_environment()?;
let args = <crate::interface::Main as clap::Parser>::parse();
crate::logging::setup_logging(args.verbose)?;
tracing::debug!("{args:#?}");
tracing::debug!(%NH_VERSION, ?NH_REV);
if do_warn {
tracing::warn!(
"nh {NH_VERSION} now uses NH_FLAKE instead of FLAKE, please modify your configuration"
);
}
// Verify the Nix environment before running commands
check::verify_nix_environment()?;
args.command.run()
}
/// Self-elevates the current process by re-executing it with sudo
fn self_elevate() -> ! {
use std::os::unix::process::CommandExt;
let mut cmd = std::process::Command::new("sudo");
// use NH_SUDO_ASKPASS program for sudo if present
let askpass = std::env::var("NH_SUDO_ASKPASS");
if let Ok(askpass) = askpass {
cmd.env("SUDO_ASKPASS", askpass).arg("-A");
}
cmd.args(std::env::args());
debug!("{:?}", cmd);
let err = cmd.exec();
panic!("{}", err);
}