@@ -167,24 +167,45 @@ impl DarwinRebuildArgs {
167167 let darwin_rebuild = out_path. join ( "sw/bin/darwin-rebuild" ) ;
168168 let activate_user = out_path. join ( "activate-user" ) ;
169169
170- // Determine if we need to elevate privileges
171- let needs_elevation = !activate_user
170+ // Determine if darwin-rebuild is present, and if so, use it
171+ let has_darwin_rebuild = darwin_rebuild
172+ . try_exists ( )
173+ . context ( "Failed to check if darwin-rebuild file exists" ) ?;
174+
175+ // Determine if we need to elevate privileges and/or run the deprecated activate-user script
176+ let uses_new_activation = !activate_user
172177 . try_exists ( )
173178 . context ( "Failed to check if activate-user file exists" ) ?
174179 || std:: fs:: read_to_string ( & activate_user)
175180 . context ( "Failed to read activate-user file" ) ?
176181 . contains ( "# nix-darwin: deprecated" ) ;
177182
178- // Create and run the activation command with or without elevation
179- Command :: new ( darwin_rebuild)
180- . arg ( "activate" )
183+ let activation = if has_darwin_rebuild {
184+ Command :: new ( darwin_rebuild) . arg ( "activate" )
185+ } else {
186+ Command :: new ( out_path. join ( "activate" ) )
187+ } ;
188+
189+ let should_elevate = uses_new_activation || !has_darwin_rebuild;
190+
191+ activation
181192 . message ( "Activating configuration" )
182- . elevate ( needs_elevation . then_some ( elevation) )
193+ . elevate ( should_elevate . then_some ( elevation) )
183194 . dry ( self . common . dry )
184195 . show_output ( true )
185196 . with_required_env ( )
186197 . run ( )
187198 . wrap_err ( "Darwin activation failed" ) ?;
199+
200+ if !has_darwin_rebuild && !uses_new_activation {
201+ Command :: new ( activate_user)
202+ . message ( "Activating configuration for user" )
203+ . dry ( self . common . dry )
204+ . show_output ( true )
205+ . with_required_env ( )
206+ . run ( )
207+ . wrap_err ( "Darwin user activation failed" ) ?;
208+ }
188209 }
189210
190211 debug ! ( "Completed operation with output path: {out_path:?}" ) ;
0 commit comments