Skip to content
kasha

Getting started

In this tutorial you run a box locally, push a signed build of hello to it with plain nix copy, and pull it back into a fresh store, gated by your signing key. It takes about five minutes and needs no S3 bucket.

You need Nix with the nix-command and flakes experimental features enabled, and curl. Everything happens in a scratch directory; your own Nix store is only read.

Terminal window
mkdir kasha-tutorial && cd kasha-tutorial

The box never signs anything: it only accepts paths signed by a key it trusts. Generate a throwaway key pair:

Terminal window
nix key generate-secret --key-name demo-1 > secret-key
nix key convert-secret-to-public < secret-key > public-key
cat public-key
demo-1:3SEmxzPlTj0luByKrJ9hB5lOmfpOXRvGk1pPNm2/XV0=

Your key differs; demo-1: is the name you chose.

In a second terminal, in the same directory, start the box. It trusts your public key and accepts writes authenticated with the token demo-token:

Terminal window
KASHA_TOKEN=demo-token nix run github:Zebradil/kasha -- serve \
--data ./box --listen 127.0.0.1:5000 --trusted-keys "$(cat public-key)"

The box warns KASHA_REMOTE unset: mirroring and GC disabled, since no remote cache is configured, then logs kasha serving with its listen address.

Back in the first terminal, ask the box for its status:

Terminal window
curl -s http://127.0.0.1:5000/status
{"flakes":{},"objects":0,"pending_mirror_up":0,"store_bytes":0}

Build hello and copy its closure into a scratch store, ./client, so signing it leaves your own store untouched:

Terminal window
p=$(nix build nixpkgs#hello --no-link --print-out-paths)
nix copy --to ./client "$p"

Sign the whole closure with your key:

Terminal window
nix store sign --store ./client --key-file secret-key --recursive "$p"

Tell Nix the write token through a netrc file (any login; the password is the token), then push:

Terminal window
echo 'machine 127.0.0.1 login nix password demo-token' > netrc
nix copy --store ./client --option netrc-file "$PWD/netrc" --to 'http://127.0.0.1:5000?compression=zstd' "$p"

The box now holds hello, its dependencies, and their NARs:

Terminal window
curl -s http://127.0.0.1:5000/status
{"flakes":{},"objects":3,"pending_mirror_up":0,"store_bytes":854474}

Counts and sizes depend on your platform’s hello closure.

Pull the path into a second scratch store, trusting only your key:

Terminal window
nix copy --from http://127.0.0.1:5000 --to ./other \
--option trusted-public-keys "$(cat public-key)" "$p"
./other"$p"/bin/hello
Hello, world!

Try the same pull trusting a different key, and Nix refuses it:

Terminal window
nix copy --from http://127.0.0.1:5000 --to ./other2 \
--option trusted-public-keys 'wrong-1:3SEmxzPlTj0luByKrJ9hB5lOmfpOXRvGk1pPNm2/XV0=' "$p"
error: cannot add path '/nix/store/…' because it lacks a signature by a trusted key

Stop the box with Ctrl-C and delete kasha-tutorial when you are done.