You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* moved spec to it's own file
* included spec into the markdown
* mentioned sorted order of directory entries
* moved nix-archive.md to it's own directory
[file system object]: @docroot@/store/file-system-object.md
9
+
10
+
The format of this specification is close to [Extended Backus–Naur form](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form), with the exception of the `str(..)` function / parameterized rule, which length-prefixes and pads strings.
11
+
This makes the resulting binary format easier to parse.
12
+
13
+
Regular users do *not* need to know this information.
14
+
But for those interested in exactly how Nix works, e.g. if they are reimplementing it, this information can be useful.
The `str` function / parameterized rule is defined as follows:
38
+
39
+
-`str(s)` = `int(|s|), pad(s);`
40
+
41
+
-`int(n)` = the 64-bit little endian representation of the number `n`
42
+
43
+
-`pad(s)` = the byte sequence `s`, padded with 0s to a multiple of 8 byte
44
+
45
+
## Kaitai Struct Specification
46
+
47
+
The Nix Archive (NAR) format is also formally described using [Kaitai Struct](https://kaitai.io/), an Interface Description Language (IDL) for defining binary data structures.
48
+
49
+
> Kaitai Struct provides a language-agnostic, machine-readable specification that can be compiled into parsers for various programming languages (e.g., C++, Python, Java, Rust).
50
+
51
+
```yaml
52
+
{{#include nar.ksy}}
53
+
```
54
+
55
+
The source of the spec can be found [here](https://github.com/nixos/nix/blob/master/src/nix-manual/source/protocols/nix-archive/nar.ksy). Contributions and improvements to the spec are welcomed.
[file system object]: @docroot@/store/file-system-object.md
9
-
10
-
The format of this specification is close to [Extended Backus–Naur form](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form), with the exception of the `str(..)` function / parameterized rule, which length-prefixes and pads strings.
11
-
This makes the resulting binary format easier to parse.
12
-
13
-
Regular users do *not* need to know this information.
14
-
But for those interested in exactly how Nix works, e.g. if they are reimplementing it, this information can be useful.
The `str` function / parameterized rule is defined as follows:
38
-
39
-
-`str(s)` = `int(|s|), pad(s);`
40
-
41
-
-`int(n)` = the 64-bit little endian representation of the number `n`
42
-
43
-
-`pad(s)` = the byte sequence `s`, padded with 0s to a multiple of 8 byte
44
-
45
-
## Kaitai Struct Specification
46
-
47
-
The Nix Archive (NAR) format is also formally described using [Kaitai Struct](https://kaitai.io/), an Interface Description Language (IDL) for defining binary data structures.
48
-
49
-
> Kaitai Struct provides a language-agnostic, machine-readable specification that can be compiled into parsers for various programming languages (e.g., C++, Python, Java, Rust).
50
-
51
-
```yaml
52
1
meta:
53
2
id: nix_nar
54
3
title: Nix Archive (NAR)
@@ -115,7 +64,7 @@ types:
115
64
doc: "Must be ')', a token ending the node definition."
116
65
117
66
type_directory:
118
-
doc: "A directory node, containing a list of entries."
67
+
doc: "A directory node, containing a list of entries. Entries must be ordered by their names."
119
68
seq:
120
69
- id: entries
121
70
type: dir_entry
@@ -196,7 +145,7 @@ types:
196
145
seq:
197
146
- id: len_contents
198
147
type: u8
199
-
# This relies on the property of instances that they are lazily evaluated and cached.
148
+
## This relies on the property of instances that they are lazily evaluated and cached.
200
149
- size: 0
201
150
if: nar_offset < 0
202
151
- id: contents
@@ -217,7 +166,4 @@ types:
217
166
expr: _.body == 'target'
218
167
- id: target_val
219
168
type: padded_str
220
-
doc: "The destination path of the symlink."
221
-
```
222
-
223
-
The source of the spec can be found [here](https://github.com/fzakaria/nix-nar-kaitai-spec/blob/main/NAR.ksy). Contributions and improvements to the spec are welcomed.
0 commit comments