@@ -167,24 +167,46 @@ 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
176+ // activate-user script
177+ let uses_new_activation = !activate_user
172178 . try_exists ( )
173179 . context ( "Failed to check if activate-user file exists" ) ?
174180 || std:: fs:: read_to_string ( & activate_user)
175181 . context ( "Failed to read activate-user file" ) ?
176182 . contains ( "# nix-darwin: deprecated" ) ;
177183
178- // Create and run the activation command with or without elevation
179- Command :: new ( darwin_rebuild)
180- . arg ( "activate" )
184+ let activation = if has_darwin_rebuild {
185+ Command :: new ( darwin_rebuild) . arg ( "activate" )
186+ } else {
187+ Command :: new ( out_path. join ( "activate" ) )
188+ } ;
189+
190+ let should_elevate = uses_new_activation || !has_darwin_rebuild;
191+
192+ activation
181193 . message ( "Activating configuration" )
182- . elevate ( needs_elevation . then_some ( elevation) )
194+ . elevate ( should_elevate . then_some ( elevation) )
183195 . dry ( self . common . dry )
184196 . show_output ( true )
185197 . with_required_env ( )
186198 . run ( )
187199 . wrap_err ( "Darwin activation failed" ) ?;
200+
201+ if !has_darwin_rebuild && !uses_new_activation {
202+ Command :: new ( activate_user)
203+ . message ( "Activating configuration for user" )
204+ . dry ( self . common . dry )
205+ . show_output ( true )
206+ . with_required_env ( )
207+ . run ( )
208+ . wrap_err ( "Darwin user activation failed" ) ?;
209+ }
188210 }
189211
190212 debug ! ( "Completed operation with output path: {out_path:?}" ) ;
0 commit comments