Skip to content

Commit

Permalink
Merge #989
Browse files Browse the repository at this point in the history
989: added default nix_store value r=Alexhuszagh,otavio a=IllustratedMan-code

This pull request fixes the nix related issues described in #260. Its super simple, I just made the nix_store match statement default to `/nix/store` if the NIX_STORE variable is not set. 

There might be some edge cases where this won't fix the problem, but should be fine for any normal NixOS installation.




Co-authored-by: lew2mz <[email protected]>
  • Loading branch information
bors[bot] and IllustratedMan-code authored Aug 8, 2022
2 parents 7c638e6 + a087f0b commit 8728c84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/989.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "changed",
"description": "add default nix_store value to solve nix-related issues",
"issues": [260]
}
18 changes: 16 additions & 2 deletions src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ impl Directories {
let cargo = home::cargo_home()?;
let xargo =
env::var_os("XARGO_HOME").map_or_else(|| home_dir.join(".xargo"), PathBuf::from);
let nix_store = env::var_os("NIX_STORE").map(PathBuf::from);
// NIX_STORE_DIR is an override of NIX_STORE, which is the path in derivations.
let nix_store = env::var_os("NIX_STORE_DIR")
.or_else(|| env::var_os("NIX_STORE"))
.map(PathBuf::from);
let target = &metadata.target_directory;

// create the directories we are going to mount before we mount them,
Expand All @@ -292,8 +295,19 @@ impl Directories {
// directories after failed canonicalization into a shared directory.
let cargo = file::canonicalize(&cargo)?;
let xargo = file::canonicalize(&xargo)?;

let default_nix_store = PathBuf::from("/nix/store");
let nix_store = match nix_store {
Some(store) => Some(file::canonicalize(&store)?),
Some(store) if store.exists() => {
let path = file::canonicalize(&store)?;
Some(path)
}
Some(store) => {
eyre::bail!("unable to find provided nix-store directory {store:?}");
}
None if cfg!(target_os = "linux") && default_nix_store.exists() => {
Some(default_nix_store)
}
None => None,
};

Expand Down

0 comments on commit 8728c84

Please sign in to comment.