Allow configuring the FlakeHub flake name
This commit is contained in:
parent
308fa515eb
commit
531387f66f
|
@ -9,7 +9,6 @@ use attic_client::{
|
|||
};
|
||||
use reqwest::Url;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
@ -29,6 +28,7 @@ pub async fn init_cache(
|
|||
flakehub_api_server: &Url,
|
||||
flakehub_api_server_netrc: &Path,
|
||||
flakehub_cache_server: &Url,
|
||||
flakehub_flake_name: &str,
|
||||
store: Arc<NixStore>,
|
||||
) -> Result<State> {
|
||||
// Parse netrc to get the credentials for api.flakehub.com.
|
||||
|
@ -93,12 +93,8 @@ pub async fn init_cache(
|
|||
|
||||
// Get the cache UUID for this project.
|
||||
let cache_name = {
|
||||
let github_repo = env::var("GITHUB_REPOSITORY").map_err(|_| {
|
||||
Error::Config("GITHUB_REPOSITORY environment variable is not set".to_owned())
|
||||
})?;
|
||||
|
||||
let url = flakehub_api_server
|
||||
.join(&format!("project/{}", github_repo))
|
||||
.join(&format!("project/{}", flakehub_flake_name))
|
||||
.map_err(|_| Error::Config(format!("bad URL '{}'", flakehub_api_server)))?;
|
||||
|
||||
let response = reqwest::Client::new()
|
||||
|
|
|
@ -91,6 +91,9 @@ struct Args {
|
|||
#[arg(long)]
|
||||
flakehub_cache_server: Option<reqwest::Url>,
|
||||
|
||||
#[arg(long)]
|
||||
flakehub_flake_name: Option<String>,
|
||||
|
||||
/// The location of `nix.conf`.
|
||||
#[arg(long)]
|
||||
nix_conf: PathBuf,
|
||||
|
@ -164,6 +167,15 @@ async fn main_cli() -> Result<()> {
|
|||
let flakehub_api_server_netrc = args
|
||||
.flakehub_api_server_netrc
|
||||
.ok_or_else(|| anyhow!("--flakehub-api-server-netrc is required"))?;
|
||||
let flakehub_flake_name = args
|
||||
.flakehub_flake_name
|
||||
.ok_or_else(|| {
|
||||
tracing::debug!(
|
||||
"--flakehub-flake-name was not set, inferring from $GITHUB_REPOSITORY env var"
|
||||
);
|
||||
std::env::var("GITHUB_REPOSITORY")
|
||||
})
|
||||
.map_err(|_| anyhow!("--flakehub-flake-name and $GITHUB_REPOSITORY were both unset"))?;
|
||||
|
||||
match flakehub::init_cache(
|
||||
&args
|
||||
|
@ -171,6 +183,7 @@ async fn main_cli() -> Result<()> {
|
|||
.ok_or_else(|| anyhow!("--flakehub-api-server is required"))?,
|
||||
&flakehub_api_server_netrc,
|
||||
&flakehub_cache_server,
|
||||
&flakehub_flake_name,
|
||||
store.clone(),
|
||||
)
|
||||
.await
|
||||
|
|
Loading…
Reference in a new issue