Derivation

Title: Derivation

Typeobject
RequiredNo
Additional propertiesAny type allowed

Description: Experimental JSON representation of a Nix derivation (version 4).

This schema describes the JSON representation of Nix's Derivation type.

Warning

This JSON format is currently experimental and subject to change.

PropertyTypePatternTitle/Description
+ namestringNoDerivation name
+ versionconstNoFormat version (must be 4)
+ outputsobjectNoOutput specifications
+ inputsobjectNoDerivation inputs
+ systemstringNoBuild system type
+ builderstringNoBuild program path
+ argsarray of stringNoBuilder arguments
+ envobjectNoEnvironment variables
- structuredAttrsobjectNoStructured attributes

1. Property name

Title: Derivation name

Typestring
RequiredYes

Description: The name of the derivation. Used when calculating store paths for the derivation’s outputs.

2. Property version

Title: Format version (must be 4)

Typeconst
RequiredYes

Description: Must be 4. This is a guard that allows us to continue evolving this format. The choice of 3 is fairly arbitrary, but corresponds to this informal version:

  • Version 0: ATerm format

  • Version 1: Original JSON format, with ugly "r:sha256" inherited from ATerm format.

  • Version 2: Separate method and hashAlgo fields in output specs

  • Version 3: Drop store dir from store paths, just include base name.

  • Version 4: Two cleanups, batched together to lesson churn:

    • Reorganize inputs into nested structure (inputs.srcs and inputs.drvs)

    • Use canonical content address JSON format for floating content addressed derivation outputs.

Note that while this format is experimental, the maintenance of versions is best-effort, and not promised to identify every change.

Specific value: 4

3. Property outputs

Title: Output specifications

Typeobject
RequiredYes
Additional propertiesEach additional property must conform to the schema

Description: Information about the output paths of the derivation. This is a JSON object with one member per output, where the key is the output name and the value is a JSON object as described.

Example

"outputs": {
  "out": {
    "method": "nar",
    "hashAlgo": "sha256",
    "hash": "6fc80dcc62179dbc12fc0b5881275898f93444833d21b89dfe5f7fbcbb1d0d62"
  }
}
PropertyTypePatternTitle/Description
- objectNoDerivation Output

3.1. Property Derivation Output

Title: Derivation Output

Typecombining
RequiredNo
Additional propertiesAny type allowed
Defined in#/$defs/output/overall

Description: A single output of a derivation, with different variants for different output types.

3.1.1. Property Input-Addressed Output

Title: Input-Addressed Output

Typeobject
RequiredNo
Additional propertiesNot allowed
Defined in#/$defs/output/inputAddressed

Description: The traditional non-fixed-output derivation type. The output path is determined from the derivation itself.

See Input-addressing derivation outputs for more details.

PropertyTypePatternTitle/Description
+ pathstringNoOutput path
3.1.1.1. Property path

Title: Output path

Typestring
RequiredYes
Defined instore-path-v1.yaml

Description: The output path determined from the derivation itself.

Restrictions
Min length34
Must match regular expression^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+$ Test

3.1.2. Property Fixed Content-Addressed Output

Title: Fixed Content-Addressed Output

Typeobject
RequiredNo
Additional propertiesNot allowed
Defined in#/$defs/output/caFixed

Description: The output is content-addressed, and the content-address is fixed in advance.

See Fixed-output content-addressing for more details.

PropertyTypePatternTitle/Description
+ methodenum (of string)NoContent-Addressing Method
+ hashstringNoExpected hash value
3.1.2.1. Property method

Title: Content-Addressing Method

Typeenum (of string)
RequiredYes
Defined inJSON format for ContentAddress

Description: Method of content addressing used for this output.

Must be one of:

  • "flat"
  • "nar"
  • "text"
  • "git"
3.1.2.2. Property hash

Title: Expected hash value

Typestring
RequiredYes
Defined inJSON format for Hash

Description: The expected content hash.

Examples:

"sha256-ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="
"sha512-IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="
Restrictions
Must match regular expression^(blake3|md5|sha1|sha256|sha512)-[A-Za-z0-9+/]+=*$ Test

3.1.3. Property Floating Content-Addressed Output

Title: Floating Content-Addressed Output

Typeobject
RequiredNo
Additional propertiesNot allowed
Defined in#/$defs/output/caFloating

Description: Floating-output derivations, whose outputs are content addressed, but not fixed, and so the output paths are dynamically calculated from whatever the output ends up being.

See Floating Content-Addressing for more details.

PropertyTypePatternTitle/Description
+ methodenum (of string)NoContent-Addressing Method
+ hashAlgoenum (of string)NoHash algorithm
3.1.3.1. Property method

Title: Content-Addressing Method

Typeenum (of string)
RequiredYes
Same definition asmethod

Description: Method of content addressing used for this output.

3.1.3.2. Property hashAlgo

Title: Hash algorithm

Typeenum (of string)
RequiredYes
Defined inJSON format for Hash

Description: What hash algorithm to use for the given method of content-addressing.

Must be one of:

  • "blake3"
  • "md5"
  • "sha1"
  • "sha256"
  • "sha512"

3.1.4. Property Deferred Output

Title: Deferred Output

Typeobject
RequiredNo
Additional propertiesAny type allowed
Defined in#/$defs/output/deferred

Description: Input-addressed output which depends on a (CA) derivation whose outputs (and thus their content-address are not yet known.

3.1.5. Property Impure Output

Title: Impure Output

Typeobject
RequiredNo
Additional propertiesNot allowed
Defined in#/$defs/output/impure

Description: Impure output which is just like a floating content-addressed output, but this derivation runs without sandboxing. As such, we don't record it in the build trace, under the assumption that if we need it again, we should rebuild it, as it might produce something different.

PropertyTypePatternTitle/Description
+ impureconstNo-
+ methodenum (of string)NoContent-Addressing Method
+ hashAlgoenum (of string)NoHash algorithm
3.1.5.1. Property impure
Typeconst
RequiredYes

Specific value: true

3.1.5.2. Property method

Title: Content-Addressing Method

Typeenum (of string)
RequiredYes
Same definition asmethod

Description: How the file system objects will be serialized for hashing.

3.1.5.3. Property hashAlgo

Title: Hash algorithm

Typeenum (of string)
RequiredYes
Defined inJSON format for Hash

Description: How the serialization will be hashed.

Must be one of:

  • "blake3"
  • "md5"
  • "sha1"
  • "sha256"
  • "sha512"

4. Property inputs

Title: Derivation inputs

Typeobject
RequiredYes
Additional propertiesNot allowed

Description: Input dependencies for the derivation, organized into source paths and derivation dependencies.

PropertyTypePatternTitle/Description
+ srcsarrayNoInput source paths
+ drvsobjectNoInput derivations

4.1. Property srcs

Title: Input source paths

Typearray
RequiredYes

Description: List of store paths on which this derivation depends.

Example

"srcs": [
  "47y241wqdhac3jm5l7nv0x4975mb1975-separate-debug-info.sh",
  "56d0w71pjj9bdr363ym3wj1zkwyqq97j-fix-pop-var-context-error.patch"
]
Array restrictions
Min itemsN/A
Max itemsN/A
Items unicityFalse
Additional itemsFalse
Tuple validationSee below
Each item of this array must beDescription
Store PathA store path identifying a store object. ...

4.1.1. Store Path

Title: Store Path

Typestring
RequiredNo
Same definition aspath

Description: A store path identifying a store object.

This schema describes the JSON representation of store paths as used in various Nix JSON APIs.

Format

Store paths in JSON are represented as strings containing just the hash and name portion, without the store directory prefix.

For example: "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"

(If the store dir is /nix/store, then this corresponds to the path /nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv.)

Structure

The format follows this pattern: ${digest}-${name}

  • hash: Digest rendered in a custom variant of Base32 (20 arbitrary bytes become 32 ASCII characters)
  • name: The package name and optional version/suffix information

4.2. Property drvs

Title: Input derivations

Typeobject
RequiredYes
Additional propertiesNot allowed

Description: Mapping of derivation paths to lists of output names they provide.

Example

"drvs": {
  "6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
  "fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
}

specifies that this derivation depends on the dev output of curl, and the out output of unzip.

PropertyTypePatternTitle/Description
- ^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+.drv$CombinationYesStore Path

4.2.1. Pattern Property Store Path

All properties whose name matches the regular expression ^[0123456789abcdfghijklmnpqrsvwxyz]{32}-.+\.drv$ (Test) must respect the following conditions

Title: Store Path

Typecombining
RequiredNo
Additional propertiesAny type allowed

Description: A store path to a derivation, mapped to the outputs of that derivation.

4.2.1.1. Property Output Names

Title: Output Names

Typearray
RequiredNo
Defined in#/$defs/outputNames

Description: Set of names of derivation outputs to depend on

Array restrictions
Min itemsN/A
Max itemsN/A
Items unicityFalse
Additional itemsFalse
Tuple validationSee below
Each item of this array must beDescription
Output nameName of the derivation output to depend on
4.2.1.1.1. Output name

Title: Output name

Typestring
RequiredNo
Defined in#/$defs/outputName

Description: Name of the derivation output to depend on

4.2.1.2. Property Dynamic Outputs

Title: Dynamic Outputs

Typeobject
RequiredNo
Additional propertiesAny type allowed
Defined in#/$defs/dynamicOutputs

Description: Experimental feature: dynamic-derivations

This recursive data type allows for depending on outputs of outputs.

PropertyTypePatternTitle/Description
- outputsarrayNoOutput Names
- dynamicOutputsobjectNoDynamic Outputs
4.2.1.2.1. Property outputs

Title: Output Names

Typearray
RequiredNo
Same definition asOutput Names

Description: Set of names of derivation outputs to depend on

4.2.1.2.2. Property dynamicOutputs

Title: Dynamic Outputs

Typeobject
RequiredNo
Additional propertiesAny type allowed
Same definition asDynamic Outputs

Description: Experimental feature: dynamic-derivations

This recursive data type allows for depending on outputs of outputs.

5. Property system

Title: Build system type

Typestring
RequiredYes

Description: The system type on which this derivation is to be built (e.g. x86_64-linux).

6. Property builder

Title: Build program path

Typestring
RequiredYes

Description: Absolute path of the program used to perform the build. Typically this is the bash shell (e.g. /nix/store/r3j288vpmczbl500w6zz89gyfa4nr0b1-bash-4.4-p23/bin/bash).

7. Property args

Title: Builder arguments

Typearray of string
RequiredYes

Description: Command-line arguments passed to the builder.

Array restrictions
Min itemsN/A
Max itemsN/A
Items unicityFalse
Additional itemsFalse
Tuple validationSee below
Each item of this array must beDescription
args items-

7.1. args items

Typestring
RequiredNo

8. Property env

Title: Environment variables

Typeobject
RequiredYes
Additional propertiesEach additional property must conform to the schema

Description: Environment variables passed to the builder.

PropertyTypePatternTitle/Description
- stringNo-

8.1. Property additionalProperties

Typestring
RequiredNo

9. Property structuredAttrs

Title: Structured attributes

Typeobject
RequiredNo
Additional propertiesAny type allowed

Description: Structured Attributes, only defined if the derivation contains them. Structured attributes are JSON, and thus embedded as-is.

PropertyTypePatternTitle/Description
- objectNo-