@@ -15,6 +15,7 @@ use crate::{
1515 interface:: {
1616 self ,
1717 DiffType ,
18+ NotifyAskMode ,
1819 OsBuildVmArgs ,
1920 OsGenerationsArgs ,
2021 OsRebuildArgs ,
@@ -23,6 +24,7 @@ use crate::{
2324 OsSubcommand :: { self } ,
2425 } ,
2526 nh_info,
27+ notify:: NotificationSender ,
2628 update:: update,
2729 util:: { ensure_ssh_key_login, get_hostname, print_dix_diff} ,
2830} ;
@@ -40,7 +42,7 @@ impl interface::OsArgs {
4042 OsSubcommand :: Test ( args) => args. rebuild ( & Test , None , elevation) ,
4143 OsSubcommand :: Switch ( args) => args. rebuild ( & Switch , None , elevation) ,
4244 OsSubcommand :: Build ( args) => {
43- if args. common . ask || args. common . dry {
45+ if args. common . ask . is_some ( ) || args. common . dry {
4446 warn ! ( "`--ask` and `--dry` have no effect for `nh os build`" ) ;
4547 }
4648 args. rebuild ( & Build , None , elevation)
@@ -276,7 +278,7 @@ impl OsRebuildArgs {
276278 }
277279
278280 if self . common . dry || matches ! ( variant, Build | BuildVm ) {
279- if self . common . ask {
281+ if self . common . ask . is_some ( ) {
280282 warn ! ( "--ask has no effect as dry run was requested" ) ;
281283 }
282284
@@ -288,10 +290,22 @@ impl OsRebuildArgs {
288290 return Ok ( ( ) ) ;
289291 }
290292
291- if self . common . ask {
292- let confirmation = inquire:: Confirm :: new ( "Apply the config?" )
293- . with_default ( false )
294- . prompt ( ) ?;
293+ if let Some ( ask) = & self . common . ask {
294+ let confirmation = match ask {
295+ NotifyAskMode :: Prompt => {
296+ inquire:: Confirm :: new ( "Apply the config?" )
297+ . with_default ( false )
298+ . prompt ( ) ?
299+ } ,
300+ NotifyAskMode :: Notify => {
301+ NotificationSender :: new (
302+ "nh os switch" ,
303+ "Do you want to apply the NixOS configuration?" ,
304+ )
305+ . ask ( )
306+ } ,
307+ NotifyAskMode :: Both => unimplemented ! ( ) ,
308+ } ;
295309
296310 if !confirmation {
297311 bail ! ( "User rejected the new config" ) ;
@@ -453,13 +467,25 @@ impl OsRollbackArgs {
453467 return Ok ( ( ) ) ;
454468 }
455469
456- if self . ask {
457- let confirmation = inquire:: Confirm :: new ( & format ! (
458- "Roll back to generation {}?" ,
459- target_generation. number
460- ) )
461- . with_default ( false )
462- . prompt ( ) ?;
470+ if let Some ( ask) = & self . ask {
471+ let confirmation = match ask {
472+ NotifyAskMode :: Prompt => {
473+ inquire:: Confirm :: new ( & format ! (
474+ "Roll back to generation {}?" ,
475+ target_generation. number
476+ ) )
477+ . with_default ( false )
478+ . prompt ( ) ?
479+ } ,
480+ NotifyAskMode :: Notify => {
481+ NotificationSender :: new (
482+ "nh os rollback" ,
483+ & format ! ( "Roll back to generation {}?" , target_generation. number) ,
484+ )
485+ . ask ( )
486+ } ,
487+ NotifyAskMode :: Both => unimplemented ! ( ) ,
488+ } ;
463489
464490 if !confirmation {
465491 bail ! ( "User rejected the rollback" ) ;
0 commit comments