Home Explore Blog Models CI



nixpkgs

15th chunk of `doc/stdenv/stdenv.chapter.md`
ab880ef9c464491874cd196168b14a41889d22f819c81f0a0000000100001017
##### `dontAddStaticConfigureFlags` {#var-stdenv-dontAddStaticConfigureFlags}

By default, when building statically, `stdenv` will try to add build system appropriate configure flags to try to enable static builds.

If this is undesirable, set this variable to true.

##### `dontAddDisableDepTrack` {#var-stdenv-dontAddDisableDepTrack}

By default, the flag `--disable-dependency-tracking` is added to the configure flags to speed up Automake-based builds. If this is undesirable, set this variable to true.

##### `dontFixLibtool` {#var-stdenv-dontFixLibtool}

By default, the configure phase applies some special hackery to all files called `ltmain.sh` before running the configure script in order to improve the purity of Libtool-based packages [^footnote-stdenv-sys-lib-search-path] . If this is undesirable, set this variable to true.

##### `dontDisableStatic` {#var-stdenv-dontDisableStatic}

By default, when the configure script has `--enable-static`, the option `--disable-static` is added to the configure flags.

If this is undesirable, set this variable to true.  It is automatically set to true when building statically, for example through `pkgsStatic`.

##### `configurePlatforms` {#var-stdenv-configurePlatforms}

By default, when cross compiling, the configure script has `--build=...` and `--host=...` passed. Packages can instead pass `[ "build" "host" "target" ]` or a subset to control exactly which platform flags are passed. Compilers and other tools can use this to also pass the target platform. [^footnote-stdenv-build-time-guessing-impurity]

##### `preConfigure` {#var-stdenv-preConfigure}

Hook executed at the start of the configure phase.

##### `postConfigure` {#var-stdenv-postConfigure}

Hook executed at the end of the configure phase.

### The build phase {#build-phase}

The build phase is responsible for actually building the package (e.g. compiling it). The default `buildPhase` calls `make` if a file named `Makefile`, `makefile` or `GNUmakefile` exists in the current directory (or the `makefile` is explicitly set); otherwise it does nothing.

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

##### `dontBuild` {#var-stdenv-dontBuild}

Set to true to skip the build phase.

##### `makefile` {#var-stdenv-makefile}

The file name of the Makefile.

##### `makeFlags` {#var-stdenv-makeFlags}

A list of strings passed as additional flags to `make`. These flags are also used by the default install and check phase. For setting make flags specific to the build phase, use `buildFlags` (see below).

```nix
{ makeFlags = [ "PREFIX=$(out)" ]; }
```

::: {.note}
The flags are quoted in bash, but environment variables can be specified by using the make syntax.
:::

##### `makeFlagsArray` {#var-stdenv-makeFlagsArray}

A shell array containing additional arguments passed to `make`. You must use this instead of `makeFlags` if the arguments contain spaces, e.g.

```nix
{
  preBuild = ''
    makeFlagsArray+=(CFLAGS="-O0 -g" LDFLAGS="-lfoo -lbar")
  '';
}
```

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.

Title: Nix `stdenv` Build System: Configure, Build, and Check Phase Customization
Summary
This document extends the explanation of `stdenv` build phases, covering `configurePhase`, `buildPhase`, and `checkPhase`. The `configurePhase` can be customized with variables like `dontAddStaticConfigureFlags`, `dontAddDisableDepTrack`, `dontFixLibtool`, `dontDisableStatic`, and `configurePlatforms` for cross-compiling, along with `preConfigure` and `postConfigure` hooks. The `buildPhase` compiles the package, defaulting to `make`. Customization includes `dontBuild` to skip, `makefile` to specify the Makefile, and `makeFlags`/`makeFlagsArray` (general `make` arguments) or `buildFlags`/`buildFlagsArray` (build-phase specific arguments). `preBuild` and `postBuild` hooks are also available. The `checkPhase` runs the test suite (`make $checkTarget`) if `doCheck` is enabled.