Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: Add Nix Store volume support #524

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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