Skip to content

Commit 503409a

Browse files
authored
Merge pull request #548 from nix-community/faukah/push-onwzylwrwkkl
{home, nixos}: prefer `--specialisation` command line flag over current specialisation
2 parents fed7e0c + a5021b4 commit 503409a

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

src/home.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl HomeRebuildArgs {
176176
let target_specialisation = if self.no_specialisation {
177177
None
178178
} else {
179-
current_specialisation.or(self.specialisation)
179+
self.specialisation.or(current_specialisation)
180180
};
181181

182182
debug!("target_specialisation: {target_specialisation:?}");

src/nixos.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -575,35 +575,39 @@ impl OsRebuildArgs {
575575
let target_specialisation = if self.no_specialisation {
576576
None
577577
} else {
578-
current_specialisation.or_else(|| self.specialisation.clone())
578+
self.specialisation.clone().or(current_specialisation)
579579
};
580580

581581
debug!("Target specialisation: {target_specialisation:?}");
582582

583-
let target_profile = target_specialisation.as_ref().map_or_else(
584-
|| out_path.to_path_buf(),
585-
|spec| out_path.join("specialisation").join(spec),
586-
);
583+
// Determine target profile, falling back to base if specialisation doesn't
584+
// exist
585+
let target_profile = match &target_specialisation {
586+
None => out_path.to_path_buf(),
587+
Some(spec) => {
588+
let spec_path = out_path.join("specialisation").join(spec);
589+
590+
// For local builds, check if specialisation exists and fall back if not
591+
if out_path.exists() && !spec_path.exists() {
592+
bail!(
593+
"Specialisation '{}' does not exist in the built configuration",
594+
spec
595+
);
596+
}
597+
598+
spec_path
599+
},
600+
};
587601

588602
debug!("Output path: {out_path:?}");
589603
debug!("Target profile path: {}", target_profile.display());
590604

591-
// If out_path doesn't exist locally, assume it's remote and skip existence
592-
// check
593-
if out_path.exists() {
594-
debug!("Target profile exists: {}", target_profile.exists());
595-
596-
if !target_profile
597-
.try_exists()
598-
.context("Failed to check if target profile exists")?
599-
{
600-
return Err(eyre!(
601-
"Target profile path does not exist: {}",
602-
target_profile.display()
603-
));
604-
}
605-
} else {
606-
debug!("Output path is remote, skipping local existence check");
605+
// Validate the final target profile exists if it's a local build
606+
if out_path.exists() && !target_profile.exists() {
607+
return Err(eyre!(
608+
"Target profile path does not exist: {}",
609+
target_profile.display()
610+
));
607611
}
608612

609613
Ok(target_profile)

0 commit comments

Comments
 (0)