Skip to content

Commit 3fb0fb0

Browse files
authored
Merge pull request #15004 from roberth/docs
Add Nix32 encoding documentation
2 parents a9b1a52 + 3374fdc commit 3fb0fb0

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
- [Store Path Specification](protocols/store-path.md)
137137
- [Nix Archive (NAR) Format](protocols/nix-archive/index.md)
138138
- [Derivation "ATerm" file format](protocols/derivation-aterm.md)
139+
- [Nix32 Encoding](protocols/nix32.md)
139140
- [C API](c-api.md)
140141
- [Glossary](glossary.md)
141142
- [Development](development/index.md)

doc/manual/source/language/advanced-attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Here is more information on the `output*` attributes, and what values they may b
338338
This will specify the output hash of the single output of a [fixed-output derivation].
339339
340340
The `outputHash` attribute must be a string containing the hash in either hexadecimal or "nix32" encoding, or following the format for integrity metadata as defined by [SRI](https://www.w3.org/TR/SRI/).
341-
The "nix32" encoding is an adaptation of base-32 encoding.
341+
The ["nix32" encoding](@docroot@/protocols/nix32.md) is Nix's variant of base-32 encoding.
342342
343343
> **Note**
344344
>

doc/manual/source/protocols/json/schema/store-path-v1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ description: |
2424
2525
The format follows this pattern: `${digest}-${name}`
2626
27-
- **hash**: Digest rendered in a custom variant of [Base32](https://en.wikipedia.org/wiki/Base32) (20 arbitrary bytes become 32 ASCII characters)
27+
- **hash**: Digest rendered in [Nix32](@docroot@/protocols/nix32.md), a variant of base-32 (20 hash bytes become 32 ASCII characters)
2828
- **name**: The package name and optional version/suffix information
2929
3030
type: string
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Nix32 Encoding
2+
3+
Nix32 is Nix's variant of base-32 encoding, used for [store path digests](@docroot@/protocols/store-path.md), hash output via [`nix hash`](@docroot@/command-ref/new-cli/nix3-hash.md), and the [`outputHash`](@docroot@/language/advanced-attributes.md#adv-attr-outputHash) derivation attribute.
4+
5+
## Alphabet
6+
7+
The Nix32 alphabet consists of these 32 characters:
8+
9+
```
10+
0 1 2 3 4 5 6 7 8 9 a b c d f g h i j k l m n p q r s v w x y z
11+
```
12+
13+
The letters `e`, `o`, `u`, and `t` are omitted.
14+
15+
## Byte Order
16+
17+
Nix32 encoding processes the hash bytes from the end (last byte first), while base-16 encoding processes from the beginning (first byte first).
18+
19+
Consequently, the string sort order is determined primarily by the first bytes for base-16, and by the last bytes for Nix32.

doc/manual/source/protocols/store-path.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ where
2020

2121
- `store-dir` = the [store directory](@docroot@/store/store-path.md#store-directory)
2222

23-
- `digest` = base-32 representation of the compressed to 160 bits [SHA-256] hash of `fingerprint`
23+
- `digest` = base-32 representation of the compressed to 160 bits [SHA-256] hash of `fingerprint`.
2424

25-
For the definition of the hash compression algorithm, please refer to the section 5.1 of
26-
the [Nix thesis](https://edolstra.github.io/pubs/phd-thesis.pdf), which also defines the
27-
specifics of base-32 encoding. Note that base-32 encoding processes the hash bytestring from
28-
the end, while base-16 processes in from the beginning.
25+
Nix uses a custom base-32 encoding called [Nix32](@docroot@/protocols/nix32.md).
26+
27+
For the definition of the hash compression algorithm, please refer to section 5.1 of the [Nix thesis](https://edolstra.github.io/pubs/phd-thesis.pdf).
2928

3029
## Fingerprint
3130

doc/manual/source/store/store-path.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ A store path is rendered to a file system path as the concatenation of
3131

3232
- [Store directory](#store-directory) (typically `/nix/store`)
3333
- Path separator (`/`)
34-
- Digest rendered in a custom variant of [Base32](https://en.wikipedia.org/wiki/Base32) (20 arbitrary bytes become 32 ASCII characters)
34+
- Digest rendered in [Nix32](@docroot@/protocols/nix32.md), a variant of base-32 (20 hash bytes become 32 ASCII characters)
3535
- Hyphen (`-`)
3636
- Name
3737

0 commit comments

Comments
 (0)