Support early build cache hints

This commit is contained in:
Timothy J. Aveni
2026-07-02 11:21:53 -07:00
parent 837dea284c
commit f8c9ef03bf
2 changed files with 57 additions and 1 deletions
+26
View File
@@ -15,6 +15,32 @@ also disables the default shell-oriented `amazon-init` service and enables a
small generic service that treats EC2 user-data as `/etc/nixos/flake.nix`, then
runs `nixos-rebuild switch --flake /etc/nixos`.
## First-Boot Build Cache Hints
The first user-data switch is built by the AMI's existing Nix configuration,
before the target NixOS system has activated its own `nix.settings`. A caller
flake can optionally expose `quixosEarlyBuildNixConfig` to make that first
build use known binary caches without baking any project-specific cache into
the AMI:
```nix
{
quixosEarlyBuildNixConfig = {
hosts = {
"2600:..." = [ "nix-cache.internal.example.org" ];
};
substituters = [ "http://nix-cache.internal.example.org/cache" ];
trustedPublicKeys = [ "nix-cache.internal.example.org-1:..." ];
};
}
```
The AMI runner evaluates this output after writing `/etc/nixos/flake.nix`,
appends the host hints to `/etc/hosts`, and passes the substituters and trusted
public keys through `NIX_CONFIG` only for the first `nixos-rebuild switch`.
The target NixOS configuration should still declare the same cache in
`nix.settings` for all later rebuilds.
## Publish
The normal flow builds on a temporary EC2 instance, so your local machine does