Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complicated reups #1294

Closed
wants to merge 12 commits into from
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
default = pkgs.nix-installer-static;
} // nixpkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) {
default = pkgs.nix-installer;

determinate-nixd = pkgs.runCommand "determinate-nixd-link" { } ''
ln -s ${optionalPathToDeterminateNixd system} $out
'';
});

hydraJobs = {
Expand Down
6 changes: 3 additions & 3 deletions src/action/base/create_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ impl Action for CreateDirectory {
if child_path_type.is_dir() {
remove_dir_all(child_path_path.clone())
.await
.map_err(|e| ActionErrorKind::Remove(path.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?
} else {
remove_file(child_path_path)
.await
.map_err(|e| ActionErrorKind::Remove(path.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?
}
}
Expand All @@ -280,7 +280,7 @@ impl Action for CreateDirectory {
},
(false, true, _) | (false, false, true) => remove_dir_all(path.clone())
.await
.map_err(|e| ActionErrorKind::Remove(path.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?,
(false, false, false) => {
tracing::debug!("Not removing `{}`, the folder is not empty", path.display());
Expand Down
2 changes: 1 addition & 1 deletion src/action/base/create_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl Action for CreateFile {

remove_file(&path)
.await
.map_err(|e| ActionErrorKind::Remove(path.to_owned(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/action/base/create_or_insert_into_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl Action for CreateOrInsertIntoFile {
if file_contents.is_empty() {
remove_file(&path)
.await
.map_err(|e| ActionErrorKind::Remove(path.to_owned(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?;
} else {
file.seek(SeekFrom::Start(0))
Expand Down
24 changes: 16 additions & 8 deletions src/action/base/create_or_merge_nix_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl CreateOrMergeNixConfig {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn plan(
path: impl AsRef<Path>,
alternate_path: Option<impl AsRef<Path>>,
pending_nix_config: NixConfig,
) -> Result<StatefulAction<Self>, ActionError> {
let path = path.as_ref().to_path_buf();
Expand All @@ -62,6 +63,12 @@ impl CreateOrMergeNixConfig {
pending_nix_config,
};

if let Some(alternate) = alternate_path {
if this.path.exists() && alternate.as_ref().exists() {
return Ok(StatefulAction::completed(this));
}
}

if this.path.exists() {
let (merged_nix_config, _) =
Self::validate_existing_nix_config(&this.pending_nix_config, &this.path)?;
Expand Down Expand Up @@ -473,7 +480,8 @@ impl Action for CreateOrMergeNixConfig {

remove_file(&path)
.await
.map_err(|e| Self::error(ActionErrorKind::Remove(path.to_owned(), e)))?;
.or_else(|e| ActionErrorKind::remove_ignore_not_found(path, e))
.map_err(Self::error)?;

Ok(())
}
Expand All @@ -493,7 +501,7 @@ mod test {
nix_config
.settings_mut()
.insert("experimental-features".into(), "ca-references".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand All @@ -519,7 +527,7 @@ mod test {
nix_config
.settings_mut()
.insert("experimental-features".into(), "ca-references".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand Down Expand Up @@ -547,7 +555,7 @@ mod test {
nix_config
.settings_mut()
.insert("experimental-features".into(), "flakes".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand Down Expand Up @@ -579,7 +587,7 @@ mod test {
nix_config
.settings_mut()
.insert("allow-dirty".into(), "false".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand Down Expand Up @@ -624,7 +632,7 @@ mod test {
nix_config
.settings_mut()
.insert("warn-dirty".into(), "false".into());
match CreateOrMergeNixConfig::plan(&test_file, nix_config).await {
match CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await {
Err(err) => {
if let ActionErrorKind::Custom(e) = err.kind() {
match e.downcast_ref::<CreateOrMergeNixConfigError>() {
Expand Down Expand Up @@ -666,7 +674,7 @@ mod test {
nix_config
.settings_mut()
.insert("experimental-features".into(), "ca-references".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand Down Expand Up @@ -698,7 +706,7 @@ mod test {
nix_config
.settings_mut()
.insert("experimental-features".into(), "ca-references".into());
let mut action = CreateOrMergeNixConfig::plan(&test_file, nix_config).await?;
let mut action = CreateOrMergeNixConfig::plan(&test_file, None::<&str>, nix_config).await?;

action.try_execute().await?;

Expand Down
2 changes: 1 addition & 1 deletion src/action/base/move_unpacked_nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Action for MoveUnpackedNix {
tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Removing already existing package");
tokio::fs::remove_dir_all(&entry_dest)
.await
.map_err(|e| ActionErrorKind::Remove(entry_dest.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(&entry_dest, e))
.map_err(Self::error)?;
}
tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Renaming");
Expand Down
3 changes: 2 additions & 1 deletion src/action/base/remove_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl Action for RemoveDirectory {
}
remove_dir_all(&self.path)
.await
.map_err(|e| Self::error(ActionErrorKind::Remove(self.path.clone(), e)))?;
.or_else(|e| ActionErrorKind::remove_ignore_not_found(&self.path, e))
.map_err(Self::error)?;
} else {
tracing::debug!("Directory `{}` not present, skipping", self.path.display(),);
};
Expand Down
13 changes: 8 additions & 5 deletions src/action/common/configure_determinate_nixd_init_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ impl ConfigureDeterminateNixdInitService {
super::configure_upstream_init_service::DARWIN_NIX_DAEMON_DEST,
)
.await
.map_err(|e| {
Self::error(ActionErrorKind::Remove(
super::configure_upstream_init_service::DARWIN_NIX_DAEMON_DEST.into(),
.or_else(|e| {
ActionErrorKind::remove_ignore_not_found(
std::path::Path::new(
super::configure_upstream_init_service::DARWIN_NIX_DAEMON_DEST,
),
e,
))
})?;
)
})
.map_err(Self::error)?;
}

Some(DARWIN_NIXD_DAEMON_DEST.into())
Expand Down
18 changes: 10 additions & 8 deletions src/action/common/configure_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl Action for ConfigureInitService {
tracing::trace!(path = %service_dest.display(), "Removing");
tokio::fs::remove_file(service_dest)
.await
.map_err(|e| ActionErrorKind::Remove(service_dest.into(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(service_dest, e))
.map_err(Self::error)?;
}
tracing::trace!(src = %service_src.display(), dest = %service_dest.display(), "Symlinking");
Expand All @@ -388,7 +388,7 @@ impl Action for ConfigureInitService {
tracing::trace!(path = %dest.display(), "Removing");
tokio::fs::remove_file(dest)
.await
.map_err(|e| ActionErrorKind::Remove(dest.into(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(dest, e))
.map_err(Self::error)?;
}

Expand Down Expand Up @@ -611,10 +611,12 @@ impl Action for ConfigureInitService {
}

if Path::new(TMPFILES_DEST).exists() {
if let Err(err) = tokio::fs::remove_file(TMPFILES_DEST)
.await
.map_err(|e| ActionErrorKind::Remove(PathBuf::from(TMPFILES_DEST), e))
{
if let Err(err) = tokio::fs::remove_file(TMPFILES_DEST).await.or_else(|e| {
ActionErrorKind::remove_ignore_not_found(
std::path::Path::new(TMPFILES_DEST),
e,
)
}) {
errors.push(err);
}
}
Expand All @@ -640,7 +642,7 @@ impl Action for ConfigureInitService {
tracing::trace!(path = %dest.display(), "Removing");
if let Err(err) = tokio::fs::remove_file(dest)
.await
.map_err(|e| ActionErrorKind::Remove(PathBuf::from(dest), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(dest, e))
{
errors.push(err);
}
Expand All @@ -652,7 +654,7 @@ impl Action for ConfigureInitService {
tracing::trace!(path = %socket.dest.display(), "Removing");
if let Err(err) = tokio::fs::remove_file(&socket.dest)
.await
.map_err(|e| ActionErrorKind::Remove(socket.dest.to_path_buf(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(&socket.dest, e))
{
errors.push(err);
}
Expand Down
2 changes: 2 additions & 0 deletions src/action/common/configure_nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl ConfigureNix {
shell_profile_locations: ShellProfileLocations,
settings: &CommonSettings,
extra_internal_conf: Option<nix_config_parser::NixConfig>,
determinate_nix: bool,
) -> Result<StatefulAction<Self>, ActionError> {
let setup_default_profile = SetupDefaultProfile::plan(PathBuf::from(SCRATCH_DIR))
.await
Expand All @@ -49,6 +50,7 @@ impl ConfigureNix {
settings.proxy.clone(),
settings.ssl_cert_file.clone(),
extra_internal_conf.clone(),
determinate_nix,
settings.extra_conf.clone(),
settings.force,
)
Expand Down
9 changes: 2 additions & 7 deletions src/action/common/configure_upstream_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ impl ConfigureUpstreamInitService {
super::configure_determinate_nixd_init_service::DARWIN_NIXD_DAEMON_DEST,
)
.await
.map_err(|e| {
Self::error(ActionErrorKind::Remove(
super::configure_determinate_nixd_init_service::DARWIN_NIXD_DAEMON_DEST
.into(),
e,
))
})?;
.or_else(|e| ActionErrorKind::remove_ignore_not_found(std::path::Path::new(super::configure_determinate_nixd_init_service::DARWIN_NIXD_DAEMON_DEST), e))
.map_err(Self::error)?;
}

Some(DARWIN_NIX_DAEMON_DEST.into())
Expand Down
18 changes: 14 additions & 4 deletions src/action/common/place_nix_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ use std::path::PathBuf;

pub const NIX_CONF_FOLDER: &str = "/etc/nix";
const NIX_CONF: &str = "/etc/nix/nix.conf";
const NIX_CUSTOM_CONF: &str = "/etc/nix/nix.custom.conf";

/**
Place the `/etc/nix.conf` file
Place the `/etc/nix/nix.conf` file
*/
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "place_nix_configuration")]
Expand All @@ -31,6 +32,7 @@ impl PlaceNixConfiguration {
proxy: Option<Url>,
ssl_cert_file: Option<PathBuf>,
extra_internal_conf: Option<nix_config_parser::NixConfig>,
determinate_nix: bool,
extra_conf: Vec<UrlOrPathOrString>,
force: bool,
) -> Result<StatefulAction<Self>, ActionError> {
Expand All @@ -46,9 +48,17 @@ impl PlaceNixConfiguration {
let create_directory = CreateDirectory::plan(NIX_CONF_FOLDER, None, None, 0o0755, force)
.await
.map_err(Self::error)?;
let create_or_merge_nix_config = CreateOrMergeNixConfig::plan(NIX_CONF, nix_config)
.await
.map_err(Self::error)?;
let create_or_merge_nix_config = CreateOrMergeNixConfig::plan(
NIX_CONF,
if determinate_nix {
Some(NIX_CUSTOM_CONF)
} else {
None
},
nix_config,
)
.await
.map_err(Self::error)?;
Ok(Self {
create_directory,
create_or_merge_nix_config,
Expand Down
4 changes: 2 additions & 2 deletions src/action/common/provision_determinate_nixd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Action for ProvisionDeterminateNixd {
if self.binary_location.exists() {
remove_file(&self.binary_location)
.await
.map_err(|e| ActionErrorKind::Remove(self.binary_location.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(&self.binary_location, e))
.map_err(Self::error)?;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ impl Action for ProvisionDeterminateNixd {
if self.binary_location.exists() {
remove_file(&self.binary_location)
.await
.map_err(|e| ActionErrorKind::Remove(self.binary_location.clone(), e))
.or_else(|e| ActionErrorKind::remove_ignore_not_found(&self.binary_location, e))
.map_err(Self::error)?;
}

Expand Down
Loading
Loading