Use correct port and compression for nix copy
This commit is contained in:
parent
ec04905db4
commit
fc80531e5e
|
@ -2,7 +2,9 @@
|
||||||
//!
|
//!
|
||||||
//! This API is intended to be used by nix-installer-action.
|
//! This API is intended to be used by nix-installer-action.
|
||||||
|
|
||||||
use axum::{extract::Extension, routing::post, Json, Router};
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use axum::{extract::Extension, routing::post, http::uri::Uri, Json, Router};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -55,7 +57,8 @@ async fn workflow_finish(
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
tracing::info!("Pushing {} new paths", new_paths.len());
|
tracing::info!("Pushing {} new paths", new_paths.len());
|
||||||
upload_paths(new_paths.clone()).await?;
|
let store_uri = make_store_uri(&state.self_endpoint);
|
||||||
|
upload_paths(new_paths.clone(), &store_uri).await?;
|
||||||
|
|
||||||
let sender = state.shutdown_sender.lock().await.take().unwrap();
|
let sender = state.shutdown_sender.lock().await.take().unwrap();
|
||||||
sender.send(()).unwrap();
|
sender.send(()).unwrap();
|
||||||
|
@ -66,3 +69,13 @@ async fn workflow_finish(
|
||||||
num_new_paths: new_paths.len(),
|
num_new_paths: new_paths.len(),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn make_store_uri(self_endpoint: &SocketAddr) -> String {
|
||||||
|
Uri::builder()
|
||||||
|
.scheme("http")
|
||||||
|
.authority(self_endpoint.to_string())
|
||||||
|
.path_and_query("/?compression=zstd¶llel-compression=true")
|
||||||
|
.build()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -92,6 +92,11 @@ struct StateInner {
|
||||||
|
|
||||||
/// Set of store path hashes that are not present in GHAC.
|
/// Set of store path hashes that are not present in GHAC.
|
||||||
narinfo_nagative_cache: RwLock<HashSet<String>>,
|
narinfo_nagative_cache: RwLock<HashSet<String>>,
|
||||||
|
|
||||||
|
/// Endpoint of ourselves.
|
||||||
|
///
|
||||||
|
/// This is used by our Action API to invoke `nix copy` to upload new paths.
|
||||||
|
self_endpoint: SocketAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -124,6 +129,7 @@ fn main() {
|
||||||
shutdown_sender: Mutex::new(Some(shutdown_sender)),
|
shutdown_sender: Mutex::new(Some(shutdown_sender)),
|
||||||
original_paths: Mutex::new(HashSet::new()),
|
original_paths: Mutex::new(HashSet::new()),
|
||||||
narinfo_nagative_cache: RwLock::new(HashSet::new()),
|
narinfo_nagative_cache: RwLock::new(HashSet::new()),
|
||||||
|
self_endpoint: args.listen.to_owned(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
|
|
@ -38,16 +38,15 @@ pub async fn get_store_paths() -> Result<HashSet<PathBuf>> {
|
||||||
Ok(paths)
|
Ok(paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads a list of store paths to the cache.
|
/// Uploads a list of store paths to a store URI.
|
||||||
pub async fn upload_paths(mut paths: Vec<PathBuf>) -> Result<()> {
|
pub async fn upload_paths(mut paths: Vec<PathBuf>, store_uri: &str) -> Result<()> {
|
||||||
// When the daemon started Nix may not have been installed
|
// When the daemon started Nix may not have been installed
|
||||||
let env_path = Command::new("sh")
|
let env_path = Command::new("sh")
|
||||||
.args(&["-lc", "echo $PATH"])
|
.args(&["-lc", "echo $PATH"])
|
||||||
.output()
|
.output()
|
||||||
.await?
|
.await?
|
||||||
.stdout;
|
.stdout;
|
||||||
let env_path = String::from_utf8(env_path)
|
let env_path = String::from_utf8(env_path).expect("PATH contains invalid UTF-8");
|
||||||
.expect("PATH contains invalid UTF-8");
|
|
||||||
|
|
||||||
while !paths.is_empty() {
|
while !paths.is_empty() {
|
||||||
let mut batch = Vec::new();
|
let mut batch = Vec::new();
|
||||||
|
@ -63,8 +62,7 @@ pub async fn upload_paths(mut paths: Vec<PathBuf>) -> Result<()> {
|
||||||
|
|
||||||
let status = Command::new("nix")
|
let status = Command::new("nix")
|
||||||
.args(&["--extra-experimental-features", "nix-command"])
|
.args(&["--extra-experimental-features", "nix-command"])
|
||||||
// FIXME: Port and compression settings
|
.args(&["copy", "--to", store_uri])
|
||||||
.args(&["copy", "--to", "http://127.0.0.1:3000"])
|
|
||||||
.args(&batch)
|
.args(&batch)
|
||||||
.env("PATH", &env_path)
|
.env("PATH", &env_path)
|
||||||
.status()
|
.status()
|
||||||
|
|
Loading…
Reference in a new issue