@@ -90,6 +90,10 @@ struct ActivateOpts {
90
90
/// Path for any temporary files that may be needed during activation
91
91
#[ arg( long) ]
92
92
temp_path : PathBuf ,
93
+
94
+ /// Path to where the nix-store and nix-env binaries are stored
95
+ #[ arg( long) ]
96
+ bin_path : Option < PathBuf > ,
93
97
}
94
98
95
99
/// Wait for profile activation
@@ -119,6 +123,10 @@ struct RevokeOpts {
119
123
/// The profile name
120
124
#[ arg( long, requires = "profile_user" ) ]
121
125
profile_name : Option < String > ,
126
+
127
+ /// Path to where the nix-store and nix-env binaries are stored
128
+ #[ arg( long) ]
129
+ bin_path : Option < PathBuf > ,
122
130
}
123
131
124
132
#[ derive( Error , Debug ) ]
@@ -143,10 +151,17 @@ pub enum DeactivateError {
143
151
ReactivateExit ( Option < i32 > ) ,
144
152
}
145
153
146
- pub async fn deactivate ( profile_path : & str ) -> Result < ( ) , DeactivateError > {
154
+ pub async fn deactivate (
155
+ profile_path : & str ,
156
+ bin_path : Option < PathBuf > ,
157
+ ) -> Result < ( ) , DeactivateError > {
147
158
warn ! ( "De-activating due to error" ) ;
148
159
149
- let nix_env_rollback_exit_status = Command :: new ( "nix-env" )
160
+ let program = match bin_path {
161
+ Some ( path) => path. join ( "nix-env" ) ,
162
+ None => PathBuf :: from ( "nix-env" ) ,
163
+ } ;
164
+ let nix_env_rollback_exit_status = Command :: new ( & program)
150
165
. arg ( "-p" )
151
166
. arg ( & profile_path)
152
167
. arg ( "--rollback" )
@@ -161,7 +176,7 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
161
176
162
177
debug ! ( "Listing generations" ) ;
163
178
164
- let nix_env_list_generations_out = Command :: new ( "nix-env" )
179
+ let nix_env_list_generations_out = Command :: new ( & program )
165
180
. arg ( "-p" )
166
181
. arg ( & profile_path)
167
182
. arg ( "--list-generations" )
@@ -190,7 +205,7 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
190
205
debug ! ( "Removing generation entry {}" , last_generation_line) ;
191
206
warn ! ( "Removing generation by ID {}" , last_generation_id) ;
192
207
193
- let nix_env_delete_generation_exit_status = Command :: new ( "nix-env" )
208
+ let nix_env_delete_generation_exit_status = Command :: new ( program )
194
209
. arg ( "-p" )
195
210
. arg ( & profile_path)
196
211
. arg ( "--delete-generations" )
@@ -315,7 +330,11 @@ pub enum WaitError {
315
330
#[ error( "Error waiting for activation: {0}" ) ]
316
331
Waiting ( #[ from] DangerZoneError ) ,
317
332
}
318
- pub async fn wait ( temp_path : PathBuf , closure : String , activation_timeout : Option < u16 > ) -> Result < ( ) , WaitError > {
333
+ pub async fn wait (
334
+ temp_path : PathBuf ,
335
+ closure : String ,
336
+ activation_timeout : Option < u16 > ,
337
+ ) -> Result < ( ) , WaitError > {
319
338
let lock_path = deploy:: make_lock_path ( & temp_path, & closure) ;
320
339
321
340
let ( created, done) = mpsc:: channel ( 1 ) ;
@@ -386,14 +405,20 @@ pub async fn activate(
386
405
closure : String ,
387
406
auto_rollback : bool ,
388
407
temp_path : PathBuf ,
408
+ bin_path : Option < PathBuf > ,
389
409
confirm_timeout : u16 ,
390
410
magic_rollback : bool ,
391
411
dry_activate : bool ,
392
412
boot : bool ,
393
413
) -> Result < ( ) , ActivateError > {
394
414
if !dry_activate {
395
415
info ! ( "Activating profile" ) ;
396
- let nix_env_set_exit_status = Command :: new ( "nix-env" )
416
+ let program = match & bin_path {
417
+ Some ( path) => path. join ( "nix-env" ) ,
418
+ None => PathBuf :: from ( "nix-env" ) ,
419
+ } ;
420
+
421
+ let nix_env_set_exit_status = Command :: new ( program)
397
422
. arg ( "-p" )
398
423
. arg ( & profile_path)
399
424
. arg ( "--set" )
@@ -405,7 +430,7 @@ pub async fn activate(
405
430
Some ( 0 ) => ( ) ,
406
431
a => {
407
432
if auto_rollback && !dry_activate {
408
- deactivate ( & profile_path) . await ?;
433
+ deactivate ( & profile_path, bin_path ) . await ?;
409
434
}
410
435
return Err ( ActivateError :: SetProfileExit ( a) ) ;
411
436
}
@@ -432,7 +457,7 @@ pub async fn activate(
432
457
Ok ( x) => x,
433
458
Err ( e) => {
434
459
if auto_rollback && !dry_activate {
435
- deactivate ( & profile_path) . await ?;
460
+ deactivate ( & profile_path, bin_path ) . await ?;
436
461
}
437
462
return Err ( e) ;
438
463
}
@@ -443,7 +468,7 @@ pub async fn activate(
443
468
Some ( 0 ) => ( ) ,
444
469
a => {
445
470
if auto_rollback {
446
- deactivate ( & profile_path) . await ?;
471
+ deactivate ( & profile_path, bin_path ) . await ?;
447
472
}
448
473
return Err ( ActivateError :: RunActivateExit ( a) ) ;
449
474
}
@@ -456,7 +481,7 @@ pub async fn activate(
456
481
if magic_rollback && !boot {
457
482
info ! ( "Magic rollback is enabled, setting up confirmation hook..." ) ;
458
483
if let Err ( err) = activation_confirmation ( temp_path, confirm_timeout, closure) . await {
459
- deactivate ( & profile_path) . await ?;
484
+ deactivate ( & profile_path, bin_path ) . await ?;
460
485
return Err ( ActivateError :: ActivationConfirmation ( err) ) ;
461
486
}
462
487
}
@@ -465,8 +490,8 @@ pub async fn activate(
465
490
Ok ( ( ) )
466
491
}
467
492
468
- async fn revoke ( profile_path : String ) -> Result < ( ) , DeactivateError > {
469
- deactivate ( profile_path. as_str ( ) ) . await ?;
493
+ async fn revoke ( profile_path : String , bin_path : Option < PathBuf > ) -> Result < ( ) , DeactivateError > {
494
+ deactivate ( profile_path. as_str ( ) , bin_path ) . await ?;
470
495
Ok ( ( ) )
471
496
}
472
497
@@ -557,6 +582,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
557
582
activate_opts. closure ,
558
583
activate_opts. auto_rollback ,
559
584
activate_opts. temp_path ,
585
+ activate_opts. bin_path ,
560
586
activate_opts. confirm_timeout ,
561
587
activate_opts. magic_rollback ,
562
588
activate_opts. dry_activate ,
@@ -565,15 +591,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
565
591
. await
566
592
. map_err ( |x| Box :: new ( x) as Box < dyn std:: error:: Error > ) ,
567
593
568
- SubCommand :: Wait ( wait_opts) => wait ( wait_opts. temp_path , wait_opts. closure , wait_opts. activation_timeout )
569
- . await
570
- . map_err ( |x| Box :: new ( x) as Box < dyn std:: error:: Error > ) ,
594
+ SubCommand :: Wait ( wait_opts) => wait (
595
+ wait_opts. temp_path ,
596
+ wait_opts. closure ,
597
+ wait_opts. activation_timeout ,
598
+ )
599
+ . await
600
+ . map_err ( |x| Box :: new ( x) as Box < dyn std:: error:: Error > ) ,
571
601
572
- SubCommand :: Revoke ( revoke_opts) => revoke ( get_profile_path (
573
- revoke_opts. profile_path ,
574
- revoke_opts. profile_user ,
575
- revoke_opts. profile_name ,
576
- ) ?)
602
+ SubCommand :: Revoke ( revoke_opts) => revoke (
603
+ get_profile_path (
604
+ revoke_opts. profile_path ,
605
+ revoke_opts. profile_user ,
606
+ revoke_opts. profile_name ,
607
+ ) ?,
608
+ revoke_opts. bin_path ,
609
+ )
577
610
. await
578
611
. map_err ( |x| Box :: new ( x) as Box < dyn std:: error:: Error > ) ,
579
612
} ;
0 commit comments