Skip to content

Commit

Permalink
Merge #524
Browse files Browse the repository at this point in the history
524: docker: Add Nix Store volume support r=Emilgardis a=otavio

When running inside NixOS or using Nix packaging we need to add the Nix
Store to the running container so it can load the needed binaries.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>

Co-authored-by: Otavio Salvador <otavio@ossystems.com.br>
  • Loading branch information
bors[bot] and otavio authored Mar 17, 2022
2 parents 762f0f0 + 787045c commit 38fd62b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #552 - Added CHANGELOG.md automation
- #543 - Added environment variables to control the UID and GID in the container
- #534 - fix image builds with update of dependencies
- #524 - docker: Add Nix Store volume support
- #502 - fix ci: bump openssl version in freebsd
- #501 - x86_64-linux: lower glibc version requirement to 2.17 (compatible with centos 7)
- #500 - use runner setting specified in Cross.toml
Expand Down
10 changes: 10 additions & 0 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn run(
let xargo_dir = env::var_os("XARGO_HOME")
.map(PathBuf::from)
.unwrap_or_else(|| home_dir.join(".xargo"));
let nix_store_dir = env::var_os("NIX_STORE").map(PathBuf::from);
let target_dir = target_dir.clone().unwrap_or_else(|| root.join("target"));

// create the directories we are going to mount before we mount them,
Expand Down Expand Up @@ -200,6 +201,15 @@ pub fn run(
.args(&["-v", &format!("{}:/target:Z", target_dir.display())])
.args(&["-w", &mount_root.display().to_string()]);

// When running inside NixOS or using Nix packaging we need to add the Nix
// Store to the running container so it can load the needed binaries.
if let Some(nix_store) = nix_store_dir {
docker.args(&[
"-v",
&format!("{}:{}:Z", nix_store.display(), nix_store.display()),
]);
}

if atty::is(Stream::Stdin) {
docker.arg("-i");
if atty::is(Stream::Stdout) && atty::is(Stream::Stderr) {
Expand Down

0 comments on commit 38fd62b

Please sign in to comment.