Skip to content

Commit 34da5b0

Browse files
committed
darwin: fix activation without darwin-rebuild
1 parent 440d3a6 commit 34da5b0

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ be put in the "Changed" section or, if it's just to remove code or
1414
functionality, under the "Removed" section.
1515
-->
1616

17+
## Unreleased
18+
19+
### Fixed
20+
21+
- Darwin: fall back to directly executing `activate` (and `activate-user` if
22+
applicable) if `darwin-rebuild` does not exist.
23+
1724
## 4.2.0
1825

1926
### Changed

src/darwin.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,45 @@ impl DarwinRebuildArgs {
167167
let darwin_rebuild = out_path.join("sw/bin/darwin-rebuild");
168168
let activate_user = out_path.join("activate-user");
169169

170-
// Determine if we need to elevate privileges
171-
let needs_elevation = !activate_user
170+
// Determine if darwin-rebuild is present, and if so, use it
171+
let has_darwin_rebuild = darwin_rebuild
172+
.try_exists()
173+
.context("Failed to check if darwin-rebuild file exists")?;
174+
175+
// Determine if we need to elevate privileges and/or run the deprecated activate-user script
176+
let uses_new_activation = !activate_user
172177
.try_exists()
173178
.context("Failed to check if activate-user file exists")?
174179
|| std::fs::read_to_string(&activate_user)
175180
.context("Failed to read activate-user file")?
176181
.contains("# nix-darwin: deprecated");
177182

178-
// Create and run the activation command with or without elevation
179-
Command::new(darwin_rebuild)
180-
.arg("activate")
183+
let activation = if has_darwin_rebuild {
184+
Command::new(darwin_rebuild).arg("activate")
185+
} else {
186+
Command::new(out_path.join("activate"))
187+
};
188+
189+
let should_elevate = uses_new_activation || !has_darwin_rebuild;
190+
191+
activation
181192
.message("Activating configuration")
182-
.elevate(needs_elevation.then_some(elevation))
193+
.elevate(should_elevate.then_some(elevation))
183194
.dry(self.common.dry)
184195
.show_output(true)
185196
.with_required_env()
186197
.run()
187198
.wrap_err("Darwin activation failed")?;
199+
200+
if !has_darwin_rebuild && !uses_new_activation {
201+
Command::new(activate_user)
202+
.message("Activating configuration for user")
203+
.dry(self.common.dry)
204+
.show_output(true)
205+
.with_required_env()
206+
.run()
207+
.wrap_err("Darwin user activation failed")?;
208+
}
188209
}
189210

190211
debug!("Completed operation with output path: {out_path:?}");

0 commit comments

Comments
 (0)