From 26546f213f4c9fa89c6aa051271fe8f9e16334ef Mon Sep 17 00:00:00 2001 From: Artturin Date: Mon, 11 Sep 2023 00:19:21 +0300 Subject: [PATCH] WIP Bindmount files instead of hardlinking https://github.com/nixos/nix/commit/16591eb3cccf86da8cd3f20c56e2dd847576ff5e#diff-19f999107b609d37cfb22c58e7f0bc1cf76edf1180e238dd6389e03cc279b604 (2013) added support for files to doBind This is work towards allowing users to change the location of chrootRootDir, to, for example, a tmpfs. inspired by trofi on matrix > It looks like build sandbox created by nix-daemon runs on the same filesystem, as /nix/store including things like /tmp which makes all small temporary files hit the disk. Is it intentional? If it is is there an easy way to redirect chroot's root to be tmpfs? --- src/libstore/build/local-derivation-goal.cc | 6 +++++- src/libstore/build/local-derivation-goal.hh | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc index 64b55ca6ac2d..8dab795b42e0 100644 --- a/src/libstore/build/local-derivation-goal.cc +++ b/src/libstore/build/local-derivation-goal.cc @@ -714,7 +714,7 @@ void LocalDerivationGoal::startBuilder() if (S_ISDIR(lstat(r).st_mode)) dirsInChroot.insert_or_assign(p, r); else - linkOrCopy(r, chrootRootDir + p); + filesInChroot.insert_or_assign(p, r); } /* If we're repairing, checking or rebuilding part of a @@ -1858,6 +1858,10 @@ void LocalDerivationGoal::runChild() doBind(i.second.source, chrootRootDir + i.first, i.second.optional); } + for (auto & i : filesInChroot) { + doBind(i.second.source, chrootRootDir + i.first, i.second.optional); + } + /* Bind a new instance of procfs on /proc. */ createDirs(chrootRootDir + "/proc"); if (mount("none", (chrootRootDir + "/proc").c_str(), "proc", 0, 0) == -1) diff --git a/src/libstore/build/local-derivation-goal.hh b/src/libstore/build/local-derivation-goal.hh index 0a05081c78a5..d6ace70fe5d5 100644 --- a/src/libstore/build/local-derivation-goal.hh +++ b/src/libstore/build/local-derivation-goal.hh @@ -89,6 +89,9 @@ struct LocalDerivationGoal : public DerivationGoal typedef map DirsInChroot; // maps target path to source path DirsInChroot dirsInChroot; + typedef map FilesInChroot; // maps target path to source path + FilesInChroot filesInChroot; + typedef map Environment; Environment env;