feat: parse installables
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
419976d275
commit
e949478754
3 changed files with 34 additions and 6 deletions
|
@ -6,12 +6,15 @@
|
||||||
use clap::{arg, command, crate_authors, value_parser, ArgAction, Command};
|
use clap::{arg, command, crate_authors, value_parser, ArgAction, Command};
|
||||||
|
|
||||||
const DEFAULT_CACHE: &str = "cache.nixos.org";
|
const DEFAULT_CACHE: &str = "cache.nixos.org";
|
||||||
|
const DEFAULT_INSTALLABLE: &str = "./#nixosConfigurations.{}.config.system.build.toplevel";
|
||||||
|
|
||||||
pub fn build_cli() -> Command {
|
pub fn build_cli() -> Command {
|
||||||
command!()
|
command!()
|
||||||
.author(crate_authors!("\n"))
|
.author(crate_authors!("\n"))
|
||||||
|
// TODO: parse multiple installables, like e.g. build does?
|
||||||
|
.arg(arg!([installable] "A nix installable").required(false))
|
||||||
.arg(
|
.arg(
|
||||||
arg!(--cache <CACHE> "check a specific cache")
|
arg!(--cache <CACHE> "Check a specific cache")
|
||||||
.required(false)
|
.required(false)
|
||||||
.default_value(DEFAULT_CACHE),
|
.default_value(DEFAULT_CACHE),
|
||||||
)
|
)
|
||||||
|
|
|
@ -103,7 +103,11 @@ async fn main() -> io::Result<()> {
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let binding = get_requisites(&host_name, &config_dir);
|
let binding = get_requisites(
|
||||||
|
&host_name,
|
||||||
|
&config_dir,
|
||||||
|
matches.get_one::<String>("installable").cloned(),
|
||||||
|
);
|
||||||
|
|
||||||
let get_requisites_duration = initial_time.elapsed().as_secs();
|
let get_requisites_duration = initial_time.elapsed().as_secs();
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,9 @@ use std::{
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
/// Get nixosConfiguration derivation path
|
||||||
let get_drv_path = Command::new("nix")
|
fn get_config_drv_path(host: &str, config_dir: &str) -> std::io::Result<std::process::Output> {
|
||||||
|
Command::new("nix")
|
||||||
.current_dir(Path::new(config_dir))
|
.current_dir(Path::new(config_dir))
|
||||||
.args([
|
.args([
|
||||||
"build",
|
"build",
|
||||||
|
@ -23,10 +24,30 @@ pub fn get_requisites(host: &str, config_dir: &str) -> String {
|
||||||
"--json",
|
"--json",
|
||||||
])
|
])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
}
|
||||||
|
|
||||||
|
/// Get installable derivation path
|
||||||
|
fn get_installable_drv_path(
|
||||||
|
host: &str,
|
||||||
|
config_dir: &str,
|
||||||
|
installable: &str,
|
||||||
|
) -> std::io::Result<std::process::Output> {
|
||||||
|
Command::new("nix")
|
||||||
|
.current_dir(Path::new(config_dir))
|
||||||
|
.args(["build", "--quiet", installable, "--dry-run", "--json"])
|
||||||
|
.output()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_requisites(host: &str, config_dir: &str, installable: Option<String>) -> String {
|
||||||
|
let mut drv_path;
|
||||||
|
if let Some(installable) = installable {
|
||||||
|
drv_path = get_installable_drv_path(host, config_dir, &installable).unwrap();
|
||||||
|
} else {
|
||||||
|
drv_path = get_config_drv_path(host, config_dir).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let drv_path_json: Value =
|
let drv_path_json: Value =
|
||||||
serde_json::from_str(&String::from_utf8(get_drv_path.stdout).unwrap()).unwrap();
|
serde_json::from_str(&String::from_utf8(drv_path.stdout).unwrap()).unwrap();
|
||||||
let drv_path = drv_path_json[0]["drvPath"].clone();
|
let drv_path = drv_path_json[0]["drvPath"].clone();
|
||||||
|
|
||||||
log::debug!("drv_path: {}", &drv_path);
|
log::debug!("drv_path: {}", &drv_path);
|
||||||
|
|
Loading…
Reference in a new issue