From 661e8b1cad95a75489747017140b73f8f82b4807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Fri, 29 Mar 2024 14:47:49 +0100 Subject: [PATCH] feat: `--config` flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/cli.rs | 2 +- src/main.rs | 11 +++++++++-- src/nix.rs | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 0230610..c45b846 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -27,7 +27,7 @@ pub fn build_cli() -> Command { .arg( arg!(-c --config "Path to NixOS config.") .required(false) - .value_parser(value_parser!(PathBuf)), + .value_parser(value_parser!(String)), ) .arg( arg!(--timestamp "Add timestamp to log output.") diff --git a/src/main.rs b/src/main.rs index e1a0bcb..da63ac2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ mod nix; const SLIDE: u64 = 100; const DEFAULT_CACHE: &str = "cache.nixos.org"; +const DEFAULT_CONFIG_DIR: &str = "/etc/nixos"; #[tokio::main(flavor = "multi_thread")] async fn main() -> io::Result<()> { @@ -31,6 +32,7 @@ async fn main() -> io::Result<()> { let host_name: String; let cache_url: String; + let config_dir: String; let matches = cli::build_cli().get_matches(); @@ -50,7 +52,6 @@ async fn main() -> io::Result<()> { } } - //pretty_env_logger::init(); if matches.get_flag("timestamp") { pretty_env_logger::formatted_timed_builder() .parse_env("RUST_LOG") @@ -73,6 +74,12 @@ async fn main() -> io::Result<()> { cache_url = DEFAULT_CACHE.to_string(); } + if let Some(config) = matches.get_one::("config") { + config_dir = config.to_owned(); + } else { + config_dir = DEFAULT_CONFIG_DIR.to_string(); + } + let domain = cache_url.to_owned(); let ips: Vec = lookup_host(&domain).unwrap(); @@ -85,7 +92,7 @@ async fn main() -> io::Result<()> { .build() .unwrap(); - let binding = get_requisites(&host_name); + let binding = get_requisites(&host_name, &config_dir); let get_requisites_duration = initial_time.elapsed().as_secs(); diff --git a/src/nix.rs b/src/nix.rs index e25186c..a6d7d0f 100644 --- a/src/nix.rs +++ b/src/nix.rs @@ -4,10 +4,10 @@ use std::{ process::{Command, Stdio}, }; -pub fn get_requisites(host: &str) -> String { +pub fn get_requisites(host: &str, config_dir: &str) -> String { let get_drv_path = Command::new("nix") - .current_dir(Path::new("/home/ces/org/src/git/afk-nixos")) - .env("NIXPKGS_ALLOW_INSECURE", "1") + .current_dir(Path::new(config_dir)) + .env("NIXPKGS_ALLOW_INSECURE", "1") // FIXME Idk but fix it .args([ "build", "--impure",