aboutsummaryrefslogtreecommitdiffstats

enstate and other ways of handling secrets on NixOS

How enstate compares to sops-nix, agenix and the tools around it (ragenix, agenix-rekey), vaultix, nix-secrets, Clan's vars, nixos-artifacts, and wire's (and Colmena's) deployment keys. Written 2026-12-01: for clan-core, nixos-artifacts, nix-secrets and wire from a reading of their sources and documentation that day, for the others from what was known of them then; where a detail isn't certain, it says so. The problems enstate starts from are in design.md, section 1.

The others

Most of them share one model: secrets are encrypted into the repository, become part of the system closure (encrypted, in the Nix store), and are decrypted on the host at activation, with the host's key, usually its ssh host key turned into an age identity.

  • sops-nix: sops files (YAML, JSON, dotenv, binary), encrypted with age, PGP or a cloud KMS, decrypted at activation into /run/secrets (in memory, a generation per switch, behind a symbolic link). Also templates (configuration files with secrets filled in), restartUnits/reloadUnits, and neededForUsers for passwords needed before users exist.
  • agenix: one .age file per secret, its recipients named in secrets.nix, decrypted at activation into /run/agenix. Encrypting again for a new key is by hand (agenix -r).
  • ragenix: agenix in Rust, with the same interface, and checks of secrets.nix.
  • agenix-rekey: one master identity (e.g. on a YubiKey) encrypts; the copies for each host are encrypted again from the hosts' public keys, automatically. Generators make secrets that don't exist yet.
  • vaultix: in the spirit of agenix-rekey, in Rust, as a flake-parts module: encrypted again for each host, decrypted at activation, templates. How it keeps the copies for each host isn't certain here.
  • nix-secrets (unnamed-systems, in Rust; read on 2026-12-01, at its commit of 2026-11-28): age-encrypted secrets declared entirely in the Nix module system (security.nix-secrets.secrets.NAME: recipients, by aliases, path, mode, owner, group, neededForUsers), for NixOS, Home Manager, nix-darwin and Hjem. A storage directory of encrypted files is copied into the store, and decrypted at activation, by a program of its own, into a ramfs (memory that isn't swapped), restarting or reloading units (try-restart, try-reload-or-restart). It has templates (placeholders, hashes of a secret's name, replaced at activation), generators (built-in, like uuid or ssh-ed25519, or a program; also deriving a secret from others), and a CLI to edit, regenerate and rekey. Its encrypted files hold no public keys. The name also stands for a pattern: a private Git repository of (usually sops-)encrypted secrets, used as a flake input.
  • Clan's vars (formerly facts), in clan-core: generators declared in the configuration, scripts with optional prompts that may depend on each other, make files, each secret or public, on the operator's machine (clan vars generate, which runs those whose output is missing, or outdated by a hash of the generator's definition). Public files go into the repository in plain text and are read into the configuration as values; secret ones go in encrypted with sops for each machine, or into a password-store. With sops they get to the machine as with sops-nix; with the password-store, clan machines update uploads them over ssh at deploy, outside the store. neededFor says when a file is needed (partitioning, users, activation, services), and a value can be shared by machines. The details of the backends aren't certain here.
  • nixos-artifacts (by mrVanDalo; experimental, "in the design phase" by its own account; read on 2026-12-01, at its commit of 2026-05-10): one way of declaring secrets across secret tools, inspired by Clan's vars, agenix-rekey and NixOS PR 370444. An artifact is declared in the NixOS configuration (artifacts.store.NAME): its files, each with path, owner, group, the prompts it asks for, and a generator. A TUI runs, for each artifact, the backend's check (does it exist?), the generator in a bubblewrap sandbox if not (its files in $out), and the backend's serialize; the backend's NixOS module puts the files in place at activation. Backends are chosen per artifact: agenix is the one built (sops-nix and Colmena are planned), so secrets travel as agenix's do, encrypted in the closure. Artifacts can be shared by machines (shared = true); dependencies between artifacts and public artifacts are planned.
  • wire (forallsys, a deployment tool in Colmena's style, in Rust; read on 2026-12-01, at its commit of 2026-11-27), and Colmena's own keys: a node declares deployment.keys.NAME, whose source is a text, a path (then in the store), or a command run on the deploying machine (gpg --decrypt, sops, age); a key agent of wire's (a Rust program, copied by nix copy) receives it on the node, before or after activation (uploadAt), into destDir, /run/keys by default (in memory: gone at a reboot until the next deployment), with user, group and permissions. Each key has a path, and a systemd service that services can require. wire apply keys pushes only the keys, without deploying. wire is unopinionated about encryption: it only moves keys.

Compared

sops-nix, agenix and the like Clan's vars enstate
Where secrets travel in the system closure, encrypted sops: in the closure; password-store: uploaded at deploy outside the closure: submissions, over ssh
In the Nix store yes, encrypted sops: yes, encrypted; password-store: no never
Rolling back the generation rolls back the secrets too sops: with the generation; uploaded: what was uploaded last never; migrations between schemas (design.md, section 6)
Rotating encrypt again, rebuild, deploy generate again, deploy a submission, no deploy
Public data about other hosts out of scope read into the configuration: a new peer means deploying state of its own (the fleet channel)
Source of truth the encrypted files in the repository the generators, and their results in the repository existing stores (password-store, a command), read by --pack
What a host declares names of secrets, maybe a format generators and their files a schema: slots, types (media types), validators, required or optional
Before anything changes nothing checked: a missing secret shows as a failed unit nothing checked on the machine a plan, refusals with reasons, a check before a switch
Formats for programs templates (sops-nix, vaultix) the generator writes the final files views: from templates ($(CHANNEL/SLOT)), or made by renderers, in a sandbox
Restarts restartUnits and the like (through the services) reactions, or the configuration's own
Owner and mode of a secret's file settable (owner, group, mode) as the backend has it root's (0600), on purpose: services get views as systemd credentials (LoadCredential=), a file their own user can read, at $CREDENTIALS_DIRECTORY/NAME
At rest on the host encrypted in the store, but its key, the ssh host key, is a plain file on the same disk; plain in memory (/run) as the backend has it plain in /var/lib/enstate (root's, 0700), protected by full-disk encryption; or sealed to the TPM (design.md, 8.3)
Offline, images, CI the secret is in the closure sops: the secret is in the closure state never travels through Nix's paths; an image may be preseeded with entries sealed to its host's TPM (design.md, 8.3)
Several people many recipients per secret as the backend has it whoever can run --pack against the stores
Early state (initrd, disk keys, passwords before users) in part (neededForUsers) first-class (neededFor) later; not designed out
Outdated values not a concept detected by a hash of the generator not a concept: the provider decides when to submit
Bound to NixOS modules, their tools Clan's CLI, its layout of a repository a program and file formats; NixOS by a module

What enstate does differently, on purpose

  • Secrets don't roll back with the generation, and changing one needs no rebuild: the problems design.md, section 1 starts from, which the others share.
  • Nothing secret goes into the store, not even encrypted: with the others, every builder and cache that sees a closure holds the ciphertext, and a host key that leaks opens every secret ever built for that host.
  • What a host accepts is checked before anything changes, and refused with reasons; with the others a missing or wrong secret shows as a failing service.
  • The existing stores stay the source, without a second, encrypted copy in the repository to keep in step.
  • Public data about other hosts is state, not configuration (Clan evaluates it into the system, so a new peer means deploying).

What enstate could learn

  1. Encryption for the way, and sealing for the disk, apart. The others encrypt secrets so that they can be in the store, which is readable and copied around, and decrypt them with the host's ssh key, a plain file on the same disk: against whoever has the disk, that protects nothing (a key protects only where it isn't). enstate doesn't use the store, so it doesn't need that; what it can use is encryption to the host's key for submissions that take other ways than ssh (design.md, 8.2), and sealing to the host's TPM for entries at rest (design.md, 8.3), where the key really isn't on the disk. design.md, 8.1 says what protects against what.
  2. Images preseeded with state, which the others get from the closure: for enstate, with entries sealed to the TPM of the host the image is for; never encrypted to a host key that is in the same image.
  3. Templates (sops-nix, vaultix): a file with values filled in, without writing a program. enstate has them now, as views with a template instead of a renderer (design.md, 5.3).
  4. When state is needed (Clan's neededFor, sops-nix's neededForUsers): a phase for each slot (partitioning, users, activation, services), the clearest model of early state, which the design keeps room for.
  5. Secrets in memory that isn't swapped. sops-nix, agenix and nix-secrets decrypt into a ramfs, which, unlike tmpfs, is never written to swap. enstate's views are below /run/enstate, a tmpfs, so a secret view can reach the swap, on disk (harmless with encrypted swap, or none). Secret views could go on a ramfs of enstate's own.

nixos-artifacts and enstate

They do different halves. nixos-artifacts declares what a host needs and generates it (prompts, a generator, check before, serialize after), and leaves storing and delivering to a backend; enstate leaves generating to the source (design.md, section 9), and reads sources and delivers, with a schema, plans and refusals, outside the store, without rolling back. So they could work together, rather than one replacing the other:

  • nixos-artifacts as what fills the source: its backend serializes into the store enstate reads (a password store, through a tool like secrets HOST insert), and the host's slots read it there, by a location (design.md, section 10). enstate's --pack --dry-run then says which values are still missing, and nixos-artifacts makes them.
  • Or an enstate backend for nixos-artifacts: check and serialize against the store as above, and the NixOS side as enstate's slots (an artifact's files as slots, a file's path as the slot's view) instead of deserializing at activation.

What doesn't carry over: owner and group, which enstate leaves to systemd's credentials (below), and delivering inside the closure, which enstate doesn't do. How well an enstate backend would fit nixos-artifacts' backend interface, which is experimental, isn't certain here.

Deployment keys (wire, Colmena) and enstate

Of the others, deployment keys move secrets most as enstate does: outside the store, from commands on the deploying machine, over ssh, and changed without deploying a system (wire apply keys). What enstate adds:

  • State on the host. Keys in /run/keys are gone at a reboot until the next deployment (or, with a destDir on disk, lie there as plain files nothing keeps track of); enstate keeps a snapshot, and puts the views back in place at boot by itself.
  • What a host accepts, checked: slots with types, validators, plans and refusals, before anything changes; keys are files, taken as they come.
  • Views: records, templates, renderers; keys are one file each.
  • Migrations between generations; keys follow whatever the deployment pushes.
  • Ordering and restarts: a key's service for services to require; enstate orders services that read a view by LoadCredential= after it by itself, and restarts them by reactions.

wire and Colmena stay the deployment tools, delivering enstate's submissions (examples.md); their keys can stay for what isn't in enstate, and move to slots one by one. A key carries one file, so a submission, which is a directory, isn't a key.

What enstate leaves to others, on purpose

Generators (agenix-rekey, Clan, nixos-artifacts, nix-secrets), with dependencies and prompts, and outdated values detected by a hash of the generator's definition (Clan): making a value that doesn't exist yet is the source's business (a password store's generator, a tool like secrets HOST generate-tinc-keys), which knows its layout, its recipients and how each kind of key is made. enstate only reads sources, and declares where once (design.md, section 10, locations); it doesn't generate.

Owner and mode of a secret's file (sops-nix's and agenix's owner, group, mode): handing a secret to a service is systemd's business, by its credentials (LoadCredential=), which give the service, and only it, a file its own user can read, at $CREDENTIALS_DIRECTORY/NAME, DynamicUser= included. enstate's views stay root's, and enstate configures no service: separation of concerns. A service started some other way than by systemd needs a unit of its own for that.

The others have nothing like enstate's schema, plans, refusals, migrations, or public state, so on that side there is nothing to take.