refactor(nix): tidy things into separate functions (this should be typestate but I'm eepy)
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
8c271f669a
commit
cb34302e17
1 changed files with 42 additions and 18 deletions
|
@ -10,6 +10,7 @@ use std::{
|
|||
};
|
||||
|
||||
/// Get nixosConfiguration derivation path
|
||||
#[inline]
|
||||
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))
|
||||
|
@ -27,6 +28,7 @@ fn get_config_drv_path(host: &str, config_dir: &str) -> std::io::Result<std::pro
|
|||
}
|
||||
|
||||
/// Get installable derivation path
|
||||
#[inline]
|
||||
fn get_installable_drv_path(
|
||||
host: &str,
|
||||
config_dir: &str,
|
||||
|
@ -37,7 +39,36 @@ fn get_installable_drv_path(
|
|||
.output()
|
||||
}
|
||||
|
||||
/// Takes a drv_path and gets all it's requisites from the nix store.
|
||||
#[inline]
|
||||
fn get_requisites_from_drv_path(drv_path: &str) -> std::io::Result<std::process::Child> {
|
||||
Command::new("nix-store")
|
||||
.args(["--query", "--requisites", drv_path])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
}
|
||||
|
||||
/// Turns requisites into hashes
|
||||
#[inline]
|
||||
fn requisites_to_hashes(
|
||||
drv_requisites: std::process::Child,
|
||||
) -> std::io::Result<std::process::Child> {
|
||||
let drv_requisites_remove_base = Command::new("cut")
|
||||
.args(["-d", "/", "-f4"])
|
||||
.stdin(Stdio::from(drv_requisites.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
Command::new("cut")
|
||||
.args(["-d", "-", "-f1"])
|
||||
.stdin(Stdio::from(drv_requisites_remove_base.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
}
|
||||
|
||||
pub fn get_requisites(host: &str, config_dir: &str, installable: Option<String>) -> String {
|
||||
// If the users specified an installable, we interpret that, instead of trying
|
||||
// to guess their config location.
|
||||
let mut drv_path;
|
||||
if let Some(installable) = installable {
|
||||
drv_path = get_installable_drv_path(host, config_dir, &installable).unwrap();
|
||||
|
@ -51,23 +82,16 @@ pub fn get_requisites(host: &str, config_dir: &str, installable: Option<String>)
|
|||
|
||||
log::debug!("drv_path: {}", &drv_path);
|
||||
|
||||
let get_drv_requisites = Command::new("nix-store")
|
||||
.args(["--query", "--requisites", drv_path.as_str().unwrap()])
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let drv_requisites_remove_base = Command::new("cut")
|
||||
.args(["-d", "/", "-f4"])
|
||||
.stdin(Stdio::from(get_drv_requisites.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let drv_requisites_to_hash = Command::new("cut")
|
||||
.args(["-d", "-", "-f1"])
|
||||
.stdin(Stdio::from(drv_requisites_remove_base.stdout.unwrap()))
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let drv_requisites = get_requisites_from_drv_path(drv_path.as_str().unwrap()).unwrap();
|
||||
|
||||
String::from_utf8(drv_requisites_to_hash.wait_with_output().unwrap().stdout).unwrap()
|
||||
let drv_requisite_hashes = requisites_to_hashes(drv_requisites);
|
||||
|
||||
String::from_utf8(
|
||||
drv_requisite_hashes
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
.unwrap()
|
||||
.stdout,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue