Skip to content

Commit

Permalink
Pull out JSON format for derivations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Nov 13, 2023
1 parent 99abf36 commit 2ff299d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 64 deletions.
1 change: 1 addition & 0 deletions doc/manual/src/SUMMARY.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
- [Architecture and Design](architecture/architecture.md)
- [JSON Formats](json/json.md)
- [Store Object Info](json/store-object-info.md)
- [Derivation](json/derivation.md)
- [Protocols](protocols/protocols.md)
- [Serving Tarball Flakes](protocols/tarball-fetcher.md)
- [Derivation "ATerm" file format](protocols/derivation-aterm.md)
Expand Down
62 changes: 62 additions & 0 deletions doc/manual/src/json/derivation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
The JSON serialization of a
[store derivation](@docroot@/glossary.md#gloss-store-derivation)
is a JSON object whose keys are the store paths of the derivations, and whose values are a JSON object with the following fields:

* `name`:
The name of the derivation.
This is used when calculating the store paths of the derivation's outputs.

* `outputs`:
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 with these fields:

* `path`: The output path.

* `hashAlgo`:
For fixed-output derivations, the hashing algorithm (e.g. `sha256`), optionally prefixed by `r:` if `hash` denotes a NAR hash rather than a flat file hash.

* `hash`:
For fixed-output derivations, the expected content hash in base-16.

Example:

```json
"outputs": {
"out": {
"path": "/nix/store/2543j7c6jn75blc3drf4g5vhb1rhdq29-source",
"hashAlgo": "r:sha256",
"hash": "6fc80dcc62179dbc12fc0b5881275898f93444833d21b89dfe5f7fbcbb1d0d62"
}
}
```

* `inputSrcs`:
A list of store paths on which this derivation depends.

* `inputDrvs`:
A JSON object specifying the derivations on which this derivation depends, and what outputs of those derivations.
For example,

```json
"inputDrvs": {
"/nix/store/6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
"/nix/store/fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
}
```

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

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

* `builder`:
The absolute path of the program to be executed to run the build.
Typically this is the `bash` shell
(e.g. `/nix/store/r3j288vpmczbl500w6zz89gyfa4nr0b1-bash-4.4-p23/bin/bash`).

* `args`:
The command-line arguments passed to the `builder`.

* `env`:
The environment passed to the `builder`.
11 changes: 7 additions & 4 deletions doc/manual/src/json/store-object-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ Info about a [store object].

* `path`:

[Store path](TODO) to the given store object.
[Store path][store path] to the given store object.

* `narHash`:

Hash of the [file system object](TODO) part of the store object when serialized as a [Nix Archive](..).
Hash of the [file system object] part of the store object when serialized as a [Nix Archive](#gloss-nar).

* `narSize`:

Size of the [file system object](TODO) part of the store object when serialized as a [Nix Archive](..).
Size of the [file system object] part of the store object when serialized as a [Nix Archive](#gloss-nar).

* `references`:

An array of [store paths](TODO), possibly including this one.
An array of [store paths][store path], possibly including this one.

* `ca` (optional):

Content address of this store object's file system object, used to compute its store path.

[store path]: @docroot@/glossary.md#gloss-store-path
[file system object]: @docroot@/architecture/file-system-object.md

## Impure fields

These are not intrinsic properties of the store object.
Expand Down
7 changes: 4 additions & 3 deletions src/nix/derivation-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Store derivations are used internally by Nix. They are store paths with
extension `.drv` that represent the build-time dependency graph to which
a Nix expression evaluates.

[store derivation]: ../../glossary.md#gloss-store-derivation

The JSON format is documented under the [`derivation show`] command.
[store derivation]: @docroot@/glossary.md#gloss-store-derivation

[`derivation show`]: ./nix3-derivation-show.md
# JSON Format

{{#include ../../json/derivation.md}}

)""
60 changes: 3 additions & 57 deletions src/nix/derivation-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ R""(
* Show the [store derivation] that results from evaluating the Hello
package:

[store derivation]: ../../glossary.md#gloss-store-derivation

```console
# nix derivation show nixpkgs#hello
{
Expand Down Expand Up @@ -48,62 +46,10 @@ a Nix expression evaluates.
By default, this command only shows top-level derivations, but with
`--recursive`, it also shows their dependencies.

The JSON output is a JSON object whose keys are the store paths of the
derivations, and whose values are a JSON object with the following
fields:

* `name`: The name of the derivation. This is used when calculating the
store paths of the derivation's outputs.

* `outputs`: 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 with these
fields:

* `path`: The output path.
* `hashAlgo`: For fixed-output derivations, the hashing algorithm
(e.g. `sha256`), optionally prefixed by `r:` if `hash` denotes a
NAR hash rather than a flat file hash.
* `hash`: For fixed-output derivations, the expected content hash in
base-16.

Example:

```json
"outputs": {
"out": {
"path": "/nix/store/2543j7c6jn75blc3drf4g5vhb1rhdq29-source",
"hashAlgo": "r:sha256",
"hash": "6fc80dcc62179dbc12fc0b5881275898f93444833d21b89dfe5f7fbcbb1d0d62"
}
}
```

* `inputSrcs`: A list of store paths on which this derivation depends.

* `inputDrvs`: A JSON object specifying the derivations on which this
derivation depends, and what outputs of those derivations. For
example,

```json
"inputDrvs": {
"/nix/store/6lkh5yi7nlb7l6dr8fljlli5zfd9hq58-curl-7.73.0.drv": ["dev"],
"/nix/store/fn3kgnfzl5dzym26j8g907gq3kbm8bfh-unzip-6.0.drv": ["out"]
}
```

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

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

* `builder`: The absolute path of the program to be executed to run
the build. Typically this is the `bash` shell
(e.g. `/nix/store/r3j288vpmczbl500w6zz89gyfa4nr0b1-bash-4.4-p23/bin/bash`).
[store derivation]: @docroot@/glossary.md#gloss-store-derivation

* `args`: The command-line arguments passed to the `builder`.
# JSON Format

* `env`: The environment passed to the `builder`.
{{#include ../../json/derivation.md}}

)""

0 comments on commit 2ff299d

Please sign in to comment.