-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christina Sørensen <[email protected]>
- Loading branch information
Showing
7 changed files
with
161 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::time::Duration; | ||
|
||
use async_recursion::async_recursion; | ||
use reqwest::Client; | ||
use tokio::time::sleep; | ||
|
||
#[async_recursion] | ||
pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> usize { | ||
let response = client | ||
.head(format!("https://{domain}/{hash}.narinfo")) | ||
.send() | ||
.await; | ||
|
||
match response { | ||
Ok(response) if response.status().as_u16() == 200 => 1, | ||
Ok(response) if response.status().as_u16() == 404 => 0, | ||
_ => { | ||
// We're so fast now we get rate limited. | ||
// | ||
// Writng an actual sliding window seems kinda hard, | ||
// so we do this instead. | ||
sleep(Duration::from_millis(slide)).await; | ||
nar_exists(client, domain, hash, slide * 2).await | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use serde_json::Value; | ||
use std::{ | ||
path::Path, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
pub fn get_requisites(host: &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") | ||
.args([ | ||
"build", | ||
"--impure", | ||
"--quiet", | ||
&format!( | ||
"./#nixosConfigurations.{}.config.system.build.toplevel", | ||
host | ||
), | ||
"--dry-run", | ||
"--json", | ||
"--option", | ||
"eval-cache", | ||
"true", | ||
]) | ||
.output() | ||
.unwrap(); | ||
|
||
let drv_path_json: Value = | ||
serde_json::from_str(&String::from_utf8(get_drv_path.stdout).unwrap()).unwrap(); | ||
let drv_path = drv_path_json[0]["drvPath"].clone(); | ||
|
||
println!("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(); | ||
|
||
String::from_utf8(drv_requisites_to_hash.wait_with_output().unwrap().stdout).unwrap() | ||
} |