/cc-skills-nix:nix-sops-secretsfrom cc-skills-nix
Secrets in NixOS flakes with sops-nix + age (+ age-plugin-yubikey) — .sops.yaml recipients and creation_rules, a centralized sops.secrets declaration module, and runtime consumption from /run/secrets. Apply when adding, editing or rotating an encrypted secret; when adding a recipient (new host key or YubiKey) or a new host that must decrypt; when a service or user can't read a secret (permission denied, file missing, empty env var); when wiring an API key or password into a NixOS service, home-manager tool or wrapper script; when configuring .sops.yaml, sops.defaultSopsFile or the age host key. Do NOT use for agenix or vault-based setups, for git-crypt, or for generic sops usage outside Nix.
Ships in cc-skills-nix. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Model: secrets live encrypted in git (secrets/*.sops.yaml), .sops.yaml says who can decrypt, one NixOS module declares which keys become files, and consumers read /run/secrets/<key> at runtime — never at eval time. Requires inputs.sops-nix (with inputs.nixpkgs.follows = "nixpkgs") and its module in every host (via the flake's shared modules).
Defaults verified against sops-nix's module source: secrets materialize at /run/secrets/<name>, mode 0400, owned by root unless owner is set; the host decrypts with the age key derived from its ed25519 SSH host key (config.services.openssh.hostKeys) unless sops.age.keyFile is set.
keys:
- &framework age18lmn8r9... # host key: ssh-to-age < /etc/ssh/ssh_host_ed25519_key.pub
- &yk-5 age1yubikey1qt3vym... # operator YubiKey: age-plugin-yubikey --list
creation_rules:
- path_regex: secrets/[^/]+\.sops\.ya?ml$
key_groups:
- age:
- *framework
- *yk-5
Two kinds of recipients, both age: host keys (each machine that must decrypt at boot) and operator keys on YubiKey (each human who edits secrets). Anchors keep the recipient list writable once and referenced per rule. After ANY change to keys/creation_rules, run sops updatekeys secrets/*.sops.yaml — editing .sops.yaml alone re-encrypts nothing.
# modules/nixos/sops.nix
{ config, ... }:
let
user = config.users.users.aldo.name; # derive, don't hardcode
in
{
sops.defaultSopsFile = ../../secrets/secrets.sops.yaml;
sops.secrets = {
"ai/pi/groq".owner = user; # nested YAML key "ai: pi: groq:"
# "db/password" = { }; # root-owned 0400 — for system services
};
}
Per-secret options that matter: owner (default root), mode (default "0400"), group (defaults to owner's group), restartUnits / reloadUnits (bounce services on rotation), neededForUsers (materializes earlier at /run/secrets-for-users/<name> for users.users.*.hashedPasswordFile; forces root owner).
NixOS services: reference config.sops.secrets."<key>".path in the service definition (e.g. EnvironmentFile, passwordFile). Never builtins.readFile a secret and never interpolate its contents into Nix — that copies the plaintext into the world-readable store.
Home-manager / user tools (house pattern): don't use a sops API at all — wrap the tool and read the file at invocation time, exporting the variable only if the file is readable:
if [[ -r "/run/secrets/ai/pi/groq" ]]; then
export GROQ_API_KEY="$(</run/secrets/ai/pi/groq)"
fi
Unset is deliberate: tools distinguish "no key configured" from "empty key". The flip side: a key never declared in sops.secrets, or misspelled, degrades silently — the wrapper runs without the variable.
Devshell: sops, age, age-plugin-yubikey, ssh-to-age. Optional .envrc helper to load a dotenv-shaped secrets file into direnv:
use_sops() {
local path=${1:-$PWD/secrets.yaml}
eval "$(sops --decrypt --output-type dotenv "$path" | direnv dotenv bash /dev/stdin)"
watch_file "$path"
}
Step-by-step operations (add/edit secret, add recipient, onboard host, rotate a YubiKey): references/workflows.md. What breaks and how it looks (updatekeys forgotten, owner wrong, eval-time reads, boot ordering, git add): references/failure-modes.md.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub aldoborrero/skills --plugin cc-skills-nix6 skills in this plugin
/nix-blueprintnumtide/blueprint — Nix flake framework that maps a fixed directory structure to flake outputs with zero glue code. Apply when a repo's flake.nix calls `inputs.blueprint { ... }`; when deciding where a package, devshell, host, module, check or template file must live; when a package/devshell/host is missing from `nix flake show` or `nix build` says the attribute doesn't exist; when adding the `prefix` option; when writing packages/<name>/default.nix, devshell.nix or modules/<class>/<name>.nix. Do NOT use for generic Nix flakes without blueprint (hand-written outputs, flake-parts, flake-utils), for nixpkgs contributions, or for NixOS module semantics unrelated to file placement. Prefer nix-project-scaffold for creating a NEW project, nix-treefmt-formatter for formatter.nix internals, and nixos-host-provisioning for adding hosts with disko/facter./nix-oci-imageBuilding and publishing OCI/Docker container images from Nix — dockerTools.buildLayeredImage over a buildEnv (app + cacert), non-root numeric User for Kubernetes runAsNonRoot, version-derived tags, and pushing with skopeo (docker-archive → OCI) to registries like Zot that reject `docker push`. Apply when adding a container image output to a flake; when writing packages/docker/*.nix or dockerTools code; when a Nix-built image fails TLS (missing CA bundle), lacks PATH, or runs as root; when pushing ./result to a private/homelab registry fails; when wiring an image build+push recipe into a justfile or CI. Do NOT use for Dockerfile-based builds, docker-compose, or Kubernetes manifest authoring./nixos-host-provisioningAdding or provisioning a NixOS host in a blueprint-based config flake — hosts/<name>/default.nix escape hatch wiring input modules (disko, sops-nix, nixos-hardware, nixos-facter), declarative partitioning with disko (GPT ESP+root, ext4 or btrfs subvolumes), hardware detection via nixos-facter instead of hardware-configuration.nix, and manual home-manager user wiring. Apply when adding a new machine to a NixOS flake; when writing or editing hosts/<name>/{default.nix,configuration.nix,disko.nix}; when generating or overriding facter.json; when a host needs modules from flake inputs; when home-manager users don't get created on a host. Do NOT use for non-NixOS projects, for nix-darwin-only hosts, or for flakes not using blueprint's hosts/ convention./nix-project-scaffoldHouse-style scaffold for new Nix-flake projects (Go, Python, or other languages) — numtide/blueprint with prefix="nix", direnv .envrc, numtide devshell with in-repo toolchain caches, treefmt formatter, two-file package (default.nix shim + nixpkgs-style package.nix with src=flake), justfile facade, and GitHub Actions CI pinned to flake.lock's nixpkgs. Apply when creating a new project or repository that should use Nix; when adding Nix/flake tooling to an existing Go or Python repo; when asked for a devshell + formatter + CI setup 'like my other repos'; when wiring justfile targets to nix commands; when setting up direnv for a flake. Do NOT use for repos that already follow a different flake convention (flake-parts, devenv, hand-rolled outputs), for NixOS system configuration repos, or for nixpkgs contributions./nix-treefmt-formattertreefmt-nix formatter for Nix flakes — `formatter.nix` via `treefmt-nix.lib.evalModule` (build.wrapper + build.check), lint→format ordering with priorities (deadnix→nixfmt, shellcheck→shfmt, ruff-check→ruff-format), and the format check wired into `nix flake check` via passthru.tests. Apply when writing or editing formatter.nix / treefmt config in a flake; when adding a language formatter (Go, Python, shell, YAML, TOML, Markdown, just); when `nix fmt` misbehaves, formats vendored files, or skips files (excludes, on-unmatched, default excludes); when CI passes `nix flake check` but formatting is actually broken (check never ran); when deadnix deletes wanted lambda args. Do NOT use for non-treefmt formatting setups, editor/IDE format-on-save config, or choosing code style rules of a language.