Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::LocalSettings Struct Reference

#include <local-settings.hh>

Inheritance diagram for nix::LocalSettings:
nix::Config nix::GCSettings nix::AutoAllocateUidSettings nix::AbstractConfig nix::Config nix::Config nix::AbstractConfig nix::AbstractConfig nix::Settings

Public Types

using ExternalBuilders = std::vector<ExternalBuilder>
Public Types inherited from nix::Config
using Settings = std::map<std::string, SettingData>

Public Member Functions

GCSettings & getGCSettings ()
const GCSettings & getGCSettings () const
const AutoAllocateUidSettings * getAutoAllocateUidSettings () const
const AbsolutePath * getDiffHook () const
const ExternalBuilder * findExternalDerivationBuilderIfSupported (const BasicDerivation &drv)
Public Member Functions inherited from nix::Config
 Config (StringMap initials={})
bool set (const std::string &name, const std::string &value) override
void addSetting (AbstractSetting *setting)
void getSettings (std::map< std::string, SettingInfo > &res, bool overriddenOnly=false) const override
void resetOverridden () override
nlohmann::json toJSON () override
std::string toKeyValue (bool overriddenOnly=false) override
void convertToArgs (Args &args, const std::string &category) override
Public Member Functions inherited from nix::AbstractConfig
void applyConfig (const std::string &contents, const std::string &path="<unknown>")
void warnUnknownSettings ()
void reapplyUnknownSettings ()

Public Attributes

Setting< unsigned int > buildCores
Setting< bool > fsyncMetadata
Setting< bool > fsyncStorePaths
Setting< bool > syncBeforeRegistering
Setting< bool > autoOptimiseStore
Setting< size_t > narBufferSize
Setting< bool > allowSymlinkedStore
Setting< std::string > buildUsersGroup
Setting< bool > autoAllocateUids
Setting< bool > useCgroups
Setting< SandboxMode > sandboxMode
Setting< PathsInChroot > sandboxPaths
Setting< bool > sandboxFallback
Setting< bool > requireDropSupplementaryGroups
Setting< std::string > sandboxShmSize
Setting< AbsolutePath > sandboxBuildDir
Setting< std::optional< AbsolutePath > > buildDir
Setting< std::set< std::filesystem::path > > allowedImpureHostPrefixes
Setting< bool > darwinLogSandboxViolations
Setting< bool > runDiffHook
Setting< std::string > preBuildHook
Setting< bool > filterSyscalls
Setting< bool > allowNewPrivileges
Setting< StringMap > impureEnv
Setting< Strings > hashedMirrors
Setting< ExternalBuilders > externalBuilders
Public Attributes inherited from nix::GCSettings
Setting< off_t > reservedSize
Setting< bool > keepOutputs
Setting< bool > keepDerivations
Setting< uint64_t > minFree
Setting< uint64_t > maxFree
Setting< uint64_t > minFreeCheckInterval
Public Attributes inherited from nix::AutoAllocateUidSettings
Setting< uint32_t > startId
Setting< uint32_t > uidCount

Additional Inherited Members

Protected Member Functions inherited from nix::AbstractConfig
 AbstractConfig (StringMap initials={})
Protected Attributes inherited from nix::AbstractConfig
StringMap unknownSettings

Detailed Description

Either about local store or local building

These are things that should not be part of the global settings, but should be per-local-store at a minimum. We expose them from settings with settings.getLocalSettings() for now, but we also have localStore.config->getLocalSettings() as a way to get them too. Even though both ways will actually draw from the same global variable, we would much prefer if you use the second one, because this will prepare the code base to making these actual, rather than pretend, per-store settings.

Member Function Documentation

◆ findExternalDerivationBuilderIfSupported()

const ExternalBuilder * nix::LocalSettings::findExternalDerivationBuilderIfSupported ( const BasicDerivation & drv)

Finds the first external derivation builder that supports this derivation, or else returns a null pointer.

◆ getAutoAllocateUidSettings()

const AutoAllocateUidSettings * nix::LocalSettings::getAutoAllocateUidSettings ( ) const
inline

Get AutoAllocateUidSettings if auto-allocate-uids is enabled.

Returns
Pointer to settings if enabled, nullptr otherwise.

◆ getDiffHook()

const AbsolutePath * nix::LocalSettings::getDiffHook ( ) const
inline

Get the diff hook path if run-diff-hook is enabled.

Returns
Pointer to path if enabled, nullptr otherwise.

◆ getGCSettings()

GCSettings & nix::LocalSettings::getGCSettings ( )
inline

Get the GC settings.

Member Data Documentation

◆ allowedImpureHostPrefixes

Setting<std::set<std::filesystem::path> > nix::LocalSettings::allowedImpureHostPrefixes
Initial value:
{
this,
{},
"allowed-impure-host-deps",
"Which prefixes to allow derivations to ask for access to (primarily for Darwin)."}

◆ allowNewPrivileges

Setting<bool> nix::LocalSettings::allowNewPrivileges
Initial value:
{
this,
false,
"allow-new-privileges",
R"(
(Linux-specific.) By default, builders on Linux cannot acquire new
privileges by calling setuid/setgid programs or programs that have
file capabilities. For example, programs such as `sudo` or `ping`
should fail. (Note that in sandbox builds, no such programs are
available unless you bind-mount them into the sandbox via the
`sandbox-paths` option.) You can allow the use of such programs by
enabling this option. This is impure and usually undesirable, but
may be useful in certain scenarios (e.g. to spin up containers or
set up userspace network interfaces in tests).
)"}

◆ allowSymlinkedStore

Setting<bool> nix::LocalSettings::allowSymlinkedStore
Initial value:
{
this,
false,
"allow-symlinked-store",
R"(
If set to `true`, Nix stops complaining if the store directory
(typically `/nix/store`) contains symlink components.
This risks making some builds "impure" because builders sometimes
"canonicalise" paths by resolving all symlink components. Problems
occur if those builds are then deployed to machines where /nix/store
resolves to a different location from that of the build machine. You
can enable this setting if you are sure you're not going to do that.
)"}

◆ autoAllocateUids

Setting<bool> nix::LocalSettings::autoAllocateUids
Initial value:
{
this,
false,
"auto-allocate-uids",
R"(
Whether to select UIDs for builds automatically, instead of using the
users in `build-users-group`.
UIDs are allocated starting at 872415232 (0x34000000) on Linux and 56930 on macOS.
)",
{},
true,
Xp::AutoAllocateUids}

◆ autoOptimiseStore

Setting<bool> nix::LocalSettings::autoOptimiseStore
Initial value:
{
this,
false,
"auto-optimise-store",
R"(
If set to `true`, Nix automatically detects files in the store
that have identical contents, and replaces them with hard links to
a single copy. This saves disk space. If set to `false` (the
default), you can still run `nix-store --optimise` to get rid of
duplicate files.
)"}

◆ buildCores

Setting<unsigned int> nix::LocalSettings::buildCores
Initial value:
{
this,
0,
"cores",
R"(
Sets the value of the `NIX_BUILD_CORES` environment variable in the [invocation of the `builder` executable](@docroot@/store/building.md#env-vars) of a derivation.
The `builder` executable can use this variable to control its own maximum amount of parallelism.
<!--
FIXME(@fricklerhandwerk): I don't think this should even be mentioned here.
A very generic example using `derivation` and `xargs` may be more appropriate to explain the mechanism.
Using `mkDerivation` as an example requires being aware of that there are multiple independent layers that are completely opaque here.
-->
For instance, in Nixpkgs, if the attribute `enableParallelBuilding` for the `mkDerivation` build helper is set to `true`, it passes the `-j${NIX_BUILD_CORES}` flag to GNU Make.
If set to `0`, nix will detect the number of CPU cores and pass this number via `NIX_BUILD_CORES`.
> **Note**
>
> The number of parallel local Nix build jobs is independently controlled with the [`max-jobs`](#conf-max-jobs) setting.
)",
{"build-cores"}}

◆ buildDir

Setting<std::optional<AbsolutePath> > nix::LocalSettings::buildDir
Initial value:
{
this,
std::nullopt,
"build-dir",
R"(
Override the `build-dir` store setting for all stores that have this setting.
See also the per-store [`build-dir`](@docroot@/store/types/local-store.md#store-local-store-build-dir) setting.
)"}

◆ darwinLogSandboxViolations

Setting<bool> nix::LocalSettings::darwinLogSandboxViolations
Initial value:
{
this,
false,
"darwin-log-sandbox-violations",
"Whether to log Darwin sandbox access violations to the system log."}

◆ filterSyscalls

Setting<bool> nix::LocalSettings::filterSyscalls
Initial value:
{
this,
true,
"filter-syscalls",
R"(
Whether to prevent certain dangerous system calls, such as
creation of setuid/setgid files or adding ACLs or extended
attributes. Only disable this if you're aware of the
security implications.
)"}

◆ fsyncMetadata

Setting<bool> nix::LocalSettings::fsyncMetadata
Initial value:
{
this,
true,
"fsync-metadata",
R"(
If set to `true`, changes to the Nix store metadata (in
`/nix/var/nix/db`) are synchronously flushed to disk. This improves
robustness in case of system crashes, but reduces performance. The
default is `true`.
)"}

◆ fsyncStorePaths

Setting<bool> nix::LocalSettings::fsyncStorePaths
Initial value:
{
this,
false,
"fsync-store-paths",
R"(
Whether to call `fsync()` on store paths before registering them, to
flush them to disk. This improves robustness in case of system crashes,
but reduces performance. The default is `false`.
)"}

◆ hashedMirrors

Setting<Strings> nix::LocalSettings::hashedMirrors
Initial value:
{
this,
{},
"hashed-mirrors",
R"(
A list of web servers used by `builtins.fetchurl` to obtain files by
hash. Given a hash algorithm *ha* and a base-16 hash *h*, Nix tries to
download the file from *hashed-mirror*/*ha*/*h*. This allows files to
be downloaded even if they have disappeared from their original URI.
For example, given an example mirror `http://tarballs.nixos.org/`,
when building the derivation
```nix
builtins.fetchurl {
url = "https://example.org/foo-1.2.3.tar.xz";
sha256 = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae";
}
```
Nix will attempt to download this file from
`http://tarballs.nixos.org/sha256/2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae`
first. If it is not available there, it tries the original URI.
)"}

◆ impureEnv

Setting<StringMap> nix::LocalSettings::impureEnv
Initial value:
{
this,
{},
"impure-env",
R"(
A list of items, each in the format of:
- `name=value`: Set environment variable `name` to `value`.
If the user is trusted (see `trusted-users` option), when building
a fixed-output derivation, environment variables set in this option
is passed to the builder if they are listed in [`impureEnvVars`](@docroot@/language/advanced-attributes.md#adv-attr-impureEnvVars).
This option is useful for, e.g., setting `https_proxy` for
fixed-output derivations and in a multi-user Nix installation, or
setting private access tokens when fetching a private repository.
)",
{},
true,
Xp::ConfigurableImpureEnv}

◆ narBufferSize

Setting<size_t> nix::LocalSettings::narBufferSize
Initial value:
{
this, 32 * 1024 * 1024, "nar-buffer-size", "Maximum size of NARs before spilling them to disk."}

◆ preBuildHook

Setting<std::string> nix::LocalSettings::preBuildHook
Initial value:
{
this,
"",
"pre-build-hook",
R"(
If set, the path to a program that can set extra derivation-specific
settings for this system. This is used for settings that can't be
captured by the derivation model itself and are too variable between
different versions of the same system to be hard-coded into nix.
The hook is passed the derivation path and, if sandboxes are
enabled, the sandbox directory. It can then modify the sandbox and
send a series of commands to modify various settings to stdout. The
currently recognized commands are:
- `extra-sandbox-paths`\
Pass a list of files and directories to be included in the
sandbox for this build. One entry per line, terminated by an
empty line. Entries have the same format as `sandbox-paths`.
)"}

◆ requireDropSupplementaryGroups

Setting<bool> nix::LocalSettings::requireDropSupplementaryGroups
Initial value:
{
this,
"require-drop-supplementary-groups",
R"(
Following the principle of least privilege,
Nix attempts to drop supplementary groups when building with sandboxing.
However this can fail under some circumstances.
For example, if the user lacks the `CAP_SETGID` capability.
Search `setgroups(2)` for `EPERM` to find more detailed information on this.
If you encounter such a failure, setting this option to `false` enables you to ignore it and continue.
But before doing so, you should consider the security implications carefully.
Not dropping supplementary groups means the build sandbox is less restricted than intended.
This option defaults to `true` when the user is root
(since `root` usually has permissions to call setgroups)
and `false` otherwise.
)"}
bool isRootUser()
Definition users.cc:65

◆ runDiffHook

Setting<bool> nix::LocalSettings::runDiffHook
Initial value:
{
this,
false,
"run-diff-hook",
R"(
If true, enable the execution of the `diff-hook` program.
When using the Nix daemon, `run-diff-hook` must be set in the
`nix.conf` configuration file, and cannot be passed at the command
line.
)"}

◆ sandboxBuildDir

Setting<AbsolutePath> nix::LocalSettings::sandboxBuildDir
Initial value:
{
this,
"/build",
"sandbox-build-dir",
R"(
*Linux only*
The build directory inside the sandbox.
This directory is backed by [`build-dir`](#conf-build-dir) on the host.
)"}

◆ sandboxFallback

Setting<bool> nix::LocalSettings::sandboxFallback
Initial value:
{
this, true, "sandbox-fallback", "Whether to disable sandboxing when the kernel doesn't allow it."}

◆ sandboxPaths

Setting<PathsInChroot> nix::LocalSettings::sandboxPaths
Initial value:
{
this,
{},
"sandbox-paths",
R"(
A list of paths bind-mounted into Nix sandbox environments. You can
use the syntax `target=source` to mount a path in a different
location in the sandbox; for instance, `/bin=/nix-bin` mounts
the path `/nix-bin` as `/bin` inside the sandbox. If *source* is
followed by `?`, then it is not an error if *source* does not exist;
for example, `/dev/nvidiactl?` specifies that `/dev/nvidiactl`
only be mounted in the sandbox if it exists in the host filesystem.
If the source is in the Nix store, then its closure is added to
the sandbox as well.
Depending on how Nix was built, the default value for this option
may be empty or provide `/bin/sh` as a bind-mount of `bash`.
)",
{"build-chroot-dirs", "build-sandbox-paths"}}

◆ sandboxShmSize

Setting<std::string> nix::LocalSettings::sandboxShmSize
Initial value:
{
this,
"50%",
"sandbox-dev-shm-size",
R"(
*Linux only*
This option determines the maximum size of the `tmpfs` filesystem
mounted on `/dev/shm` in Linux sandboxes. For the format, see the
description of the `size` option of `tmpfs` in mount(8). The default
is `50%`.
)"}

◆ syncBeforeRegistering

Setting<bool> nix::LocalSettings::syncBeforeRegistering
Initial value:
{
this, false, "sync-before-registering", "Whether to call `sync()` before registering a path as valid."}

◆ useCgroups

Setting<bool> nix::LocalSettings::useCgroups
Initial value:
{
this,
false,
"use-cgroups",
R"(
Whether to execute builds inside cgroups.
This is only supported on Linux.
Cgroups are required and enabled automatically for derivations
that require the `uid-range` system feature.
)"}

The documentation for this struct was generated from the following files: