Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ jobs:
echo "/nix exists"
exit 1
fi
- uses: namespacelabs/breakpoint-action@v0
if: failure()
with:
duration: 30m
authorized-users: grahamc, cole-h
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: namespacelabs/breakpoint-action@v0
if: failure()
with:
duration: 30m
authorized-users: grahamc, cole-h


run-x86_64-darwin:
name: Run x86_64 Darwin${{ matrix.determinate && ' (--determinate)' || ''}}
Expand Down
28 changes: 14 additions & 14 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@
# This means `follows` won't cause surprisingly extensive rebuilds, just trivial `chmod +x` rebuilds.
inputs.nixpkgs.follows = "nixpkgs";
inputs.nix.follows = "nix";

inputs.determinate-nixd-aarch64-linux = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/aarch64-linux";
flake = false;
};
inputs.determinate-nixd-x86_64-linux = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/x86_64-linux";
flake = false;
};
inputs.determinate-nixd-aarch64-darwin = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/macOS";
flake = false;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
inputs.determinate-nixd-aarch64-linux = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/aarch64-linux";
flake = false;
};
inputs.determinate-nixd-x86_64-linux = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/x86_64-linux";
flake = false;
};
inputs.determinate-nixd-aarch64-darwin = {
url = "https://install.determinate.systems/determinate-nixd/pr/190/macOS";
flake = false;
};

};

flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.0.0.tar.gz";
Expand Down
78 changes: 38 additions & 40 deletions src/action/base/create_or_merge_nix_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,22 @@ impl From<CreateOrMergeNixConfigError> for ActionErrorKind {
pub struct CreateOrMergeNixConfig {
pub(crate) path: PathBuf,
pending_nix_config: NixConfig,
header: String,
}

impl CreateOrMergeNixConfig {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn plan(
path: impl AsRef<Path>,
pending_nix_config: NixConfig,
header: String,
) -> Result<StatefulAction<Self>, ActionError> {
let path = path.as_ref().to_path_buf();

let this = Self {
path,
pending_nix_config,
header,
};

if this.path.exists() {
Expand Down Expand Up @@ -170,7 +173,7 @@ impl Action for CreateOrMergeNixConfig {
}
fn tracing_synopsis(&self) -> String {
format!(
"Merge or create nix.conf file `{path}`",
"Merge or create Nix configuration file `{path}`",
path = self.path.display(),
)
}
Expand Down Expand Up @@ -216,16 +219,11 @@ impl Action for CreateOrMergeNixConfig {

#[tracing::instrument(level = "debug", skip_all)]
async fn execute(&mut self) -> Result<(), ActionError> {
let Self {
path,
pending_nix_config,
} = self;

if tracing::enabled!(tracing::Level::TRACE) {
let span = tracing::Span::current();
span.record(
"pending_nix_config",
pending_nix_config
self.pending_nix_config
.settings()
.iter()
.map(|(k, v)| format!("{k}='{v}'"))
Expand All @@ -237,7 +235,7 @@ impl Action for CreateOrMergeNixConfig {
// Create a temporary file in the same directory as the one
// that the final file goes in, so that we can rename it
// atomically
let parent_dir = path.parent().expect("File must be in a directory");
let parent_dir = self.path.parent().expect("File must be in a directory");
let mut temp_file_path = parent_dir.to_owned();
{
let mut rng = rand::thread_rng();
Expand All @@ -259,20 +257,20 @@ impl Action for CreateOrMergeNixConfig {
Self::error(ActionErrorKind::Open(temp_file_path.clone(), e))
})?;

let (mut merged_nix_config, mut existing_nix_config) = if path.exists() {
let (mut merged_nix_config, mut existing_nix_config) = if self.path.exists() {
let (merged_nix_config, existing_nix_config) =
Self::validate_existing_nix_config(pending_nix_config, path)?;
Self::validate_existing_nix_config(&self.pending_nix_config, &self.path)?;
(merged_nix_config, Some(existing_nix_config))
} else {
(pending_nix_config.clone(), None)
(self.pending_nix_config.clone(), None)
};

let mut new_config = String::new();

if let Some(existing_nix_config) = existing_nix_config.as_mut() {
let mut discovered_buf = tokio::fs::read_to_string(&path)
let mut discovered_buf = tokio::fs::read_to_string(&self.path)
.await
.map_err(|e| Self::error(ActionErrorKind::Read(path.to_path_buf(), e)))?;
.map_err(|e| Self::error(ActionErrorKind::Read(self.path.to_path_buf(), e)))?;

// We append a newline to ensure that, in the case there are comments at the end of the
// file and _NO_ trailing newline, we still preserve the entire block of comments.
Expand Down Expand Up @@ -397,9 +395,7 @@ impl Action for CreateOrMergeNixConfig {
new_config.push('\n');
}

new_config
.push_str("# Generated by https://github.com/DeterminateSystems/nix-installer.\n");
new_config.push_str("# See `/nix/nix-installer --version` for the version details.\n");
new_config.push_str(&self.header);
new_config.push('\n');

for (name, value) in merged_nix_config.settings() {
Expand All @@ -418,20 +414,20 @@ impl Action for CreateOrMergeNixConfig {
.map_err(|e| {
Self::error(ActionErrorKind::SetPermissions(
NIX_CONF_MODE,
path.to_owned(),
self.path.to_owned(),
e,
))
})?;
temp_file
.sync_all()
.await
.map_err(|e| Self::error(ActionErrorKind::Sync(temp_file_path.clone(), e)))?;
tokio::fs::rename(&temp_file_path, &path)
tokio::fs::rename(&temp_file_path, &self.path)
.await
.map_err(|e| {
Self::error(ActionErrorKind::Rename(
temp_file_path.to_owned(),
path.to_owned(),
self.path.to_owned(),
e,
))
})?;
Expand All @@ -440,27 +436,17 @@ impl Action for CreateOrMergeNixConfig {
}

fn revert_description(&self) -> Vec<ActionDescription> {
let Self {
path,
pending_nix_config: _,
} = &self;

vec![ActionDescription::new(
format!("Delete file `{}`", path.display()),
vec![format!("Delete file `{}`", path.display())],
format!("Delete file `{}`", self.path.display()),
vec![format!("Delete file `{}`", self.path.display())],
)]
}

#[tracing::instrument(level = "debug", skip_all)]
async fn revert(&mut self) -> Result<(), ActionError> {
let Self {
path,
pending_nix_config: _,
} = self;

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

Ok(())
}
Expand All @@ -480,7 +466,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand All @@ -506,7 +494,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand Down Expand Up @@ -534,7 +524,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand Down Expand Up @@ -566,7 +558,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand Down Expand Up @@ -611,7 +605,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, nix_config, "".to_string()).await {
Err(err) => {
if let ActionErrorKind::Custom(e) = err.kind() {
match e.downcast_ref::<CreateOrMergeNixConfigError>() {
Expand Down Expand Up @@ -653,7 +647,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand Down Expand Up @@ -685,7 +681,9 @@ 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, nix_config, "# Generated by".to_string())
.await?;

action.try_execute().await?;

Expand Down
3 changes: 1 addition & 2 deletions src/action/common/configure_nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl ConfigureNix {
pub async fn plan(
shell_profile_locations: ShellProfileLocations,
settings: &CommonSettings,
extra_internal_conf: Option<nix_config_parser::NixConfig>,
) -> Result<StatefulAction<Self>, ActionError> {
let setup_default_profile = SetupDefaultProfile::plan(PathBuf::from(SCRATCH_DIR))
.await
Expand All @@ -53,9 +52,9 @@ impl ConfigureNix {
settings.nix_build_group_name.clone(),
settings.proxy.clone(),
settings.ssl_cert_file.clone(),
extra_internal_conf.clone(),
settings.extra_conf.clone(),
settings.force,
settings.determinate_nix,
)
.await
.map_err(Self::error)?,
Expand Down
Loading
Loading