1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +01:00

Merge pull request #13799 from obsidiansystems/typed-sandbox-paths

Make `sandbox-settings` better typed, get `globals.hh` out of other headers
This commit is contained in:
John Ericson 2025-08-20 16:50:34 -04:00 committed by GitHub
commit ca86d34077
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 215 additions and 59 deletions

View file

@ -15,6 +15,7 @@
#include "nix/fetchers/fetch-to-store.hh" #include "nix/fetchers/fetch-to-store.hh"
#include "nix/cmd/compatibility-settings.hh" #include "nix/cmd/compatibility-settings.hh"
#include "nix/expr/eval-settings.hh" #include "nix/expr/eval-settings.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -4,6 +4,7 @@
#include "nix/expr/eval.hh" #include "nix/expr/eval.hh"
#include "nix/expr/eval-inline.hh" #include "nix/expr/eval-inline.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/globals.hh"
// Need specialization involving `SymbolStr` just in this one module. // Need specialization involving `SymbolStr` just in this one module.
#include "nix/util/strings-inline.hh" #include "nix/util/strings-inline.hh"

View file

@ -6,6 +6,7 @@
#include "nix/util/exit.hh" #include "nix/util/exit.hh"
#include "nix/util/types.hh" #include "nix/util/types.hh"
#include "nix/util/util.hh" #include "nix/util/util.hh"
#include "nix/util/environment-variables.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/derivations.hh" #include "nix/store/derivations.hh"
#include "nix/store/downstream-placeholder.hh" #include "nix/store/downstream-placeholder.hh"

View file

@ -5,6 +5,7 @@
#include "nix/expr/eval-settings.hh" #include "nix/expr/eval-settings.hh"
#include "nix/expr/gc-small-vector.hh" #include "nix/expr/gc-small-vector.hh"
#include "nix/expr/json-to-value.hh" #include "nix/expr/json-to-value.hh"
#include "nix/store/globals.hh"
#include "nix/store/names.hh" #include "nix/store/names.hh"
#include "nix/store/path-references.hh" #include "nix/store/path-references.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"

View file

@ -2,6 +2,7 @@
#include "nix/expr/eval-inline.hh" #include "nix/expr/eval-inline.hh"
#include "nix/store/derivations.hh" #include "nix/store/derivations.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -3,6 +3,7 @@
#include "nix/store/realisation.hh" #include "nix/store/realisation.hh"
#include "nix/store/make-content-addressed.hh" #include "nix/store/make-content-addressed.hh"
#include "nix/util/url.hh" #include "nix/util/url.hh"
#include "nix/util/environment-variables.hh"
namespace nix { namespace nix {

View file

@ -1,4 +1,5 @@
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/globals.hh"
#include "nix/fetchers/fetch-settings.hh" #include "nix/fetchers/fetch-settings.hh"
#include "nix/fetchers/fetchers.hh" #include "nix/fetchers/fetchers.hh"
#include "nix/fetchers/git-utils.hh" #include "nix/fetchers/git-utils.hh"

View file

@ -4,6 +4,7 @@
#include "nix/store/sqlite.hh" #include "nix/store/sqlite.hh"
#include "nix/util/sync.hh" #include "nix/util/sync.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/globals.hh"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>

View file

@ -6,6 +6,7 @@
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -12,6 +12,7 @@
#include "nix/store/common-protocol.hh" #include "nix/store/common-protocol.hh"
#include "nix/store/common-protocol-impl.hh" #include "nix/store/common-protocol-impl.hh"
#include "nix/store/local-store.hh" // TODO remove, along with remaining downcasts #include "nix/store/local-store.hh" // TODO remove, along with remaining downcasts
#include "nix/store/globals.hh"
#include <fstream> #include <fstream>
#include <sys/types.h> #include <sys/types.h>

View file

@ -11,7 +11,7 @@
#include "nix/util/compression.hh" #include "nix/util/compression.hh"
#include "nix/store/common-protocol.hh" #include "nix/store/common-protocol.hh"
#include "nix/store/common-protocol-impl.hh" // Don't remove is actually needed #include "nix/store/common-protocol-impl.hh" // Don't remove is actually needed
#include "nix/store/local-store.hh" // TODO remove, along with remaining downcasts #include "nix/store/globals.hh"
#include <fstream> #include <fstream>
#include <sys/types.h> #include <sys/types.h>

View file

@ -4,6 +4,7 @@
#include "nix/store/build/substitution-goal.hh" #include "nix/store/build/substitution-goal.hh"
#include "nix/util/callback.hh" #include "nix/util/callback.hh"
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -1,5 +1,6 @@
#include "nix/store/build/goal.hh" #include "nix/store/build/goal.hh"
#include "nix/store/build/worker.hh" #include "nix/store/build/worker.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -4,6 +4,8 @@
#include "nix/store/nar-info.hh" #include "nix/store/nar-info.hh"
#include "nix/util/finally.hh" #include "nix/util/finally.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/store/globals.hh"
#include <coroutine> #include <coroutine>
namespace nix { namespace nix {

View file

@ -10,6 +10,7 @@
# include "nix/store/build/hook-instance.hh" # include "nix/store/build/hook-instance.hh"
#endif #endif
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -1,6 +1,7 @@
#include "nix/store/builtins.hh" #include "nix/store/builtins.hh"
#include "nix/store/filetransfer.hh" #include "nix/store/filetransfer.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/globals.hh"
#include "nix/util/archive.hh" #include "nix/util/archive.hh"
#include "nix/util/compression.hh" #include "nix/util/compression.hh"

View file

@ -16,6 +16,7 @@
#include "nix/util/args.hh" #include "nix/util/args.hh"
#include "nix/util/git.hh" #include "nix/util/git.hh"
#include "nix/util/logging.hh" #include "nix/util/logging.hh"
#include "nix/store/globals.hh"
#ifndef _WIN32 // TODO need graceful async exit support on Windows? #ifndef _WIN32 // TODO need graceful async exit support on Windows?
# include "nix/util/monitor-fd.hh" # include "nix/util/monitor-fd.hh"

View file

@ -5,6 +5,7 @@
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/util/types.hh" #include "nix/util/types.hh"
#include "nix/util/util.hh" #include "nix/util/util.hh"
#include "nix/store/globals.hh"
#include <optional> #include <optional>
#include <string> #include <string>

View file

@ -86,13 +86,22 @@ Settings::Settings()
} }
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(SANDBOX_SHELL) #if (defined(__linux__) || defined(__FreeBSD__)) && defined(SANDBOX_SHELL)
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL); sandboxPaths = {{"/bin/sh", {.source = SANDBOX_SHELL}}};
#endif #endif
/* chroot-like behavior from Apple's sandbox */ /* chroot-like behavior from Apple's sandbox */
#ifdef __APPLE__ #ifdef __APPLE__
sandboxPaths = tokenizeString<StringSet>( for (PathView p : {
"/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib"); "/System/Library/Frameworks",
"/System/Library/PrivateFrameworks",
"/bin/sh",
"/bin/bash",
"/private/tmp",
"/private/var/tmp",
"/usr/lib",
}) {
sandboxPaths.get().insert_or_assign(std::string{p}, ChrootPath{.source = std::string{p}});
}
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh"); allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
#endif #endif
} }
@ -317,6 +326,42 @@ void BaseSetting<SandboxMode>::convertToArg(Args & args, const std::string & cat
}); });
} }
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ChrootPath, source, optional)
template<>
PathsInChroot BaseSetting<PathsInChroot>::parse(const std::string & str) const
{
PathsInChroot pathsInChroot;
for (auto i : tokenizeString<StringSet>(str)) {
if (i.empty())
continue;
bool optional = false;
if (i[i.size() - 1] == '?') {
optional = true;
i.pop_back();
}
size_t p = i.find('=');
if (p == std::string::npos)
pathsInChroot[i] = {.source = i, .optional = optional};
else
pathsInChroot[i.substr(0, p)] = {.source = i.substr(p + 1), .optional = optional};
}
return pathsInChroot;
}
template<>
std::string BaseSetting<PathsInChroot>::to_string() const
{
std::vector<std::string> accum;
for (auto & [name, cp] : value) {
std::string s = name == cp.source ? name : name + "=" + cp.source;
if (cp.optional)
s += "?";
accum.push_back(std::move(s));
}
return concatStringsSep(" ", accum);
}
unsigned int MaxBuildJobsSetting::parse(const std::string & str) const unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
{ {
if (str == "auto") if (str == "auto")
@ -329,6 +374,14 @@ unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
} }
} }
template<>
void BaseSetting<PathsInChroot>::appendOrSet(PathsInChroot newValue, bool append)
{
if (!append)
value.clear();
value.insert(std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end()));
}
static void preloadNSS() static void preloadNSS()
{ {
/* builtin:fetchurl can trigger a DNS lookup, which with glibc can trigger a dynamic library load of /* builtin:fetchurl can trigger a DNS lookup, which with glibc can trigger a dynamic library load of

View file

@ -8,10 +8,20 @@
#include "nix/store/parsed-derivations.hh" #include "nix/store/parsed-derivations.hh"
#include "nix/util/processes.hh" #include "nix/util/processes.hh"
#include "nix/store/restricted-store.hh" #include "nix/store/restricted-store.hh"
#include "nix/store/user-lock.hh"
namespace nix { namespace nix {
/**
* Stuff we need to pass to initChild().
*/
struct ChrootPath
{
Path source;
bool optional = false;
};
typedef std::map<Path, ChrootPath> PathsInChroot; // maps target path to source path
/** /**
* Parameters by (mostly) `const` reference for `DerivationBuilder`. * Parameters by (mostly) `const` reference for `DerivationBuilder`.
*/ */
@ -178,7 +188,9 @@ struct DerivationBuilder : RestrictionContext
virtual void killSandbox(bool getStats) = 0; virtual void killSandbox(bool getStats) = 0;
}; };
#ifndef _WIN32 // TODO enable `DerivationBuilder` on Windows
std::unique_ptr<DerivationBuilder> makeDerivationBuilder( std::unique_ptr<DerivationBuilder> makeDerivationBuilder(
LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params); LocalStore & store, std::unique_ptr<DerivationBuilderCallbacks> miscMethods, DerivationBuilderParams params);
#endif
} // namespace nix } // namespace nix

View file

@ -11,6 +11,7 @@
#include "nix/util/environment-variables.hh" #include "nix/util/environment-variables.hh"
#include "nix/util/experimental-features.hh" #include "nix/util/experimental-features.hh"
#include "nix/util/users.hh" #include "nix/util/users.hh"
#include "nix/store/build/derivation-builder.hh"
#include "nix/store/config.hh" #include "nix/store/config.hh"
@ -23,6 +24,20 @@ SandboxMode BaseSetting<SandboxMode>::parse(const std::string & str) const;
template<> template<>
std::string BaseSetting<SandboxMode>::to_string() const; std::string BaseSetting<SandboxMode>::to_string() const;
template<>
PathsInChroot BaseSetting<PathsInChroot>::parse(const std::string & str) const;
template<>
std::string BaseSetting<PathsInChroot>::to_string() const;
template<>
struct BaseSetting<PathsInChroot>::trait
{
static constexpr bool appendable = true;
};
template<>
void BaseSetting<PathsInChroot>::appendOrSet(PathsInChroot newValue, bool append);
struct MaxBuildJobsSetting : public BaseSetting<unsigned int> struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
{ {
MaxBuildJobsSetting( MaxBuildJobsSetting(
@ -697,7 +712,7 @@ public:
)", )",
{"build-use-chroot", "build-use-sandbox"}}; {"build-use-chroot", "build-use-sandbox"}};
Setting<PathSet> sandboxPaths{ Setting<PathsInChroot> sandboxPaths{
this, this,
{}, {},
"sandbox-paths", "sandbox-paths",

View file

@ -22,15 +22,31 @@ struct LocalFSStoreConfig : virtual StoreConfig
OptionalPathSetting rootDir{this, std::nullopt, "root", "Directory prefixed to all other paths."}; OptionalPathSetting rootDir{this, std::nullopt, "root", "Directory prefixed to all other paths."};
private:
/**
* An indirection so that we don't need to refer to global settings
* in headers.
*/
static Path getDefaultStateDir();
/**
* An indirection so that we don't need to refer to global settings
* in headers.
*/
static Path getDefaultLogDir();
public:
PathSetting stateDir{ PathSetting stateDir{
this, this,
rootDir.get() ? *rootDir.get() + "/nix/var/nix" : settings.nixStateDir, rootDir.get() ? *rootDir.get() + "/nix/var/nix" : getDefaultStateDir(),
"state", "state",
"Directory where Nix stores state."}; "Directory where Nix stores state."};
PathSetting logDir{ PathSetting logDir{
this, this,
rootDir.get() ? *rootDir.get() + "/nix/var/log/nix" : settings.nixLogDir, rootDir.get() ? *rootDir.get() + "/nix/var/log/nix" : getDefaultLogDir(),
"log", "log",
"directory where Nix stores log files."}; "directory where Nix stores log files."};

View file

@ -74,9 +74,19 @@ struct LocalStoreConfig : std::enable_shared_from_this<LocalStoreConfig>,
LocalStoreConfig(std::string_view scheme, std::string_view authority, const Params & params); LocalStoreConfig(std::string_view scheme, std::string_view authority, const Params & params);
private:
/**
* An indirection so that we don't need to refer to global settings
* in headers.
*/
bool getDefaultRequireSigs();
public:
Setting<bool> requireSigs{ Setting<bool> requireSigs{
this, this,
settings.requireSigs, getDefaultRequireSigs(),
"require-sigs", "require-sigs",
"Whether store paths copied into this store should have a trusted signature."}; "Whether store paths copied into this store should have a trusted signature."};

View file

@ -12,6 +12,7 @@ config_pub_h = configure_file(
headers = [ config_pub_h ] + files( headers = [ config_pub_h ] + files(
'binary-cache-store.hh', 'binary-cache-store.hh',
'build-result.hh', 'build-result.hh',
'build/derivation-builder.hh',
'build/derivation-building-goal.hh', 'build/derivation-building-goal.hh',
'build/derivation-building-misc.hh', 'build/derivation-building-misc.hh',
'build/derivation-goal.hh', 'build/derivation-goal.hh',

View file

@ -1,10 +1,13 @@
#pragma once #pragma once
///@file ///@file
#include "nix/store/local-store.hh" #include "nix/store/store-api.hh"
namespace nix { namespace nix {
class LocalStore;
struct LocalStoreConfig;
/** /**
* A restricted store has a pointer to one of these, which manages the * A restricted store has a pointer to one of these, which manages the
* restrictions that are in place. * restrictions that are in place.
@ -55,6 +58,6 @@ struct RestrictionContext
/** /**
* Create a shared pointer to a restricted store. * Create a shared pointer to a restricted store.
*/ */
ref<Store> makeRestrictedStore(ref<LocalStore::Config> config, ref<LocalStore> next, RestrictionContext & context); ref<Store> makeRestrictedStore(ref<LocalStoreConfig> config, ref<LocalStore> next, RestrictionContext & context);
} // namespace nix } // namespace nix

View file

@ -8,7 +8,6 @@
#include "nix/util/serialise.hh" #include "nix/util/serialise.hh"
#include "nix/util/lru-cache.hh" #include "nix/util/lru-cache.hh"
#include "nix/util/sync.hh" #include "nix/util/sync.hh"
#include "nix/store/globals.hh"
#include "nix/util/configuration.hh" #include "nix/util/configuration.hh"
#include "nix/store/path-info.hh" #include "nix/store/path-info.hh"
#include "nix/util/repair-flag.hh" #include "nix/util/repair-flag.hh"
@ -89,9 +88,19 @@ struct StoreConfigBase : Config
{ {
using Config::Config; using Config::Config;
private:
/**
* An indirection so that we don't need to refer to global settings
* in headers.
*/
static Path getDefaultNixStoreDir();
public:
const PathSetting storeDir_{ const PathSetting storeDir_{
this, this,
settings.nixStore, getDefaultNixStoreDir(),
"store", "store",
R"( R"(
Logical location of the Nix store, usually Logical location of the Nix store, usually

View file

@ -3,7 +3,6 @@
#include "nix/store/path.hh" #include "nix/store/path.hh"
#include "nix/util/hash.hh" #include "nix/util/hash.hh"
#include "nix/store/content-address.hh" #include "nix/store/content-address.hh"
#include "nix/store/globals.hh"
#include "nix/util/configuration.hh" #include "nix/util/configuration.hh"
#include <map> #include <map>

View file

@ -30,9 +30,12 @@ ref<Store> openStore(StoreReference && storeURI);
* Opens the store at `uri`, where `uri` is in the format expected by * Opens the store at `uri`, where `uri` is in the format expected by
* `StoreReference::parse` * `StoreReference::parse`
*/ */
ref<Store> openStore( ref<Store> openStore(const std::string & uri, const StoreReference::Params & extraParams = StoreReference::Params());
const std::string & uri = settings.storeUri.get(),
const StoreReference::Params & extraParams = StoreReference::Params()); /**
* Short-hand which opens the default store, according to global settings
*/
ref<Store> openStore();
/** /**
* @return the default substituter stores, defined by the * @return the default substituter stores, defined by the

View file

@ -13,6 +13,7 @@
#include "nix/store/derivations.hh" #include "nix/store/derivations.hh"
#include "nix/util/callback.hh" #include "nix/util/callback.hh"
#include "nix/store/store-registration.hh" #include "nix/store/store-registration.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {

View file

@ -8,6 +8,16 @@
namespace nix { namespace nix {
Path LocalFSStoreConfig::getDefaultStateDir()
{
return settings.nixStateDir;
}
Path LocalFSStoreConfig::getDefaultLogDir()
{
return settings.nixLogDir;
}
LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params) LocalFSStoreConfig::LocalFSStoreConfig(PathView rootDir, const Params & params)
: StoreConfig(params) : StoreConfig(params)
// Default `?root` from `rootDir` if non set // Default `?root` from `rootDir` if non set

View file

@ -86,6 +86,11 @@ ref<Store> LocalStore::Config::openStore() const
return make_ref<LocalStore>(ref{shared_from_this()}); return make_ref<LocalStore>(ref{shared_from_this()});
} }
bool LocalStoreConfig::getDefaultRequireSigs()
{
return settings.requireSigs;
}
struct LocalStore::State::Stmts struct LocalStore::State::Stmts
{ {
/* Some precompiled SQLite statements. */ /* Some precompiled SQLite statements. */

View file

@ -1,5 +1,6 @@
#include "nix/store/profiles.hh" #include "nix/store/profiles.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "nix/store/globals.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
#include "nix/util/users.hh" #include "nix/util/users.hh"

View file

@ -2,6 +2,7 @@
#include "nix/store/build-result.hh" #include "nix/store/build-result.hh"
#include "nix/util/callback.hh" #include "nix/util/callback.hh"
#include "nix/store/realisation.hh" #include "nix/store/realisation.hh"
#include "nix/store/local-store.hh"
namespace nix { namespace nix {

View file

@ -27,6 +27,11 @@ using json = nlohmann::json;
namespace nix { namespace nix {
Path StoreConfigBase::getDefaultNixStoreDir()
{
return settings.nixStore;
}
StoreConfig::StoreConfig(const Params & params) StoreConfig::StoreConfig(const Params & params)
: StoreConfigBase(params) : StoreConfigBase(params)
, StoreDirConfig{storeDir_} , StoreDirConfig{storeDir_}

View file

@ -2,9 +2,15 @@
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/local-store.hh" #include "nix/store/local-store.hh"
#include "nix/store/uds-remote-store.hh" #include "nix/store/uds-remote-store.hh"
#include "nix/store/globals.hh"
namespace nix { namespace nix {
ref<Store> openStore()
{
return openStore(settings.storeUri.get());
}
ref<Store> openStore(const std::string & uri, const Store::Config::Params & extraParams) ref<Store> openStore(const std::string & uri, const Store::Config::Params & extraParams)
{ {
return openStore(StoreReference::parse(uri, extraParams)); return openStore(StoreReference::parse(uri, extraParams));

View file

@ -2,6 +2,7 @@
#include "nix/util/unix-domain-socket.hh" #include "nix/util/unix-domain-socket.hh"
#include "nix/store/worker-protocol.hh" #include "nix/store/worker-protocol.hh"
#include "nix/store/store-registration.hh" #include "nix/store/store-registration.hh"
#include "nix/store/globals.hh"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -135,7 +135,7 @@ struct ChrootDerivationBuilder : virtual DerivationBuilderImpl
for (auto & i : inputPaths) { for (auto & i : inputPaths) {
auto p = store.printStorePath(i); auto p = store.printStorePath(i);
pathsInChroot.insert_or_assign(p, store.toRealPath(p)); pathsInChroot.insert_or_assign(p, ChrootPath{.source = store.toRealPath(p)});
} }
/* If we're repairing, checking or rebuilding part of a /* If we're repairing, checking or rebuilding part of a

View file

@ -69,7 +69,7 @@ struct DarwinDerivationBuilder : DerivationBuilderImpl
/* Add all our input paths to the chroot */ /* Add all our input paths to the chroot */
for (auto & i : inputPaths) { for (auto & i : inputPaths) {
auto p = store.printStorePath(i); auto p = store.printStorePath(i);
pathsInChroot.insert_or_assign(p, p); pathsInChroot.insert_or_assign(p, ChrootPath{.source = p});
} }
/* Violations will go to the syslog if you set this. Unfortunately the destination does not appear to be /* Violations will go to the syslog if you set this. Unfortunately the destination does not appear to be

View file

@ -15,6 +15,8 @@
#include "nix/store/posix-fs-canonicalise.hh" #include "nix/store/posix-fs-canonicalise.hh"
#include "nix/util/posix-source-accessor.hh" #include "nix/util/posix-source-accessor.hh"
#include "nix/store/restricted-store.hh" #include "nix/store/restricted-store.hh"
#include "nix/store/user-lock.hh"
#include "nix/store/globals.hh"
#include <queue> #include <queue>
@ -106,23 +108,6 @@ protected:
*/ */
const DerivationType derivationType; const DerivationType derivationType;
/**
* Stuff we need to pass to initChild().
*/
struct ChrootPath
{
Path source;
bool optional;
ChrootPath(Path source = "", bool optional = false)
: source(source)
, optional(optional)
{
}
};
typedef std::map<Path, ChrootPath> PathsInChroot; // maps target path to source path
typedef StringMap Environment; typedef StringMap Environment;
Environment env; Environment env;
@ -870,30 +855,16 @@ void DerivationBuilderImpl::startBuilder()
processSandboxSetupMessages(); processSandboxSetupMessages();
} }
DerivationBuilderImpl::PathsInChroot DerivationBuilderImpl::getPathsInSandbox() PathsInChroot DerivationBuilderImpl::getPathsInSandbox()
{ {
PathsInChroot pathsInChroot;
/* Allow a user-configurable set of directories from the /* Allow a user-configurable set of directories from the
host file system. */ host file system. */
for (auto i : settings.sandboxPaths.get()) { PathsInChroot pathsInChroot = settings.sandboxPaths.get();
if (i.empty())
continue;
bool optional = false;
if (i[i.size() - 1] == '?') {
optional = true;
i.pop_back();
}
size_t p = i.find('=');
if (p == std::string::npos)
pathsInChroot[i] = {i, optional};
else
pathsInChroot[i.substr(0, p)] = {i.substr(p + 1), optional};
}
if (hasPrefix(store.storeDir, tmpDirInSandbox())) { if (hasPrefix(store.storeDir, tmpDirInSandbox())) {
throw Error("`sandbox-build-dir` must not contain the storeDir"); throw Error("`sandbox-build-dir` must not contain the storeDir");
} }
pathsInChroot[tmpDirInSandbox()] = tmpDir; pathsInChroot[tmpDirInSandbox()] = {.source = tmpDir};
/* Add the closure of store paths to the chroot. */ /* Add the closure of store paths to the chroot. */
StorePathSet closure; StorePathSet closure;
@ -908,7 +879,7 @@ DerivationBuilderImpl::PathsInChroot DerivationBuilderImpl::getPathsInSandbox()
} }
for (auto & i : closure) { for (auto & i : closure) {
auto p = store.printStorePath(i); auto p = store.printStorePath(i);
pathsInChroot.insert_or_assign(p, p); pathsInChroot.insert_or_assign(p, ChrootPath{.source = p});
} }
PathSet allowedPaths = settings.allowedImpureHostPrefixes; PathSet allowedPaths = settings.allowedImpureHostPrefixes;
@ -964,9 +935,9 @@ DerivationBuilderImpl::PathsInChroot DerivationBuilderImpl::getPathsInSandbox()
} else { } else {
auto p = line.find('='); auto p = line.find('=');
if (p == std::string::npos) if (p == std::string::npos)
pathsInChroot[line] = line; pathsInChroot[line] = {.source = line};
else else
pathsInChroot[line.substr(0, p)] = line.substr(p + 1); pathsInChroot[line.substr(0, p)] = {.source = line.substr(p + 1)};
} }
} }
} }

View file

@ -2,7 +2,6 @@ include_dirs += include_directories('../..')
headers += files( headers += files(
'build/child.hh', 'build/child.hh',
'build/derivation-builder.hh',
'build/hook-instance.hh', 'build/hook-instance.hh',
'user-lock.hh', 'user-lock.hh',
) )

View file

@ -22,6 +22,7 @@
#include "nix/store/local-store.hh" #include "nix/store/local-store.hh"
#include "nix/cmd/legacy.hh" #include "nix/cmd/legacy.hh"
#include "nix/util/experimental-features.hh" #include "nix/util/experimental-features.hh"
#include "nix/store/globals.hh"
using namespace nix; using namespace nix;
using std::cin; using std::cin;

View file

@ -5,6 +5,7 @@
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
#include "nix/expr/eval-inline.hh" #include "nix/expr/eval-inline.hh"
#include "nix/store/globals.hh"
namespace nix::fs { namespace nix::fs {
using namespace std::filesystem; using namespace std::filesystem;

View file

@ -9,6 +9,7 @@
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
#include "nix/store/worker-protocol.hh" #include "nix/store/worker-protocol.hh"
#include "nix/util/executable-path.hh" #include "nix/util/executable-path.hh"
#include "nix/store/globals.hh"
namespace nix::fs { namespace nix::fs {
using namespace std::filesystem; using namespace std::filesystem;

View file

@ -5,6 +5,7 @@
#include "nix/main/common-args.hh" #include "nix/main/common-args.hh"
#include "nix/main/shared.hh" #include "nix/main/shared.hh"
#include "nix/store/store-api.hh" #include "nix/store/store-api.hh"
#include "nix/store/globals.hh"
#include "nix/store/outputs-spec.hh" #include "nix/store/outputs-spec.hh"
#include "nix/store/derivations.hh" #include "nix/store/derivations.hh"

View file

@ -6,6 +6,7 @@
#include "run.hh" #include "run.hh"
#include "nix/util/strings.hh" #include "nix/util/strings.hh"
#include "nix/util/executable-path.hh" #include "nix/util/executable-path.hh"
#include "nix/util/environment-variables.hh"
using namespace nix; using namespace nix;

View file

@ -1,4 +1,3 @@
#include "flake-command.hh"
#include "nix/main/common-args.hh" #include "nix/main/common-args.hh"
#include "nix/main/shared.hh" #include "nix/main/shared.hh"
#include "nix/expr/eval.hh" #include "nix/expr/eval.hh"
@ -17,6 +16,7 @@
#include "nix/util/users.hh" #include "nix/util/users.hh"
#include "nix/fetchers/fetch-to-store.hh" #include "nix/fetchers/fetch-to-store.hh"
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
#include "nix/store/globals.hh"
#include <filesystem> #include <filesystem>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -24,6 +24,9 @@
#include "nix/util/strings-inline.hh" #include "nix/util/strings-inline.hh"
// FIXME is this supposed to be private or not?
#include "flake-command.hh"
namespace nix::fs { namespace nix::fs {
using namespace std::filesystem; using namespace std::filesystem;
} }

View file

@ -5,6 +5,8 @@
#include "nix/store/local-fs-store.hh" #include "nix/store/local-fs-store.hh"
#include "nix/cmd/installable-derived-path.hh" #include "nix/cmd/installable-derived-path.hh"
#include "nix/util/environment-variables.hh" #include "nix/util/environment-variables.hh"
#include "nix/store/globals.hh"
#include "run.hh" #include "run.hh"
using namespace nix; using namespace nix;

View file

@ -1,6 +1,7 @@
#include "nix/cmd/command.hh" #include "nix/cmd/command.hh"
#include "nix/main/common-args.hh" #include "nix/main/common-args.hh"
#include "nix/main/shared.hh" #include "nix/main/shared.hh"
#include "nix/store/globals.hh"
#include "nix/store/store-open.hh" #include "nix/store/store-open.hh"
#include "nix/store/log-store.hh" #include "nix/store/log-store.hh"

View file

@ -12,7 +12,9 @@
#include "graphml.hh" #include "graphml.hh"
#include "nix/cmd/legacy.hh" #include "nix/cmd/legacy.hh"
#include "nix/util/posix-source-accessor.hh" #include "nix/util/posix-source-accessor.hh"
#include "nix/store/globals.hh"
#include "nix/store/path-with-outputs.hh" #include "nix/store/path-with-outputs.hh"
#include "man-pages.hh" #include "man-pages.hh"
#ifndef _WIN32 // TODO implement on Windows or provide allowed-to-noop interface #ifndef _WIN32 // TODO implement on Windows or provide allowed-to-noop interface

View file

@ -12,6 +12,7 @@
#include "nix/util/posix-source-accessor.hh" #include "nix/util/posix-source-accessor.hh"
#include "nix/cmd/misc-store-flags.hh" #include "nix/cmd/misc-store-flags.hh"
#include "nix/util/terminal.hh" #include "nix/util/terminal.hh"
#include "nix/util/environment-variables.hh"
#include "man-pages.hh" #include "man-pages.hh"

View file

@ -11,6 +11,8 @@
#include "nix/util/source-accessor.hh" #include "nix/util/source-accessor.hh"
#include "nix/expr/eval.hh" #include "nix/expr/eval.hh"
#include "nix/util/util.hh" #include "nix/util/util.hh"
#include "nix/store/globals.hh"
#include <filesystem> #include <filesystem>
#ifdef __linux__ #ifdef __linux__

View file

@ -8,6 +8,7 @@
#include "nix/expr/attr-path.hh" #include "nix/expr/attr-path.hh"
#include "nix/store/names.hh" #include "nix/store/names.hh"
#include "nix/util/executable-path.hh" #include "nix/util/executable-path.hh"
#include "nix/store/globals.hh"
#include "self-exe.hh" #include "self-exe.hh"
using namespace nix; using namespace nix;