@@ -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