Home Explore Blog Models CI



nixpkgs

16th chunk of `doc/stdenv/stdenv.chapter.md`
977db9fd04b5026f422c4432a248e9ff108ce3b0558b35af0000000100001042
Note that shell arrays cannot be passed through environment variables, so you cannot set `makeFlagsArray` in a derivation attribute (because those are passed through environment variables): you have to define them in shell code.

##### `buildFlags` / `buildFlagsArray` {#var-stdenv-buildFlags}

A list of strings passed as additional flags to `make`. Like `makeFlags` and `makeFlagsArray`, but only used by the build phase. Any build targets should be specified as part of the `buildFlags`.

##### `preBuild` {#var-stdenv-preBuild}

Hook executed at the start of the build phase.

##### `postBuild` {#var-stdenv-postBuild}

Hook executed at the end of the build phase.

You can set flags for `make` through the `makeFlags` variable.

Before and after running `make`, the hooks `preBuild` and `postBuild` are called, respectively.

### The check phase {#ssec-check-phase}

The check phase checks whether the package was built correctly by running its test suite. The default `checkPhase` calls `make $checkTarget`, but only if the [`doCheck` variable](#var-stdenv-doCheck) is enabled.

It is highly recommended, for packages' sources that are not distributed with any tests, to at least use [`versionCheckHook`](#versioncheckhook) to test that the resulting executable is basically functional.

#### Variables controlling the check phase {#variables-controlling-the-check-phase}

##### `doCheck` {#var-stdenv-doCheck}

Controls whether the check phase is executed. By default it is skipped, but if `doCheck` is set to true, the check phase is usually executed. Thus you should set

```nix
{ doCheck = true; }
```

in the derivation to enable checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doCheck` is set, as the newly-built program won’t run on the platform used to build it.

##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile}

See the [build phase](#var-stdenv-makeFlags) for details.

##### `checkTarget` {#var-stdenv-checkTarget}

The `make` target that runs the tests.
If unset, use `check` if it exists, otherwise `test`; if neither is found, do nothing.

##### `checkFlags` / `checkFlagsArray` {#var-stdenv-checkFlags}

A list of strings passed as additional flags to `make`. Like `makeFlags` and `makeFlagsArray`, but only used by the check phase. Unlike with `buildFlags`, the `checkTarget` is automatically added to the `make` invocation in addition to any `checkFlags` specified.

##### `checkInputs` {#var-stdenv-checkInputs}

A list of host dependencies used by the phase, usually libraries linked into executables built during tests. This gets included in `buildInputs` when `doCheck` is set.

##### `nativeCheckInputs` {#var-stdenv-nativeCheckInputs}

A list of native dependencies used by the phase, notably tools needed on `$PATH`. This gets included in `nativeBuildInputs` when `doCheck` is set.

##### `preCheck` {#var-stdenv-preCheck}

Hook executed at the start of the check phase.

##### `postCheck` {#var-stdenv-postCheck}

Hook executed at the end of the check phase.

### The install phase {#ssec-install-phase}

The install phase is responsible for installing the package in the Nix store under `out`. The default `installPhase` creates the directory `$out` and calls `make install`.

#### Variables controlling the install phase {#variables-controlling-the-install-phase}

##### `dontInstall` {#var-stdenv-dontInstall}

Set to true to skip the install phase.

##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile-1}

See the [build phase](#var-stdenv-makeFlags) for details.

##### `installTargets` {#var-stdenv-installTargets}

The make targets that perform the installation. Defaults to `install`. Example:

```nix
{ installTargets = "install-bin install-doc"; }
```

##### `installFlags` / `installFlagsArray` {#var-stdenv-installFlags}

A list of strings passed as additional flags to `make`. Like `makeFlags` and `makeFlagsArray`, but only used by the install phase. Unlike with `buildFlags`, the `installTargets` are automatically added to the `make` invocation in addition to any `installFlags` specified.

Title: Nix `stdenv` Build, Check, and Install Phase Customization
Summary
This document details advanced customization for the `stdenv` phases, specifically covering the tail end of the build phase, and the entire check and install phases. For the build phase, it explains `buildFlags`/`buildFlagsArray` for `make` and the `preBuild`/`postBuild` hooks. The check phase, controlled by `doCheck`, runs package test suites using `make $checkTarget`. It supports `checkFlags`/`checkFlagsArray` for specific `make` arguments, `checkInputs`/`nativeCheckInputs` for dependencies, and `preCheck`/`postCheck` hooks; `makeFlags` and `makefile` also apply. The install phase handles package installation to `$out` using `make install` by default, customizable with `dontInstall` to skip it, `installTargets` for specific `make` targets, and `installFlags`/`installFlagsArray` for `make` arguments.