Skip to content

Commit 27370e0

Browse files
committed
darwin.rs: use darwin-rebuild
Recommended to use the darwin-rebuild activate command by maintainers.
1 parent ddf5f81 commit 27370e0

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
### Changed
2020

21+
- Darwin: Use `darwin-rebuild` directly for activation instead of old scripts
2122
- Darwin: Future-proof handling of `activate-user` script removal
2223
- Darwin: Improve compatibility with root-only activation in newer nix-darwin versions
2324

src/darwin.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,36 +126,27 @@ impl DarwinRebuildArgs {
126126
.args(["build", "--no-link", "--profile", SYSTEM_PROFILE])
127127
.arg(out_path.get_path())
128128
.elevate(true)
129-
.dry(self.common.dry);
129+
.dry(self.common.dry)
130+
.run()?;
130131

132+
let darwin_rebuild = out_path.get_path().join("sw/bin/darwin-rebuild");
131133
let activate_user = out_path.get_path().join("activate-user");
132134

133-
let user_activation = Command::new(activate_user.clone())
134-
.message("Activating configuration for user")
135-
.dry(self.common.dry);
136-
137-
let activate = out_path.get_path().join("activate");
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");
138142

139-
let activation = Command::new(activate)
140-
.elevate(true)
143+
// Create and run the activation command with or without elevation
144+
Command::new(darwin_rebuild)
145+
.arg("activate")
141146
.message("Activating configuration")
142-
.dry(self.common.dry);
143-
144-
if activate_user.exists() {
145-
// Check whether activate-user is deprecated
146-
// If it is, only activate with root
147-
if std::fs::read_to_string(&activate_user)
148-
.context("Failed to read activate-user file")?
149-
.contains("# nix-darwin: deprecated")
150-
{
151-
activation.run()?;
152-
} else {
153-
user_activation.run()?;
154-
activation.run()?;
155-
}
156-
} else {
157-
activation.run()?;
158-
}
147+
.elevate(needs_elevation)
148+
.dry(self.common.dry)
149+
.run()?;
159150
}
160151

161152
// Make sure out_path is not accidentally dropped

0 commit comments

Comments
 (0)