@@ -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 => return Err ( RunDeployError :: NodeNotFound ( node_name. clone ( ) ) ) ,
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. clone ( ) ) ) ,
283
226
} ;
@@ -304,13 +247,13 @@ async fn run_deploy(
304
247
305
248
profiles_list
306
249
. into_iter ( )
307
- . map ( |x| ( deploy_target , data , ( node_name. as_str ( ) , node) , x) )
250
+ . map ( |x| ( target , root , ( node_name. as_str ( ) , node) , x) )
308
251
. collect ( )
309
252
}
310
253
( None , None ) => {
311
254
let mut l = Vec :: new ( ) ;
312
255
313
- for ( node_name, node) in & data . nodes {
256
+ for ( node_name, node) in & root . nodes {
314
257
let mut profiles_list: Vec < ( & str , & settings:: Profile ) > = Vec :: new ( ) ;
315
258
316
259
for profile_name in [
@@ -335,7 +278,7 @@ async fn run_deploy(
335
278
336
279
let ll: ToDeploy = profiles_list
337
280
. into_iter ( )
338
- . map ( |x| ( deploy_target , data , ( node_name. as_str ( ) , node) , x) )
281
+ . map ( |x| ( target , root , ( node_name. as_str ( ) , node) , x) )
339
282
. collect ( ) ;
340
283
341
284
l. extend ( ll) ;
@@ -358,39 +301,39 @@ async fn run_deploy(
358
301
data:: DeployDefs ,
359
302
) > = Vec :: new ( ) ;
360
303
361
- for ( deploy_target , data , ( node_name, node) , ( profile_name, profile) ) in to_deploy {
304
+ for ( target , root , ( node_name, node) , ( profile_name, profile) ) in to_deploy {
362
305
let deploy_data = data:: make_deploy_data (
363
- & data. generic_settings ,
306
+ & root. generic_settings ,
307
+ & cmd_settings,
308
+ & cmd_flags,
364
309
node,
365
310
node_name,
366
311
profile,
367
312
profile_name,
368
- cmd_overrides,
369
- debug_logs,
370
- log_dir. as_deref ( ) ,
313
+ hostname. as_deref ( ) ,
371
314
) ;
372
315
373
316
let deploy_defs = deploy_data. defs ( ) ?;
374
317
375
- parts. push ( ( deploy_target , deploy_data, deploy_defs) ) ;
318
+ parts. push ( ( target , deploy_data, deploy_defs) ) ;
376
319
}
377
320
378
- if interactive {
321
+ if cmd_flags . interactive {
379
322
prompt_deployment ( & parts[ ..] ) ?;
380
323
} else {
381
324
print_deployment ( & parts[ ..] ) ?;
382
325
}
383
326
384
- for ( deploy_target , deploy_data, deploy_defs) in & parts {
327
+ for ( target , deploy_data, deploy_defs) in & parts {
385
328
deploy:: push:: push_profile ( deploy:: push:: PushProfileData {
386
- supports_flakes,
387
- check_sigs,
388
- repo : & deploy_target . repo ,
389
- deploy_data,
390
- deploy_defs,
391
- keep_result,
392
- result_path,
393
- extra_build_args,
329
+ supports_flakes : & supports_flakes ,
330
+ check_sigs : & cmd_flags . checksigs ,
331
+ repo : & target . repo ,
332
+ deploy_data : & deploy_data ,
333
+ deploy_defs : & deploy_defs ,
334
+ keep_result : & cmd_flags . keep_result ,
335
+ result_path : cmd_flags . result_path . as_deref ( ) ,
336
+ extra_build_args : & cmd_flags . extra_build_args ,
394
337
} )
395
338
. await ?;
396
339
}
@@ -402,14 +345,14 @@ async fn run_deploy(
402
345
// Rollbacks adhere to the global seeting to auto_rollback and secondary
403
346
// the profile's configuration
404
347
for ( _, deploy_data, deploy_defs) in & parts {
405
- if let Err ( e) = deploy:: deploy:: deploy_profile ( deploy_data, deploy_defs, dry_activate) . await
348
+ if let Err ( e) = deploy:: deploy:: deploy_profile ( deploy_data, deploy_defs, cmd_flags . dry_activate ) . await
406
349
{
407
350
error ! ( "{}" , e) ;
408
- if dry_activate {
351
+ if cmd_flags . dry_activate {
409
352
info ! ( "dry run, not rolling back" ) ;
410
353
}
411
354
info ! ( "Revoking previous deploys" ) ;
412
- if rollback_succeeded && cmd_overrides . auto_rollback . unwrap_or ( true ) {
355
+ if cmd_flags . rollback_succeeded && cmd_settings . auto_rollback . unwrap_or ( true ) {
413
356
// revoking all previous deploys
414
357
// (adheres to profile configuration if not set explicitely by
415
358
// the command line)
@@ -454,8 +397,8 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
454
397
} ;
455
398
456
399
deploy:: init_logger (
457
- opts. debug_logs ,
458
- opts. log_dir . as_deref ( ) ,
400
+ opts. flags . debug_logs ,
401
+ opts. flags . log_dir . as_deref ( ) ,
459
402
& deploy:: LoggerType :: Deploy ,
460
403
) ?;
461
404
@@ -464,51 +407,30 @@ pub async fn run(args: Option<&ArgMatches>) -> Result<(), RunError> {
464
407
. targets
465
408
. unwrap_or_else ( || vec ! [ opts. clone( ) . target. unwrap_or_else( || "." . to_string( ) ) ] ) ;
466
409
467
- let deploy_targets: Vec < data:: Target > = deploys
468
- . iter ( )
469
- . map ( |f| f. parse :: < data:: Target > ( ) )
470
- . collect :: < Result < Vec < data:: Target > , data:: ParseTargetError > > ( ) ?;
471
-
472
- let cmd_overrides = data:: CmdOverrides {
473
- ssh_user : opts. ssh_user ,
474
- profile_user : opts. profile_user ,
475
- ssh_opts : opts. ssh_opts ,
476
- fast_connection : opts. fast_connection ,
477
- auto_rollback : opts. auto_rollback ,
478
- hostname : opts. hostname ,
479
- magic_rollback : opts. magic_rollback ,
480
- temp_path : opts. temp_path ,
481
- confirm_timeout : opts. confirm_timeout ,
482
- dry_activate : opts. dry_activate ,
483
- } ;
484
-
485
410
let supports_flakes = test_flake_support ( ) . await . map_err ( RunError :: FlakeTest ) ?;
486
411
487
412
if !supports_flakes {
488
413
warn ! ( "A Nix version without flakes support was detected, support for this is work in progress" ) ;
489
414
}
490
415
491
- if !opts. skip_checks {
492
- for deploy_target in deploy_targets. iter ( ) {
493
- flake:: check_deployment ( supports_flakes, & deploy_target. repo , & opts. extra_build_args ) . await ?;
416
+ let targets: Vec < data:: Target > = deploys
417
+ . into_iter ( )
418
+ . map ( |f| f. parse :: < data:: Target > ( ) )
419
+ . collect :: < Result < Vec < data:: Target > , data:: ParseTargetError > > ( ) ?;
420
+
421
+ if !opts. flags . skip_checks {
422
+ for target in targets. iter ( ) {
423
+ flake:: check_deployment ( supports_flakes, & target. repo , & opts. flags . extra_build_args ) . await ?;
494
424
}
495
425
}
496
- let result_path = opts. result_path . as_deref ( ) ;
497
- let data = flake:: get_deployment_data ( supports_flakes, & deploy_targets, & opts. extra_build_args ) . await ?;
426
+ let settings = flake:: get_deployment_data ( supports_flakes, & targets, & opts. flags . extra_build_args ) . await ?;
498
427
run_deploy (
499
- deploy_targets ,
500
- data ,
428
+ targets ,
429
+ settings ,
501
430
supports_flakes,
502
- opts. checksigs ,
503
- opts. interactive ,
504
- & cmd_overrides,
505
- opts. keep_result ,
506
- result_path,
507
- & opts. extra_build_args ,
508
- opts. debug_logs ,
509
- opts. dry_activate ,
510
- & opts. log_dir ,
511
- opts. rollback_succeeded . unwrap_or ( true ) ,
431
+ opts. hostname ,
432
+ opts. generic_settings ,
433
+ opts. flags ,
512
434
)
513
435
. await ?;
514
436
0 commit comments