Skip to content

Commit a7e5346

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

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-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: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,46 @@ 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
176+
// activate-user script
177+
let uses_new_activation = !activate_user
172178
.try_exists()
173179
.context("Failed to check if activate-user file exists")?
174180
|| std::fs::read_to_string(&activate_user)
175181
.context("Failed to read activate-user file")?
176182
.contains("# nix-darwin: deprecated");
177183

178-
// Create and run the activation command with or without elevation
179-
Command::new(darwin_rebuild)
180-
.arg("activate")
184+
let activation = if has_darwin_rebuild {
185+
Command::new(darwin_rebuild).arg("activate")
186+
} else {
187+
Command::new(out_path.join("activate"))
188+
};
189+
190+
let should_elevate = uses_new_activation || !has_darwin_rebuild;
191+
192+
activation
181193
.message("Activating configuration")
182-
.elevate(needs_elevation.then_some(elevation))
194+
.elevate(should_elevate.then_some(elevation))
183195
.dry(self.common.dry)
184196
.show_output(true)
185197
.with_required_env()
186198
.run()
187199
.wrap_err("Darwin activation failed")?;
200+
201+
if !has_darwin_rebuild && !uses_new_activation {
202+
Command::new(activate_user)
203+
.message("Activating configuration for user")
204+
.dry(self.common.dry)
205+
.show_output(true)
206+
.with_required_env()
207+
.run()
208+
.wrap_err("Darwin user activation failed")?;
209+
}
188210
}
189211

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

0 commit comments

Comments
 (0)