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

Allow user override of the nix store volume name #1317

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/action/macos/encrypt_apfs_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ impl EncryptApfsVolume {
) -> Result<StatefulAction<Self>, ActionError> {
let name = name.as_ref().to_owned();
let disk = disk.as_ref().to_path_buf();

println!("Volume name is {0}", name);
let mut command = Command::new("/usr/bin/security");
command.args(["find-generic-password", "-a"]);
command.arg(&name);
command.arg("-s");
command.arg("Nix Store");
command.arg(&name);
command.arg("-l");
command.arg(format!("{} encryption password", disk.display()));
command.arg("-D");
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Action for EncryptApfsVolume {
"-a",
self.name.as_str(),
"-s",
"Nix Store",
self.name.as_str(),
"-l",
format!("{} encryption password", disk_str).as_str(),
"-D",
Expand Down
33 changes: 33 additions & 0 deletions src/planner/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ impl Planner for Macos {
}

if self.settings.determinate_nix {
println!("Creating determinate nix volume {0}", self.volume_label);
println!(
"Installer volume label: {}",
std::env::var("NIX_INSTALLER_VOLUME_LABEL").unwrap_or_default()
);
plan.push(
CreateDeterminateNixVolume::plan(
root_disk.unwrap(), /* We just ensured it was populated */
Expand Down Expand Up @@ -513,3 +518,31 @@ impl HasExpectedErrors for MacosError {
}
}
}

#[cfg(all(test, feature = "cli"))]
mod tests {
use super::*;
use clap::Parser;

#[tokio::test]
async fn test_volume_label() {
// Test default value
std::env::remove_var("NIX_INSTALLER_VOLUME_LABEL");
let macos = Macos::parse_from(Vec::<String>::new());
assert_eq!(
macos.volume_label, "Nix Store",
"Default value should be 'Nix Store'"
);

// Test env var override
std::env::set_var("NIX_INSTALLER_VOLUME_LABEL", "Custom Volume");
let macos = Macos::parse_from(Vec::<String>::new());
assert_eq!(
macos.volume_label, "Custom Volume",
"Environment variable should override default"
);

// Cleanup
std::env::remove_var("NIX_INSTALLER_VOLUME_LABEL");
}
}