Skip to content

Commit 28972b6

Browse files
authored
Merge pull request #238 from khaneliman/darwin
darwin.rs: handle new root only activation
2 parents d36ff53 + 27370e0 commit 28972b6

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
support legacy/vulnerable versions of Nix, and encourage users to update if
1717
they have not yet done so.
1818

19+
### Changed
20+
21+
- Darwin: Use `darwin-rebuild` directly for activation instead of old scripts
22+
- Darwin: Future-proof handling of `activate-user` script removal
23+
- Darwin: Improve compatibility with root-only activation in newer nix-darwin versions
24+
1925
## 4.0.3
2026

2127
### Added

src/darwin.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,22 @@ impl DarwinRebuildArgs {
129129
.dry(self.common.dry)
130130
.run()?;
131131

132-
let switch_to_configuration = out_path.get_path().join("activate-user");
133-
134-
Command::new(switch_to_configuration)
135-
.message("Activating configuration for user")
136-
.dry(self.common.dry)
137-
.run()?;
138-
139-
let switch_to_configuration = out_path.get_path().join("activate");
140-
141-
Command::new(switch_to_configuration)
142-
.elevate(true)
132+
let darwin_rebuild = out_path.get_path().join("sw/bin/darwin-rebuild");
133+
let activate_user = out_path.get_path().join("activate-user");
134+
135+
// Determine if we need to elevate privileges
136+
let needs_elevation = !activate_user
137+
.try_exists()
138+
.context("Failed to check if activate-user file exists")?
139+
|| std::fs::read_to_string(&activate_user)
140+
.context("Failed to read activate-user file")?
141+
.contains("# nix-darwin: deprecated");
142+
143+
// Create and run the activation command with or without elevation
144+
Command::new(darwin_rebuild)
145+
.arg("activate")
143146
.message("Activating configuration")
147+
.elevate(needs_elevation)
144148
.dry(self.common.dry)
145149
.run()?;
146150
}

0 commit comments

Comments
 (0)