Skip to content
Merged
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
2 changes: 1 addition & 1 deletion prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ nix flake update --commit-lock-file

cargo update --aggressive
git add Cargo.lock
git commit -m "Update Cargo.lock dependencies"
git commit -m "Update Cargo.lock dependencies" || true # "fails" if there are no changes

toml set ./Cargo.toml package.version "$version" > Cargo.toml.next
mv Cargo.toml.next Cargo.toml
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 @@ -368,7 +368,7 @@ impl Action for CreateOrInsertIntoFile {
}

if file_contents.is_empty() {
crate::util::remove_file(&path, OnMissing::Ignore)
crate::util::remove_file(path, OnMissing::Ignore)
.await
.map_err(|e| ActionErrorKind::Remove(path.to_owned(), e))
.map_err(Self::error)?;
Expand Down
2 changes: 1 addition & 1 deletion src/action/common/provision_determinate_nixd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl Action for ProvisionDeterminateNixd {
// NOTE(cole-h): If /etc/nix/nix.conf was the last file in /etc/nix, then let's clean up the
// entire directory too.
let nix_conf_dir = PathBuf::from(NIX_CONF_FOLDER);
if let Some(mut entries) = tokio::fs::read_dir(&nix_conf_dir).await.ok() {
if let Ok(mut entries) = tokio::fs::read_dir(&nix_conf_dir).await {
if entries.next_entry().await.ok().flatten().is_none() {
crate::util::remove_dir_all(&nix_conf_dir, OnMissing::Ignore)
.await
Expand Down
131 changes: 75 additions & 56 deletions src/cli/subcommand/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ pub struct Install {
pub planner: Option<BuiltinPlanner>,
}

#[derive(Eq, PartialEq)]
enum InstallCase {
DeterminateInteractive,
DeterminateScripted,
UpstreamInteractive,
UpstreamScripted,
}

#[async_trait::async_trait]
impl CommandExecute for Install {
#[tracing::instrument(level = "trace", skip_all)]
Expand Down Expand Up @@ -135,7 +143,7 @@ impl CommandExecute for Install {
tracing::info!("{}", msg.trim());
}

let mut post_install_message = None;
let mut case: Option<InstallCase> = None;

let mut install_plan = if let Some(plan_path) = plan {
let install_plan_string = tokio::fs::read_to_string(&plan_path)
Expand Down Expand Up @@ -183,63 +191,65 @@ impl CommandExecute for Install {
None => {
let planner_settings = planner.common_settings_mut();

if !planner_settings.determinate_nix {
if !std::io::stdin().is_terminal() || no_confirm {
let msg = feedback
.get_feature_ptr_payload::<String>("dni-det-msg-noninteractive-ptr")
.await
.unwrap_or("Consider using Determinate Nix, for less fuss: https://dtr.mn/determinate-nix".into());
post_install_message = Some(msg);
} else {
let base_prompt = feedback
.get_feature_ptr_payload::<String>(
"dni-det-msg-interactive-prompt-ptr",
)
.await
.unwrap_or("Install Determinate Nix?".into());
let explanation = feedback
.get_feature_ptr_payload::<String>(
"dni-det-msg-interactive-explanation-ptr",
)
.await
.unwrap_or(DETERMINATE_MSG_EXPLAINER.into());

let mut currently_explaining = explain;

loop {
let prompt = if currently_explaining {
&format!(
"\n{}\n{}",
base_prompt.trim().green(),
explanation.trim()
)
} else {
&format!("\n{}", base_prompt.trim().green())
};

let response = interaction::prompt(
prompt.to_string(),
PromptChoice::Yes,
currently_explaining,
)
.await?;

match response {
PromptChoice::Explain => {
currently_explaining = true;
},
PromptChoice::Yes => {
planner_settings.determinate_nix = true;
break;
},
PromptChoice::No => {
break;
},
}
if !planner_settings.determinate_nix
&& std::io::stdin().is_terminal()
&& !no_confirm
{
let base_prompt = feedback
.get_feature_ptr_payload::<String>("dni-det-msg-interactive-prompt-ptr")
.await
.unwrap_or("Install Determinate Nix?".into());

let mut explanation: Option<String> = None;

loop {
let prompt = if let Some(ref explanation) = explanation {
&format!("\n{}\n{}", base_prompt.trim().green(), explanation.trim())
} else {
&format!("\n{}", base_prompt.trim().green())
};

let response = interaction::prompt(
prompt.to_string(),
PromptChoice::Yes,
explanation.is_some(),
)
.await?;

match response {
PromptChoice::Explain => {
explanation = Some(
feedback
.get_feature_ptr_payload::<String>(
"dni-det-msg-interactive-explanation-ptr",
)
.await
.unwrap_or(DETERMINATE_MSG_EXPLAINER.into()),
);
},
PromptChoice::Yes => {
planner_settings.determinate_nix = true;
break;
},
PromptChoice::No => {
break;
},
}
}
}

case = Some(
match (
planner_settings.determinate_nix,
std::io::stdin().is_terminal() && !no_confirm,
) {
(true, true) => InstallCase::DeterminateInteractive,
(true, false) => InstallCase::DeterminateScripted,
(false, true) => InstallCase::UpstreamInteractive,
(false, false) => InstallCase::UpstreamScripted,
},
);

feedback.set_planner(&planner).await?;

let res = planner.plan().await;
Expand Down Expand Up @@ -413,8 +423,17 @@ impl CommandExecute for Install {
},
);

if let Some(post_message) = post_install_message {
println!("{}\n", post_message.trim());
let feat = match case {
Some(InstallCase::DeterminateInteractive) => Some("dni-post-det-int-ptr"),
Some(InstallCase::UpstreamInteractive) => Some("dni-post-ups-int-ptr"),
Some(InstallCase::UpstreamScripted) => Some("dni-post-ups-scr-ptr"),
_ => None,
};
if let Some(feat) = feat {
let msg = feedback.get_feature_ptr_payload::<String>(feat).await;
if let Some(msg) = msg {
println!("{}\n", msg.trim());
}
}
},
}
Expand Down
Loading