Home Explore Blog CI



nix

4th chunk of `doc/manual/source/language/advanced-attributes.md`
2956781fb85e8abf7f3da64ebb97bf038275bc2136736bfa0000000100000f8c
  If a derivation has the `requiredSystemFeatures` attribute, then Nix will only build it on a machine that has the corresponding features set in its [`system-features` configuration](@docroot@/command-ref/conf-file.md#conf-system-features).

  For example, setting

  ```nix
  requiredSystemFeatures = [ "kvm" ];
  ```

  ensures that the derivation can only be built on a machine with the `kvm` feature.

# Impure builder configuration

  - [`impureEnvVars`]{#adv-attr-impureEnvVars}\
    This attribute allows you to specify a list of environment variables
    that should be passed from the environment of the calling user to
    the builder. Usually, the environment is cleared completely when the
    builder is executed, but with this attribute you can allow specific
    environment variables to be passed unmodified. For example,
    `fetchurl` in Nixpkgs has the line

    ```nix
    impureEnvVars = [ "http_proxy" "https_proxy" ... ];
    ```

    to make it use the proxy server configuration specified by the user
    in the environment variables `http_proxy` and friends.

    This attribute is only allowed in [fixed-output derivations][fixed-output derivation],
    where impurities such as these are okay since (the hash
    of) the output is known in advance. It is ignored for all other
    derivations.

    > **Warning**
    >
    > `impureEnvVars` implementation takes environment variables from
    > the current builder process. When a daemon is building its
    > environmental variables are used. Without the daemon, the
    > environmental variables come from the environment of the
    > `nix-build`.

    If the [`configurable-impure-env` experimental
    feature](@docroot@/development/experimental-features.md#xp-feature-configurable-impure-env)
    is enabled, these environment variables can also be controlled
    through the
    [`impure-env`](@docroot@/command-ref/conf-file.md#conf-impure-env)
    configuration setting.

## Setting the derivation type

As discussed in [Derivation Outputs and Types of Derivations](@docroot@/store/derivation/outputs/index.md), there are multiples kinds of derivations / kinds of derivation outputs.
The choice of the following attributes determines which kind of derivation we are making.

- [`__contentAddressed`]

- [`outputHash`]

- [`outputHashAlgo`]

- [`outputHashMode`]

The three types of derivations are chosen based on the following combinations of these attributes.
All other combinations are invalid.

- [Input-addressing derivations](@docroot@/store/derivation/outputs/input-address.md)

  This is the default for `builtins.derivation`.
  Nix only currently supports one kind of input-addressing, so no other information is needed.

  `__contentAddressed = false;` may also be included, but is not needed, and will trigger the experimental feature check.

- [Fixed-output derivations][fixed-output derivation]

  All of [`outputHash`], [`outputHashAlgo`], and [`outputHashMode`].

  <!--

  `__contentAddressed` is ignored, because fixed-output derivations always content-address their outputs, by definition.

  **TODO CHECK**

  -->

- [(Floating) content-addressing derivations](@docroot@/store/derivation/outputs/content-address.md)

  Both [`outputHashAlgo`] and [`outputHashMode`], `__contentAddressed = true;`, and *not* `outputHash`.

  If an output hash was given, then the derivation output would be "fixed" not "floating".

Here is more information on the `output*` attributes, and what values they may be set to:

  - [`outputHashMode`]{#adv-attr-outputHashMode}

    This specifies how the files of a content-addressing derivation output are digested to produce a content address.

    This works in conjunction with [`outputHashAlgo`](#adv-attr-outputHashAlgo).
    Specifying one without the other is an error (unless [`outputHash` is also specified and includes its own hash algorithm as described below).

    The `outputHashMode` attribute determines how the hash is computed.

Title: Advanced Derivation Attributes: Impure Environment Variables and Derivation Types
Summary
This section details advanced derivation attributes. It explains `impureEnvVars`, which allows specified environment variables to be passed to the builder in fixed-output derivations. It also discusses how to define different types of derivations (input-addressing, fixed-output, and content-addressing) based on the presence and values of attributes like `__contentAddressed`, `outputHash`, `outputHashAlgo`, and `outputHashMode`.