1
- use std:: { env, path:: PathBuf } ;
1
+ use std:: { env, fmt , path:: PathBuf } ;
2
2
3
3
use color_eyre:: eyre:: { Context , bail, eyre} ;
4
4
use tracing:: { debug, warn} ;
5
5
6
6
use crate :: {
7
7
Result ,
8
- commands,
9
- commands:: { Command , ElevationStrategy } ,
8
+ commands:: { self , Command , ElevationStrategy } ,
10
9
installable:: Installable ,
11
10
interface:: {
12
11
DarwinArgs ,
13
12
DarwinRebuildArgs ,
14
13
DarwinReplArgs ,
15
14
DarwinSubcommand ,
16
15
DiffType ,
16
+ NotifyAskMode ,
17
17
} ,
18
18
nixos:: toplevel_for,
19
+ notify:: NotificationSender ,
19
20
update:: update,
20
21
util:: { get_hostname, print_dix_diff} ,
21
22
} ;
@@ -34,7 +35,7 @@ impl DarwinArgs {
34
35
match self . subcommand {
35
36
DarwinSubcommand :: Switch ( args) => args. rebuild ( & Switch , elevation) ,
36
37
DarwinSubcommand :: Build ( args) => {
37
- if args. common . ask || args. common . dry {
38
+ if args. common . ask . is_some ( ) || args. common . dry {
38
39
warn ! ( "`--ask` and `--dry` have no effect for `nh darwin build`" ) ;
39
40
}
40
41
args. rebuild ( & Build , elevation)
@@ -49,6 +50,16 @@ enum DarwinRebuildVariant {
49
50
Build ,
50
51
}
51
52
53
+ impl fmt:: Display for DarwinRebuildVariant {
54
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
55
+ let s = match self {
56
+ DarwinRebuildVariant :: Build => "build" ,
57
+ DarwinRebuildVariant :: Switch => "switch" ,
58
+ } ;
59
+ write ! ( f, "{s}" )
60
+ }
61
+ }
62
+
52
63
impl DarwinRebuildArgs {
53
64
fn rebuild (
54
65
self ,
@@ -144,13 +155,29 @@ impl DarwinRebuildArgs {
144
155
let _ = print_dix_diff ( & PathBuf :: from ( CURRENT_PROFILE ) , & target_profile) ;
145
156
}
146
157
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 ( ) ?;
158
+ if !self . common . dry && !matches ! ( variant, Build ) {
159
+ if let Some ( ask) = self . common . ask {
160
+ let confirmation = match ask {
161
+ NotifyAskMode :: Prompt => {
162
+ inquire:: Confirm :: new ( "Apply the config?" )
163
+ . with_default ( false )
164
+ . prompt ( ) ?
165
+ } ,
166
+ // MacOS doesn't support notification actions
167
+ NotifyAskMode :: Notify | NotifyAskMode :: Both => {
168
+ NotificationSender :: new ( & format ! ( "nh darwin {variant}" ) , "testing" )
169
+ . send ( )
170
+ . unwrap ( ) ;
171
+
172
+ inquire:: Confirm :: new ( "Apply the config?" )
173
+ . with_default ( false )
174
+ . prompt ( ) ?
175
+ } ,
176
+ } ;
151
177
152
- if !confirmation {
153
- bail ! ( "User rejected the new config" ) ;
178
+ if !confirmation {
179
+ bail ! ( "User rejected the new config" ) ;
180
+ }
154
181
}
155
182
}
156
183
0 commit comments