Skip to content

Commit cdc466c

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

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/darwin.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,29 @@ impl DarwinRebuildArgs {
135135
.args(["build", "--no-link", "--profile", SYSTEM_PROFILE])
136136
.arg(out_path.get_path())
137137
.elevate(true)
138-
.dry(self.common.dry);
138+
.dry(self.common.dry)
139+
.run()?;
139140

141+
let darwin_rebuild = out_path.get_path().join("sw/bin/darwin-rebuild");
140142
let activate_user = out_path.get_path().join("activate-user");
141143

142-
let user_activation = Command::new(activate_user.clone())
143-
.message("Activating configuration for user")
144-
.dry(self.common.dry);
145-
146-
let activate = out_path.get_path().join("activate");
144+
// Determine if we need to elevate privileges
145+
let needs_elevation = !activate_user.exists()
146+
|| std::fs::read_to_string(&activate_user)
147+
.context("Failed to read activate-user file")?
148+
.contains("# nix-darwin: deprecated");
147149

148-
let activation = Command::new(activate)
149-
.elevate(true)
150+
// Create and run the activation command with or without elevation
151+
let mut activation = Command::new(darwin_rebuild)
152+
.arg("activate")
150153
.message("Activating configuration")
151154
.dry(self.common.dry);
152155

153-
if activate_user.exists() {
154-
// Check whether activate-user is deprecated
155-
// If it is, only activate with root
156-
if std::fs::read_to_string(&activate_user)
157-
.context("Failed to read activate-user file")?
158-
.contains("# nix-darwin: deprecated")
159-
{
160-
activation.run()?;
161-
} else {
162-
user_activation.run()?;
163-
activation.run()?;
164-
}
165-
} else {
166-
activation.run()?;
156+
if needs_elevation {
157+
activation = activation.elevate(true);
167158
}
159+
160+
activation.run()?;
168161
}
169162

170163
// Make sure out_path is not accidentally dropped

0 commit comments

Comments
 (0)