Skip to content

Commit

Permalink
docs: Use secret-key-files when demonstrating post-build-hooks
Browse files Browse the repository at this point in the history
The docs used to recommend calling `nix store sign` in a post-build
hook, but on more recent versions of nix, this results in unsigned
store paths being copied into binary caches. See
#6960 for details.

Instead, use the `secret-key-files` config option, which signs all
locally-built derivations with the private key.
  • Loading branch information
endgame committed Dec 7, 2022
1 parent 237f502 commit 8748bdf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions doc/manual/src/advanced-topics/post-build-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ distribute the public key for verifying the authenticity of the paths.
example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=
```

Then, add the public key and the cache URL to your `nix.conf`'s
`trusted-public-keys` and `substituters` options:
Then update [`nix.conf`](../command-ref/conf-file.md) on any machine that will access the cache, adding the cache URL to [`substituters`](../command-ref/conf-file.md#conf-substituters) and the public key to [`trusted-public-keys`](../command-ref/conf-file.md#conf-trusted-public-keys):

substituters = https://cache.nixos.org/ s3://example-nix-cache
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= example-nix-cache-1:1/cKDz3QCCOmwcztD2eV6Coggp6rqc9DGjWv7C0G+rM=

Machines that build for the cache must sign derivations using the private key. Add the path to the key file to the [`secret-key-files`](../command-ref/conf-file.md#conf-secret-key-files) field in their [`nix.conf`](../command-ref/conf-file.md):

secret-key-files = /etc/nix/key.private

We will restart the Nix daemon in a later step.

# Implementing the build hook
Expand All @@ -52,10 +55,8 @@ set -eu
set -f # disable globbing
export IFS=' '

echo "Signing paths" $OUT_PATHS
nix store sign --key-file /etc/nix/key.private $OUT_PATHS
echo "Uploading paths" $OUT_PATHS
exec nix copy --to 's3://example-nix-cache' $OUT_PATHS
exec nix copy --to "s3://example-nix-cache" $OUT_PATHS
```

> **Note**
Expand Down

0 comments on commit 8748bdf

Please sign in to comment.