1- use std:: { env, path:: PathBuf } ;
1+ use std:: { env, fmt , path:: PathBuf } ;
22
33use color_eyre:: eyre:: { Context , bail, eyre} ;
44use tracing:: { debug, warn} ;
@@ -14,8 +14,10 @@ use crate::{
1414 DarwinReplArgs ,
1515 DarwinSubcommand ,
1616 DiffType ,
17+ NotifyAskMode ,
1718 } ,
1819 nixos:: toplevel_for,
20+ notify:: NotificationSender ,
1921 update:: update,
2022 util:: { get_hostname, print_dix_diff} ,
2123} ;
@@ -34,7 +36,7 @@ impl DarwinArgs {
3436 match self . subcommand {
3537 DarwinSubcommand :: Switch ( args) => args. rebuild ( & Switch , elevation) ,
3638 DarwinSubcommand :: Build ( args) => {
37- if args. common . ask || args. common . dry {
39+ if args. common . ask . is_some ( ) || args. common . dry {
3840 warn ! ( "`--ask` and `--dry` have no effect for `nh darwin build`" ) ;
3941 }
4042 args. rebuild ( & Build , elevation)
@@ -49,6 +51,16 @@ enum DarwinRebuildVariant {
4951 Build ,
5052}
5153
54+ impl fmt:: Display for DarwinRebuildVariant {
55+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
56+ let s = match self {
57+ DarwinRebuildVariant :: Build => "build" ,
58+ DarwinRebuildVariant :: Switch => "switch" ,
59+ } ;
60+ write ! ( f, "{s}" )
61+ }
62+ }
63+
5264impl DarwinRebuildArgs {
5365 fn rebuild (
5466 self ,
@@ -144,13 +156,27 @@ impl DarwinRebuildArgs {
144156 let _ = print_dix_diff ( & PathBuf :: from ( CURRENT_PROFILE ) , & target_profile) ;
145157 }
146158
147- if self . common . ask && !self . common . dry && !matches ! ( variant, Build ) {
148- let confirmation = inquire:: Confirm :: new ( "Apply the config?" )
149- . with_default ( false )
150- . prompt ( ) ?;
159+ if !self . common . dry && !matches ! ( variant, Build ) {
160+ if let Some ( ask) = self . common . ask {
161+ let confirmation = match ask {
162+ NotifyAskMode :: Prompt => {
163+ inquire:: Confirm :: new ( "Apply the config?" )
164+ . with_default ( false )
165+ . prompt ( ) ?
166+ } ,
167+ #[ cfg( all( unix, not( target_os = "macos" ) ) ) ]
168+ NotifyAskMode :: Notify => {
169+ NotificationSender :: new (
170+ & format ! ( "nh darwin {variant}" ) ,
171+ "Do you want to apply the Darwin configuration?" ,
172+ )
173+ . ask ( )
174+ } ,
175+ } ;
151176
152- if !confirmation {
153- bail ! ( "User rejected the new config" ) ;
177+ if !confirmation {
178+ bail ! ( "User rejected the new config" ) ;
179+ }
154180 }
155181 }
156182
0 commit comments