@@ -90,6 +90,10 @@ struct ActivateOpts {
9090    /// Path for any temporary files that may be needed during activation 
9191#[ arg( long) ]  
9292    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 > , 
9397} 
9498
9599/// Wait for profile activation 
@@ -119,6 +123,10 @@ struct RevokeOpts {
119123    /// The profile name 
120124#[ arg( long,  requires = "profile_user" ) ]  
121125    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 > , 
122130} 
123131
124132#[ derive( Error ,  Debug ) ]  
@@ -143,10 +151,17 @@ pub enum DeactivateError {
143151    ReactivateExit ( Option < i32 > ) , 
144152} 
145153
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 >  { 
147158    warn ! ( "De-activating due to error" ) ; 
148159
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) 
150165        . arg ( "-p" ) 
151166        . arg ( & profile_path) 
152167        . arg ( "--rollback" ) 
@@ -161,7 +176,7 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
161176
162177    debug ! ( "Listing generations" ) ; 
163178
164-     let  nix_env_list_generations_out = Command :: new ( "nix-env" ) 
179+     let  nix_env_list_generations_out = Command :: new ( & program ) 
165180        . arg ( "-p" ) 
166181        . arg ( & profile_path) 
167182        . arg ( "--list-generations" ) 
@@ -190,7 +205,7 @@ pub async fn deactivate(profile_path: &str) -> Result<(), DeactivateError> {
190205    debug ! ( "Removing generation entry {}" ,  last_generation_line) ; 
191206    warn ! ( "Removing generation by ID {}" ,  last_generation_id) ; 
192207
193-     let  nix_env_delete_generation_exit_status = Command :: new ( "nix-env" ) 
208+     let  nix_env_delete_generation_exit_status = Command :: new ( program ) 
194209        . arg ( "-p" ) 
195210        . arg ( & profile_path) 
196211        . arg ( "--delete-generations" ) 
@@ -315,7 +330,11 @@ pub enum WaitError {
315330    #[ error( "Error waiting for activation: {0}" ) ]  
316331    Waiting ( #[ from]   DangerZoneError ) , 
317332} 
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 >  { 
319338    let  lock_path = deploy:: make_lock_path ( & temp_path,  & closure) ; 
320339
321340    let  ( created,  done)  = mpsc:: channel ( 1 ) ; 
@@ -386,14 +405,20 @@ pub async fn activate(
386405    closure :  String , 
387406    auto_rollback :  bool , 
388407    temp_path :  PathBuf , 
408+     bin_path :  Option < PathBuf > , 
389409    confirm_timeout :  u16 , 
390410    magic_rollback :  bool , 
391411    dry_activate :  bool , 
392412    boot :  bool , 
393413)  -> Result < ( ) ,  ActivateError >  { 
394414    if  !dry_activate { 
395415        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) 
397422            . arg ( "-p" ) 
398423            . arg ( & profile_path) 
399424            . arg ( "--set" ) 
@@ -405,7 +430,7 @@ pub async fn activate(
405430            Some ( 0 )  => ( ) , 
406431            a => { 
407432                if  auto_rollback && !dry_activate { 
408-                     deactivate ( & profile_path) . await ?; 
433+                     deactivate ( & profile_path,  bin_path ) . await ?; 
409434                } 
410435                return  Err ( ActivateError :: SetProfileExit ( a) ) ; 
411436            } 
@@ -432,7 +457,7 @@ pub async fn activate(
432457        Ok ( x)  => x, 
433458        Err ( e)  => { 
434459            if  auto_rollback && !dry_activate { 
435-                 deactivate ( & profile_path) . await ?; 
460+                 deactivate ( & profile_path,  bin_path ) . await ?; 
436461            } 
437462            return  Err ( e) ; 
438463        } 
@@ -443,7 +468,7 @@ pub async fn activate(
443468            Some ( 0 )  => ( ) , 
444469            a => { 
445470                if  auto_rollback { 
446-                     deactivate ( & profile_path) . await ?; 
471+                     deactivate ( & profile_path,  bin_path ) . await ?; 
447472                } 
448473                return  Err ( ActivateError :: RunActivateExit ( a) ) ; 
449474            } 
@@ -456,7 +481,7 @@ pub async fn activate(
456481        if  magic_rollback && !boot { 
457482            info ! ( "Magic rollback is enabled, setting up confirmation hook..." ) ; 
458483            if  let  Err ( err)  = activation_confirmation ( temp_path,  confirm_timeout,  closure) . await  { 
459-                 deactivate ( & profile_path) . await ?; 
484+                 deactivate ( & profile_path,  bin_path ) . await ?; 
460485                return  Err ( ActivateError :: ActivationConfirmation ( err) ) ; 
461486            } 
462487        } 
@@ -465,8 +490,8 @@ pub async fn activate(
465490    Ok ( ( ) ) 
466491} 
467492
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 ?; 
470495    Ok ( ( ) ) 
471496} 
472497
@@ -557,6 +582,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
557582            activate_opts. closure , 
558583            activate_opts. auto_rollback , 
559584            activate_opts. temp_path , 
585+             activate_opts. bin_path , 
560586            activate_opts. confirm_timeout , 
561587            activate_opts. magic_rollback , 
562588            activate_opts. dry_activate , 
@@ -565,15 +591,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
565591        . await 
566592        . map_err ( |x| Box :: new ( x)  as  Box < dyn  std:: error:: Error > ) , 
567593
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 > ) , 
571601
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+         ) 
577610        . await 
578611        . map_err ( |x| Box :: new ( x)  as  Box < dyn  std:: error:: Error > ) , 
579612    } ; 
0 commit comments