@@ -31,6 +31,7 @@ impl<W: io::Write> fmt::Write for WriteFmt<W> {
3131 self . 0 . write_all ( string. as_bytes ( ) ) . map_err ( |_| fmt:: Error )
3232 }
3333}
34+
3435/// Get the Nix variant (cached)
3536pub fn get_nix_variant ( ) -> & ' static NixVariant {
3637 NIX_VARIANT . get_or_init ( || {
@@ -320,3 +321,85 @@ pub fn print_dix_diff(old_generation: &Path, new_generation: &Path) -> Result<()
320321 }
321322 Ok ( ( ) )
322323}
324+
325+ /// Prints the difference between Homebrew packages in darwin generations.
326+ ///
327+ /// # Arguments
328+ ///
329+ /// * `old_generation` - A reference to the path of the old/current generation.
330+ /// * `new_generation` - A reference to the path of the new generation.
331+ ///
332+ /// # Returns
333+ ///
334+ /// Returns `Ok(())` if the operation completed successfully, or an error wrapped in `eyre::Result` if something went wrong.
335+ /// Silently returns Ok(()) if Homebrew is not available or not configured.
336+ #[ cfg( target_os = "macos" ) ]
337+ pub fn print_homebrew_diff ( _old_generation : & Path , new_generation : & Path ) -> Result < ( ) > {
338+ if !homebrew_available ( ) {
339+ debug ! ( "Homebrew not found, skipping Homebrew diff" ) ;
340+ return Ok ( ( ) ) ;
341+ }
342+
343+ // Try to extract the nix-darwin Homebrew intent from the new profile
344+ // If this fails, it likely means Homebrew isn't configured in the profile
345+ let nix_intent = match brewdiff:: extract_nix_darwin_intent ( new_generation) {
346+ Ok ( intent) => intent,
347+ Err ( e) => {
348+ debug ! ( "Could not extract Homebrew intent from profile: {}" , e) ;
349+ return Ok ( ( ) ) ;
350+ }
351+ } ;
352+
353+ if !nix_intent. has_packages ( ) {
354+ debug ! ( "No Homebrew packages configured in profile, skipping diff" ) ;
355+ return Ok ( ( ) ) ;
356+ }
357+
358+ let mut out = WriteFmt ( io:: stdout ( ) ) ;
359+
360+ let diff_handle = brewdiff:: spawn_homebrew_diff ( new_generation. to_path_buf ( ) ) ;
361+ let diff_data = match diff_handle. join ( ) {
362+ Ok ( Ok ( data) ) => data,
363+ Ok ( Err ( e) ) => {
364+ debug ! ( "Failed to compute Homebrew diff: {}" , e) ;
365+ return Ok ( ( ) ) ;
366+ }
367+ Err ( _) => {
368+ debug ! ( "Homebrew diff thread panicked" ) ;
369+ return Ok ( ( ) ) ;
370+ }
371+ } ;
372+
373+ if diff_data. has_changes ( ) {
374+ // Separator from dix' output
375+ println ! ( ) ;
376+
377+ // Print statistics first to make it clear the details below belong to Homebrew
378+ brewdiff:: write_homebrew_stats ( & mut out, & diff_data) ?;
379+ brewdiff:: display:: write_diff ( & mut out, & diff_data) ?;
380+ } else {
381+ debug ! ( "No Homebrew package changes detected" ) ;
382+ }
383+
384+ Ok ( ( ) )
385+ }
386+
387+ /// Checks if Homebrew is available on the system
388+ #[ cfg( target_os = "macos" ) ]
389+ fn homebrew_available ( ) -> bool {
390+ use std:: process:: Command as StdCommand ;
391+
392+ StdCommand :: new ( "which" )
393+ . arg ( "brew" )
394+ . stdout ( Stdio :: null ( ) )
395+ . stderr ( Stdio :: null ( ) )
396+ . status ( )
397+ . map ( |s| s. success ( ) )
398+ . unwrap_or ( false )
399+ }
400+
401+ /// Stub for non-macOS platforms
402+ #[ cfg( not( target_os = "macos" ) ) ]
403+ pub fn print_homebrew_diff ( _old_generation : & Path , _new_generation : & Path ) -> Result < ( ) > {
404+ Ok ( ( ) )
405+ }
0 commit comments