Skip to content

Commit 4073ef6

Browse files
author
faukah
committed
nixos: move missing_switch_to_configuration_error into helper function
1 parent 05d228f commit 4073ef6

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/nixos.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,7 @@ impl OsRebuildArgs {
283283
.context("Failed to resolve switch-to-configuration path")?;
284284

285285
if !switch_to_configuration.exists() {
286-
return Err(eyre!(
287-
"The 'switch-to-configuration' binary is missing from the built \
288-
configuration.\n\nThis typically happens when 'system.switch.enable' \
289-
is set to false in your\nNixOS configuration. To fix this, please \
290-
either:\n1. Remove 'system.switch.enable = false' from your \
291-
configuration, or\n2. Set 'system.switch.enable = true' \
292-
explicitly\n\nIf the problem persists, please open an issue on our \
293-
issue tracker!"
294-
));
286+
return Err(missing_switch_to_configuration_error());
295287
}
296288

297289
let canonical_out_path =
@@ -464,15 +456,7 @@ impl OsRollbackArgs {
464456
final_profile.join("bin").join("switch-to-configuration");
465457

466458
if !switch_to_configuration.exists() {
467-
return Err(eyre!(
468-
"The 'switch-to-configuration' binary is missing from the built \
469-
configuration.\n\nThis typically happens when 'system.switch.enable' \
470-
is set to false in your\nNixOS configuration. To fix this, please \
471-
either:\n1. Remove 'system.switch.enable = false' from your \
472-
configuration, or\n2. Set 'system.switch.enable = true' \
473-
explicitly\n\nIf the problem persists, please open an issue on our \
474-
issue tracker!"
475-
));
459+
return Err(missing_switch_to_configuration_error());
476460
}
477461

478462
match Command::new(&switch_to_configuration)
@@ -643,6 +627,19 @@ fn run_vm(out_path: &Path) -> Result<()> {
643627
Ok(())
644628
}
645629

630+
/// Returns an error indicating that the 'switch-to-configuration' binary is
631+
/// missing, along with common reasons and solutions.
632+
fn missing_switch_to_configuration_error() -> color_eyre::eyre::Report {
633+
eyre!(
634+
"The 'switch-to-configuration' binary is missing from the built \
635+
configuration.\n\nThis typically happens when 'system.switch.enable' is \
636+
set to false in your\nNixOS configuration. To fix this, please \
637+
either:\n1. Remove 'system.switch.enable = false' from your \
638+
configuration, or\n2. Set 'system.switch.enable = true' explicitly\n\nIf \
639+
the problem persists, please open an issue on our issue tracker!"
640+
)
641+
}
642+
646643
/// Parses the `NH_OS_FLAKE` environment variable into an `Installable::Flake`.
647644
///
648645
/// If `NH_OS_FLAKE` is not set, it returns `Ok(None)`.

0 commit comments

Comments
 (0)