diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 7f0a65c89..ee4ef0681 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -29,7 +29,6 @@ #include "lix/libutil/namespaces.hh" #include "lix/libutil/types.hh" #include "lix/libutil/unix-domain-socket.hh" -#include "lix/libutil/mount.hh" #include "lix/libutil/strings.hh" #include "lix/libutil/thread-name.hh" #include "lix/libstore/platform/linux.hh" diff --git a/lix/libstore/platform/linux.cc b/lix/libstore/platform/linux.cc index 6bcfd9e0f..b678fa1ba 100644 --- a/lix/libstore/platform/linux.cc +++ b/lix/libstore/platform/linux.cc @@ -9,7 +9,6 @@ #include "lix/libutil/file-system.hh" #include "lix/libutil/finally.hh" #include "lix/libstore/gc-store.hh" -#include "lix/libutil/mount.hh" #include "lix/libutil/processes.hh" #include "lix/libutil/result.hh" #include "lix/libutil/signals.hh" @@ -1234,6 +1233,40 @@ std::string LinuxLocalDerivationGoal::rewriteResolvConf(std::string fromHost) return std::regex_replace(fromHost, lineRegex, "") + nsInSandbox; } +static void bindPath(const Path & source, const Path & target, bool optional = false) +{ + debug("bind mounting '%1%' to '%2%'", source, target); + + auto bindMount = [&]() { + if (sys::mount(source, target, "", MS_BIND | MS_REC, 0) == -1) { + throw SysError("bind mount from '%1%' to '%2%' failed", source, target); + } + }; + + auto maybeSt = maybeLstat(source); + if (!maybeSt) { + if (optional) { + return; + } else { + throw SysError("getting attributes of path '%1%'", source); + } + } + auto st = *maybeSt; + + if (S_ISDIR(st.st_mode)) { + createDirs(target); + bindMount(); + } else if (S_ISLNK(st.st_mode)) { + // Symlinks can (apparently) not be bind-mounted, so just copy it + createDirs(dirOf(target)); + copyFile(source, target, {}); + } else { + createDirs(dirOf(target)); + writeFile(target, ""); + bindMount(); + } +} + bool LinuxLocalDerivationGoal::prepareChildSetup() { // Set the NO_NEW_PRIVS prctl flag. diff --git a/lix/libutil/meson.build b/lix/libutil/meson.build index 2690a9c05..df5cde21e 100644 --- a/lix/libutil/meson.build +++ b/lix/libutil/meson.build @@ -31,7 +31,6 @@ liblix_sources += files( 'logging-rpc.cc', 'logging.cc', 'monitor-fd.cc', - 'mount.cc', 'namespaces.cc', 'position.cc', 'print-elided.cc', @@ -114,7 +113,6 @@ libutil_headers = files( 'lru-cache.hh', 'manually-drop.hh', 'monitor-fd.hh', - 'mount.hh', 'namespaces.hh', 'notifying-counter.hh', 'pool.hh', diff --git a/lix/libutil/mount.cc b/lix/libutil/mount.cc deleted file mode 100644 index 151df835f..000000000 --- a/lix/libutil/mount.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include "lix/libutil/mount.hh" -#include "c-calls.hh" -#include "lix/libutil/error.hh" -#include "lix/libutil/file-system.hh" -#include "lix/libutil/logging.hh" -#if __linux__ -#include - -namespace nix { - -void bindPath(const Path & source, const Path & target, bool optional, CopyFileFlags flags) -{ - debug("bind mounting '%1%' to '%2%'", source, target); - - auto bindMount = [&]() { - if (sys::mount(source, target, "", MS_BIND | MS_REC, 0) == -1) { - throw SysError("bind mount from '%1%' to '%2%' failed", source, target); - } - }; - - auto maybeSt = maybeLstat(source); - if (!maybeSt) { - if (optional) - return; - else - throw SysError("getting attributes of path '%1%'", source); - } - auto st = *maybeSt; - - if (S_ISDIR(st.st_mode)) { - createDirs(target); - bindMount(); - } else if (S_ISLNK(st.st_mode)) { - // Symlinks can (apparently) not be bind-mounted, so just copy it - createDirs(dirOf(target)); - copyFile(source, target, flags); - } else { - createDirs(dirOf(target)); - writeFile(target, ""); - bindMount(); - } -} -} - -#endif diff --git a/lix/libutil/mount.hh b/lix/libutil/mount.hh deleted file mode 100644 index fbc5ca107..000000000 --- a/lix/libutil/mount.hh +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -///@file - -#include "lix/libutil/types.hh" -#include "lix/libutil/file-system.hh" - -#if __linux__ -namespace nix { - -/** - * Bind-mount file or directory from `source` to `destination`. - * If source does not exist this will fail unless `optional` is set - * - * If `source` is a symlink, it will perform a copy instead of a bind mount - * because symlinks cannot be bind mounted on all versions of the Linux kernel. - * - * If a copy is performed, extra flags to the copy can be passed using `flags`. - */ -void bindPath( - const Path & source, const Path & target, bool optional = false, CopyFileFlags flags = {} -); -} -#endif