@@ -270,7 +270,10 @@ impl Directories {
270270 let cargo = home:: cargo_home ( ) ?;
271271 let xargo =
272272 env:: var_os ( "XARGO_HOME" ) . map_or_else ( || home_dir. join ( ".xargo" ) , PathBuf :: from) ;
273- let nix_store = env:: var_os ( "NIX_STORE" ) . map ( PathBuf :: from) ;
273+ // NIX_STORE_DIR is an override of NIX_STORE, which is the path in derivations.
274+ let nix_store = env:: var_os ( "NIX_STORE_DIR" )
275+ . or_else ( || env:: var_os ( "NIX_STORE" ) )
276+ . map ( PathBuf :: from) ;
274277 let target = & metadata. target_directory ;
275278
276279 // create the directories we are going to mount before we mount them,
@@ -292,9 +295,18 @@ impl Directories {
292295 // directories after failed canonicalization into a shared directory.
293296 let cargo = file:: canonicalize ( & cargo) ?;
294297 let xargo = file:: canonicalize ( & xargo) ?;
298+
299+ let default_nix_store = PathBuf :: from ( "/nix/store" ) ;
295300 let nix_store = match nix_store {
296- Some ( store) => Some ( file:: canonicalize ( & store) ?) ,
297- None => Some ( PathBuf :: from ( r"/nix/store" ) ) ,
301+ Some ( store) if store. exists ( ) => {
302+ let path = file:: canonicalize ( & store) ?;
303+ Some ( path)
304+ }
305+ Some ( store) => {
306+ eyre:: bail!( "unable to find provided nix-store directory {store:?}" ) ;
307+ }
308+ None if cfg ! ( target_os = "linux" ) && default_nix_store. exists ( ) => Some ( default_nix_store) ,
309+ None => None ,
298310 } ;
299311
300312 let cargo = mount_finder. find_mount_path ( cargo) ;
0 commit comments