Skip to content

Commit 95b9d8d

Browse files
authored
Merge pull request NixOS#15006 from roberth/doc-nix-cache-info
doc: add nix-cache-info format documentation
2 parents f130f49 + 4c304bd commit 95b9d8d

3 files changed

Lines changed: 61 additions & 6 deletions

File tree

doc/manual/source/SUMMARY.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
- [Serving Tarball Flakes](protocols/tarball-fetcher.md)
136136
- [Store Path Specification](protocols/store-path.md)
137137
- [Nix Archive (NAR) Format](protocols/nix-archive/index.md)
138+
- [Nix Cache Info Format](protocols/nix-cache-info.md)
138139
- [Derivation "ATerm" file format](protocols/derivation-aterm.md)
139140
- [Nix32 Encoding](protocols/nix32.md)
140141
- [C API](c-api.md)

doc/manual/source/package-management/binary-cache-substituter.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ whatever port you like:
1919
$ nix-serve -p 8080
2020
```
2121

22-
To check whether it works, try the following on the client:
22+
To check whether it works, try fetching the [`nix-cache-info`](@docroot@/protocols/nix-cache-info.md) file on the client:
2323

2424
```console
2525
$ curl http://avalon:8080/nix-cache-info
26+
StoreDir: /nix/store
27+
WantMassQuery: 1
28+
Priority: 30
2629
```
2730

28-
which should print something like:
29-
30-
StoreDir: /nix/store
31-
WantMassQuery: 1
32-
Priority: 30
31+
When writing to a binary cache (e.g., with [`nix copy`](@docroot@/command-ref/new-cli/nix3-copy.md)), Nix creates [`nix-cache-info`](@docroot@/protocols/nix-cache-info.md) automatically if it doesn't exist.
3332

3433
On the client side, you can tell Nix to use your binary cache using
3534
`--substituters`, e.g.:
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Nix Cache Info Format
2+
3+
The `nix-cache-info` file is a metadata file at the root of a [binary cache](@docroot@/package-management/binary-cache-substituter.md) (e.g., `https://cache.example.com/nix-cache-info`).
4+
5+
MIME type: `text/x-nix-cache-info`
6+
7+
## Format
8+
9+
Line-based key-value format:
10+
11+
```
12+
Key: value
13+
```
14+
15+
Leading and trailing whitespace is trimmed from values.
16+
Lines without a colon are ignored.
17+
Unknown keys are silently ignored.
18+
19+
## Fields
20+
21+
### `StoreDir`
22+
23+
The Nix store directory path that this cache was built for (e.g., `/nix/store`).
24+
25+
If present, Nix verifies that this matches the client's store directory:
26+
27+
```
28+
error: binary cache 'https://example.com' is for Nix stores with prefix '/nix/store', not '/home/user/nix/store'
29+
```
30+
31+
### `WantMassQuery`
32+
33+
`1` or `0`. Sets the default for [`want-mass-query`](@docroot@/store/types/http-binary-cache-store.md#store-http-binary-cache-store-want-mass-query).
34+
35+
### `Priority`
36+
37+
Integer. Sets the default for [`priority`](@docroot@/store/types/http-binary-cache-store.md#store-http-binary-cache-store-priority).
38+
39+
## Example
40+
41+
```
42+
StoreDir: /nix/store
43+
WantMassQuery: 1
44+
Priority: 30
45+
```
46+
47+
## Caching Behavior
48+
49+
Nix caches `nix-cache-info` in the [cache directory](@docroot@/command-ref/env-common.md#env-NIX_CACHE_HOME) with a 7-day TTL.
50+
51+
## See Also
52+
53+
- [HTTP Binary Cache Store](@docroot@/store/types/http-binary-cache-store.md)
54+
- [Serving a Nix store via HTTP](@docroot@/package-management/binary-cache-substituter.md)
55+
- [`substituters`](@docroot@/command-ref/conf-file.md#conf-substituters)

0 commit comments

Comments
 (0)