Home Explore Blog CI



nixpkgs

13th chunk of `doc/stdenv/stdenv.chapter.md`
6ac834e18cf432997c4d577550120b07524cd503c226e50a0000000100000fbc
For example, if you are using `fetchurl` on an archive file that gets unpacked into a single directory the name of which changes between package versions, and you want your build to start in its sub-directory, you need to set `setSourceRoot = "sourceRoot=$(echo */my-sub-directory)";`, or in the case of multiple sources, you could use something more specific, like `setSourceRoot = "sourceRoot=$(echo ${pname}-*/my-sub-directory)";`.

##### `preUnpack` {#var-stdenv-preUnpack}

Hook executed at the start of the unpack phase.

##### `postUnpack` {#var-stdenv-postUnpack}

Hook executed at the end of the unpack phase.

##### `dontUnpack` {#var-stdenv-dontUnpack}

Set to true to skip the unpack phase.

##### `dontMakeSourcesWritable` {#var-stdenv-dontMakeSourcesWritable}

If set to `1`, the unpacked sources are *not* made writable. By default, they are made writable to prevent problems with read-only sources. For example, copied store directories would be read-only without this.

##### `unpackCmd` {#var-stdenv-unpackCmd}

The unpack phase evaluates the string `$unpackCmd` for any unrecognised file. The path to the current source file is contained in the `curSrc` variable.

### The patch phase {#ssec-patch-phase}

The patch phase applies the list of patches defined in the `patches` variable.

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

##### `dontPatch` {#var-stdenv-dontPatch}

Set to true to skip the patch phase.

##### `patches` {#var-stdenv-patches}

The list of patches. They must be in the format accepted by the `patch` command, and may optionally be compressed using `gzip` (`.gz`), `bzip2` (`.bz2`) or `xz` (`.xz`).

##### `patchFlags` {#var-stdenv-patchFlags}

Flags to be passed to `patch`. If not set, the argument `-p1` is used, which causes the leading directory component to be stripped from the file names in each patch.

##### `prePatch` {#var-stdenv-prePatch}

Hook executed at the start of the patch phase.

##### `postPatch` {#var-stdenv-postPatch}

Hook executed at the end of the patch phase.

### The configure phase {#ssec-configure-phase}

The configure phase prepares the source tree for building. The default `configurePhase` runs `./configure` (typically an Autoconf-generated script) if it exists.

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

##### `configureScript` {#var-stdenv-configureScript}

The name of the configure script. It defaults to `./configure` if it exists; otherwise, the configure phase is skipped. This can actually be a command (like `perl ./Configure.pl`).

##### `configureFlags` {#var-stdenv-configureFlags}

A list of strings passed as additional arguments to the configure script.

##### `dontConfigure` {#var-stdenv-dontConfigure}

Set to true to skip the configure phase.

##### `configureFlagsArray` {#var-stdenv-configureFlagsArray}

A shell array containing additional arguments passed to the configure script. You must use this instead of `configureFlags` if the arguments contain spaces.

##### `dontAddPrefix` {#var-stdenv-dontAddPrefix}

By default, `./configure` is passed the concatenation of [`prefixKey`](#var-stdenv-prefixKey) and [`prefix`](#var-stdenv-prefix) on the command line. Disable this by setting `dontAddPrefix` to `true`.

##### `prefix` {#var-stdenv-prefix}

The prefix under which the package must be installed, passed via the `--prefix` option to the configure script. It defaults to `$out`.

##### `prefixKey` {#var-stdenv-prefixKey}

The key to use when specifying the installation [`prefix`](#var-stdenv-prefix). By default, this is set to `--prefix=` as that is used by the majority of packages. Other packages may need `--prefix ` (with a trailing space) or `PREFIX=`.

##### `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.

Title: Patch and Configure Phases in Nix Builds
Summary
This section continues the description of Nix build phases, focusing on the patch and configure phases. The patch phase involves applying patches from the `patches` variable, controlled by variables like `dontPatch`, `patchFlags`, `prePatch`, and `postPatch`. The configure phase prepares the build environment, typically running a `./configure` script, configurable via `configureScript`, `configureFlags`, `dontConfigure`, `configureFlagsArray`, `dontAddPrefix`, `prefix`, `prefixKey`, and `dontAddStaticConfigureFlags`.