This guide explains the architecture and design principles behind the vars system.
The vars system provides a declarative, reproducible way to manage generated files (especially secrets) in NixOS configurations.
Unlike imperative secret management, vars are declared in your NixOS configuration and generated deterministically. This ensures reproducibility across deployments.
Generators can depend on outputs from other generators, enabling complex workflows:
# Dependencies create a directed acyclic graph (DAG)
A → B → C
↓
D This allows building sophisticated systems like certificate authorities where intermediate certificates depend on root certificates.
The vars system distinguishes between:
.path, deployed to /run/secrets/.value, stored in nix storeThis prevents accidental exposure of secrets in the nix store.
The vars system uses pluggable storage backends:
Each backend handles encryption/decryption transparently, allowing the same generator definitions to work across different security models.
clan vars generate creates vars before deployment--regenerate flagneededFor OptionControl when vars are available during system activation:
files."early-secret" = {
secret = true;
neededFor = "users"; # Available early in activation
}; The share option enables cross-machine secret sharing:
This is useful for:
Complex systems can be built by composing simple generators:
root-ca → intermediate-ca → service-cert
↓
ocsp-responder Each generator focuses on one task, making the system modular and testable.
Compared to manual secret management, vars provides: