@@ -28,66 +28,16 @@ pub struct Opts {
28
28
/// A list of flakes to deploy alternatively
29
29
#[ clap( long, group = "deploy" ) ]
30
30
targets : Option < Vec < String > > ,
31
- /// Check signatures when using `nix copy`
32
- #[ clap( short, long) ]
33
- checksigs : bool ,
34
- /// Use the interactive prompt before deployment
35
- #[ clap( short, long) ]
36
- interactive : bool ,
37
- /// Extra arguments to be passed to nix build
38
- extra_build_args : Vec < String > ,
39
-
40
- /// Print debug logs to output
41
- #[ clap( short, long) ]
42
- debug_logs : bool ,
43
- /// Directory to print logs to (including the background activation process)
44
- #[ clap( long) ]
45
- log_dir : Option < String > ,
46
-
47
- /// Keep the build outputs of each built profile
48
- #[ clap( short, long) ]
49
- keep_result : bool ,
50
- /// Location to keep outputs from built profiles in
51
- #[ clap( short, long) ]
52
- result_path : Option < String > ,
53
31
54
- /// Skip the automatic pre-build checks
55
- #[ clap( short, long) ]
56
- skip_checks : bool ,
57
-
58
- /// Override the SSH user with the given value
59
- #[ clap( long) ]
60
- ssh_user : Option < String > ,
61
- /// Override the profile user with the given value
62
- #[ clap( long) ]
63
- profile_user : Option < String > ,
64
- /// Override the SSH options used
65
- #[ clap( long) ]
66
- ssh_opts : Option < String > ,
67
- /// Override if the connecting to the target node should be considered fast
68
- #[ clap( long) ]
69
- fast_connection : Option < bool > ,
70
- /// Override if a rollback should be attempted if activation fails
71
- #[ clap( long) ]
72
- auto_rollback : Option < bool > ,
73
32
/// Override hostname used for the node
74
33
#[ clap( long) ]
75
34
hostname : Option < String > ,
76
- /// Make activation wait for confirmation, or roll back after a period of time
77
- #[ clap( long) ]
78
- magic_rollback : Option < bool > ,
79
- /// How long activation should wait for confirmation (if using magic-rollback)
80
- #[ clap( long) ]
81
- confirm_timeout : Option < u16 > ,
82
- /// Where to store temporary files (only used by magic-rollback)
83
- #[ clap( long) ]
84
- temp_path : Option < String > ,
85
- /// Show what will be activated on the machines
86
- #[ clap( long) ]
87
- dry_activate : bool ,
88
- /// Revoke all previously succeeded deploys when deploying multiple profiles
89
- #[ clap( long) ]
90
- rollback_succeeded : Option < bool > ,
35
+
36
+ #[ clap( flatten) ]
37
+ flags : data:: Flags ,
38
+
39
+ #[ clap( flatten) ]
40
+ generic_settings : settings:: GenericSettings ,
91
41
}
92
42
93
43
/// Returns if the available Nix installation supports flakes
@@ -240,27 +190,20 @@ type ToDeploy<'a> = Vec<(
240
190
) > ;
241
191
242
192
async fn run_deploy (
243
- deploy_targets : Vec < data:: Target > ,
244
- data : Vec < settings:: Root > ,
193
+ targets : Vec < data:: Target > ,
194
+ settings : Vec < settings:: Root > ,
245
195
supports_flakes : bool ,
246
- check_sigs : bool ,
247
- interactive : bool ,
248
- cmd_overrides : & data:: CmdOverrides ,
249
- keep_result : bool ,
250
- result_path : Option < & str > ,
251
- extra_build_args : & [ String ] ,
252
- debug_logs : bool ,
253
- dry_activate : bool ,
254
- log_dir : & Option < String > ,
255
- rollback_succeeded : bool ,
196
+ hostname : Option < String > ,
197
+ cmd_settings : settings:: GenericSettings ,
198
+ cmd_flags : data:: Flags ,
256
199
) -> Result < ( ) , RunDeployError > {
257
- let to_deploy: ToDeploy = deploy_targets
200
+ let to_deploy: ToDeploy = targets
258
201
. iter ( )
259
- . zip ( & data )
260
- . map ( |( deploy_target , data ) | {
261
- let to_deploys: ToDeploy = match ( & deploy_target . node , & deploy_target . profile ) {
202
+ . zip ( & settings )
203
+ . map ( |( target , root ) | {
204
+ let to_deploys: ToDeploy = match ( & target . node , & target . profile ) {
262
205
( Some ( node_name) , Some ( profile_name) ) => {
263
- let node = match data . nodes . get ( node_name) {
206
+ let node = match root . nodes . get ( node_name) {
264
207
Some ( x) => x,
265
208
None => Err ( RunDeployError :: NodeNotFound ( node_name. to_owned ( ) ) ) ?,
266
209
} ;
@@ -270,14 +213,14 @@ async fn run_deploy(
270
213
} ;
271
214
272
215
vec ! [ (
273
- & deploy_target ,
274
- & data ,
216
+ & target ,
217
+ & root ,
275
218
( node_name. as_str( ) , node) ,
276
219
( profile_name. as_str( ) , profile) ,
277
220
) ]
278
221
}
279
222
( Some ( node_name) , None ) => {
280
- let node = match data . nodes . get ( node_name) {
223
+ let node = match root . nodes . get ( node_name) {
281
224
Some ( x) => x,
282
225
None => return Err ( RunDeployError :: NodeNotFound ( node_name. to_owned ( ) ) ) ,
283
226
} ;
@@ -306,13 +249,13 @@ async fn run_deploy(
306
249
307
250
profiles_list
308
251
. into_iter ( )
309
- . map ( |x| ( deploy_target , data , ( node_name. as_str ( ) , node) , x) )
252
+ . map ( |x| ( target , root , ( node_name. as_str ( ) , node) , x) )
310
253
. collect ( )
311
254
}
312
255
( None , None ) => {
313
256
let mut l = Vec :: new ( ) ;
314
257
315
- for ( node_name, node) in & data . nodes {
258
+ for ( node_name, node) in & root . nodes {
316
259
let mut profiles_list: Vec < ( & str , & settings:: Profile ) > = Vec :: new ( ) ;
317
260
318
261
for profile_name in [
@@ -337,7 +280,7 @@ async fn run_deploy(
337
280
338
281
let ll: ToDeploy = profiles_list
339
282
. into_iter ( )
340
- . map ( |x| ( deploy_target , data , ( node_name. as_str ( ) , node) , x) )
283
+ . map ( |x| ( target , root , ( node_name. as_str ( ) , node) , x) )
341
284
. collect ( ) ;
342
285
343
286
l. extend ( ll) ;
@@ -360,39 +303,39 @@ async fn run_deploy(
360
303
data:: DeployDefs ,
361
304
) > = Vec :: new ( ) ;
362
305
363
- for ( deploy_target , data , ( node_name, node) , ( profile_name, profile) ) in to_deploy {
306
+ for ( target , root , ( node_name, node) , ( profile_name, profile) ) in to_deploy {
364
307
let deploy_data = data:: make_deploy_data (
365
- & data. generic_settings ,
308
+ & root. generic_settings ,
309
+ & cmd_settings,
310
+ & cmd_flags,
366
311
node,
367
312
node_name,
368
313
profile,
369
314
profile_name,
370
- & cmd_overrides,
371
- debug_logs,
372
- log_dir. as_deref ( ) ,
315
+ hostname. as_deref ( ) ,
373
316
) ;
374
317
375
318
let deploy_defs = deploy_data. defs ( ) ?;
376
319
377
- parts. push ( ( deploy_target , deploy_data, deploy_defs) ) ;
320
+ parts. push ( ( target , deploy_data, deploy_defs) ) ;
378
321
}
379
322
380
- if interactive {
323
+ if cmd_flags . interactive {
381
324
prompt_deployment ( & parts[ ..] ) ?;
382
325
} else {
383
326
print_deployment ( & parts[ ..] ) ?;
384
327
}
385
328
386
- for ( deploy_target , deploy_data, deploy_defs) in & parts {
329
+ for ( target , deploy_data, deploy_defs) in & parts {
387
330
deploy:: push:: push_profile ( deploy:: push:: PushProfileData {
388
- supports_flakes,
389
- check_sigs,
390
- repo : & deploy_target . repo ,
331
+ supports_flakes : & supports_flakes ,
332
+ check_sigs : & cmd_flags . checksigs ,
333
+ repo : & target . repo ,
391
334
deploy_data : & deploy_data,
392
335
deploy_defs : & deploy_defs,
393
- keep_result,
394
- result_path,
395
- extra_build_args,
336
+ keep_result : & cmd_flags . keep_result ,
337
+ result_path : cmd_flags . result_path . as_deref ( ) ,
338
+ extra_build_args : & cmd_flags . extra_build_args ,
396
339
} )
397
340
. await ?;
398
341
}
@@ -404,14 +347,14 @@ async fn run_deploy(
404
347
// Rollbacks adhere to the global seeting to auto_rollback and secondary
405
348
// the profile's configuration
406
349
for ( _, deploy_data, deploy_defs) in & parts {
407
- if let Err ( e) = deploy:: deploy:: deploy_profile ( deploy_data, deploy_defs, dry_activate) . await
350
+ if let Err ( e) = deploy:: deploy:: deploy_profile ( deploy_data, deploy_defs, cmd_flags . dry_activate ) . await
408
351
{
409
352
error ! ( "{}" , e) ;
410
- if dry_activate {
353
+ if cmd_flags . dry_activate {
411
354
info ! ( "dry run, not rolling back" ) ;
412
355
}
413
356
info ! ( "Revoking previous deploys" ) ;
414
- if rollback_succeeded && cmd_overrides . auto_rollback . unwrap_or ( true ) {
357
+ if cmd_flags . rollback_succeeded && cmd_settings . auto_rollback . unwrap_or ( true ) {
415
358
// revoking all previous deploys
416
359
// (adheres to profile configuration if not set explicitely by
417
360
// the command line)
@@ -456,8 +399,8 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
456
399
} ;
457
400
458
401
deploy:: init_logger (
459
- opts. debug_logs ,
460
- opts. log_dir . as_deref ( ) ,
402
+ opts. flags . debug_logs ,
403
+ opts. flags . log_dir . as_deref ( ) ,
461
404
deploy:: LoggerType :: Deploy ,
462
405
) ?;
463
406
@@ -466,51 +409,30 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
466
409
. targets
467
410
. unwrap_or_else ( || vec ! [ opts. clone( ) . target. unwrap_or( "." . to_string( ) ) ] ) ;
468
411
469
- let deploy_targets: Vec < data:: Target > = deploys
470
- . into_iter ( )
471
- . map ( |f| f. parse :: < data:: Target > ( ) )
472
- . collect :: < Result < Vec < data:: Target > , data:: ParseTargetError > > ( ) ?;
473
-
474
- let cmd_overrides = data:: CmdOverrides {
475
- ssh_user : opts. ssh_user ,
476
- profile_user : opts. profile_user ,
477
- ssh_opts : opts. ssh_opts ,
478
- fast_connection : opts. fast_connection ,
479
- auto_rollback : opts. auto_rollback ,
480
- hostname : opts. hostname ,
481
- magic_rollback : opts. magic_rollback ,
482
- temp_path : opts. temp_path ,
483
- confirm_timeout : opts. confirm_timeout ,
484
- dry_activate : opts. dry_activate ,
485
- } ;
486
-
487
412
let supports_flakes = test_flake_support ( ) . await . map_err ( RunError :: FlakeTest ) ?;
488
413
489
414
if !supports_flakes {
490
415
warn ! ( "A Nix version without flakes support was detected, support for this is work in progress" ) ;
491
416
}
492
417
493
- if !opts. skip_checks {
494
- for deploy_target in deploy_targets. iter ( ) {
495
- flake:: check_deployment ( supports_flakes, & deploy_target. repo , & opts. extra_build_args ) . await ?;
418
+ let targets: Vec < data:: Target > = deploys
419
+ . into_iter ( )
420
+ . map ( |f| f. parse :: < data:: Target > ( ) )
421
+ . collect :: < Result < Vec < data:: Target > , data:: ParseTargetError > > ( ) ?;
422
+
423
+ if !opts. flags . skip_checks {
424
+ for target in targets. iter ( ) {
425
+ flake:: check_deployment ( supports_flakes, & target. repo , & opts. flags . extra_build_args ) . await ?;
496
426
}
497
427
}
498
- let result_path = opts. result_path . as_deref ( ) ;
499
- let data = flake:: get_deployment_data ( supports_flakes, & deploy_targets, & opts. extra_build_args ) . await ?;
428
+ let settings = flake:: get_deployment_data ( supports_flakes, & targets, & opts. flags . extra_build_args ) . await ?;
500
429
run_deploy (
501
- deploy_targets ,
502
- data ,
430
+ targets ,
431
+ settings ,
503
432
supports_flakes,
504
- opts. checksigs ,
505
- opts. interactive ,
506
- & cmd_overrides,
507
- opts. keep_result ,
508
- result_path,
509
- & opts. extra_build_args ,
510
- opts. debug_logs ,
511
- opts. dry_activate ,
512
- & opts. log_dir ,
513
- opts. rollback_succeeded . unwrap_or ( true ) ,
433
+ opts. hostname ,
434
+ opts. generic_settings ,
435
+ opts. flags ,
514
436
)
515
437
. await ?;
516
438
0 commit comments