netrc: w/ dnixd, don't update netrc, require it to be right path

This commit is contained in:
Cole Mickens 2024-08-29 09:25:39 -07:00
parent d9d748267f
commit 08c8cf0275
2 changed files with 47 additions and 34 deletions

View file

@ -1,5 +1,5 @@
use crate::env::Environment; use crate::env::Environment;
use crate::error::{Error, Result}; use crate::error::{self, Error, Result};
use anyhow::Context; use anyhow::Context;
use attic::cache::CacheName; use attic::cache::CacheName;
use attic::nix_store::{NixStore, StorePath}; use attic::nix_store::{NixStore, StorePath};
@ -9,6 +9,7 @@ use attic_client::{
config::ServerConfig, config::ServerConfig,
push::{PushConfig, Pusher}, push::{PushConfig, Pusher},
}; };
use reqwest::header::HeaderValue; use reqwest::header::HeaderValue;
use reqwest::Url; use reqwest::Url;
use serde::Deserialize; use serde::Deserialize;
@ -35,7 +36,16 @@ pub async fn init_cache(
flakehub_cache_server: &Url, flakehub_cache_server: &Url,
flakehub_flake_name: Option<String>, flakehub_flake_name: Option<String>,
store: Arc<NixStore>, store: Arc<NixStore>,
using_dnixd: bool,
) -> Result<State> { ) -> Result<State> {
if using_dnixd {
let dnixd_state_dir: &Path = Path::new(&crate::DETERMINATE_STATE_DIR);
let expected_netrc_path = dnixd_state_dir.join("netrc");
if flakehub_api_server_netrc != expected_netrc_path {
let err = format!("flakehub-api-server-netrc was ({}), expected ({}) since determinate-nixd is available", flakehub_api_server_netrc.display(), expected_netrc_path.display());
return Err(error::Error::Config(err));
}
}
// Parse netrc to get the credentials for api.flakehub.com. // Parse netrc to get the credentials for api.flakehub.com.
let netrc = { let netrc = {
let mut netrc_file = File::open(flakehub_api_server_netrc).await.map_err(|e| { let mut netrc_file = File::open(flakehub_api_server_netrc).await.map_err(|e| {
@ -89,6 +99,7 @@ pub async fn init_cache(
)) ))
})?; })?;
if !using_dnixd {
// Append an entry for the FlakeHub cache server to netrc. // Append an entry for the FlakeHub cache server to netrc.
if !netrc if !netrc
.machines .machines
@ -125,6 +136,7 @@ pub async fn init_cache(
)) ))
})?; })?;
} }
}
let server_config = ServerConfig { let server_config = ServerConfig {
endpoint: flakehub_cache_server.to_string(), endpoint: flakehub_cache_server.to_string(),

View file

@ -233,6 +233,7 @@ async fn main_cli() -> Result<()> {
&flakehub_cache_server, &flakehub_cache_server,
flakehub_flake_name, flakehub_flake_name,
store.clone(), store.clone(),
dnixd_available,
) )
.await .await
{ {