@@ -135,36 +135,29 @@ impl DarwinRebuildArgs {
135
135
. args ( [ "build" , "--no-link" , "--profile" , SYSTEM_PROFILE ] )
136
136
. arg ( out_path. get_path ( ) )
137
137
. elevate ( true )
138
- . dry ( self . common . dry ) ;
138
+ . dry ( self . common . dry )
139
+ . run ( ) ?;
139
140
141
+ let darwin_rebuild = out_path. get_path ( ) . join ( "sw/bin/darwin-rebuild" ) ;
140
142
let activate_user = out_path. get_path ( ) . join ( "activate-user" ) ;
141
143
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 ") ;
147
149
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" )
150
153
. message ( "Activating configuration" )
151
154
. dry ( self . common . dry ) ;
152
155
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 ) ;
167
158
}
159
+
160
+ activation. run ( ) ?;
168
161
}
169
162
170
163
// Make sure out_path is not accidentally dropped
0 commit comments