Skip to content

Commit 8728c84

Browse files
Merge #989
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]>
2 parents 7c638e6 + a087f0b commit 8728c84

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

.changes/989.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "changed",
3+
"description": "add default nix_store value to solve nix-related issues",
4+
"issues": [260]
5+
}

src/docker/shared.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,8 +295,19 @@ 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)?),
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() => {
309+
Some(default_nix_store)
310+
}
297311
None => None,
298312
};
299313

0 commit comments

Comments
 (0)