@@ -135,36 +135,25 @@ 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+ Command :: new ( darwin_rebuild)
152+ . arg ( "activate" )
150153 . message ( "Activating configuration" )
151- . dry ( self . common . dry ) ;
152-
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 ( ) ?;
167- }
154+ . elevate ( needs_elevation)
155+ . dry ( self . common . dry )
156+ . run ( ) ?;
168157 }
169158
170159 // Make sure out_path is not accidentally dropped
0 commit comments