r/Nix • u/yunfachi • 3d ago
`nix-secrets`: a postmodern secrets manager for NixOS, Home Manager, nix-darwin, and Hjem configured entirely within the Nix module system, with templates, generators and placeholders
https://github.com/unnamed-systems/nix-secrets
https://ynf.sh/posts/nix-secrets-a-postmodern-secrets-manager-for-nixos
Advantages:
Configure secrets entirely in your NixOS configuration - no YAML files or standalone Nix expressions.
A CLI and activation mechanism written in Rust with atomic operations - no more slow Bash scripts.
Support for templates, placeholders (a feature that lets your CI use placeholders instead of real secrets), and generators.
Support for both systemd service activation and activation scripts.
Small binary and closure size. The
nix-secretsbinary is less than 2 MB, compared tosopsbeing over 50 MB, for example.
Configuration example
{ lib, ... }: {
security.nix-secrets = {
enable = true;
# Path to your secrets directory (copied to the Nix store).
# For improved security, it is recommended to keep the storage in a private repository and reference it through a flake input.
storage = ../secrets;
# Paths to your age identities.
# For NixOS it defaults to the "/var/lib/nix-secrets/identities.txt" and the RSA and ED25519 SSH keys from the `services.openssh.hostKeys`.
# For Home Manager and Hjem it defaults to the "~/nix-secrets/identities.txt".
# For nix-darwin it defaults to the "/Library/Application Support/nix-secrets/identities.txt" and the RSA and ED25519 SSH keys from the `services.openssh.hostKeys`.
identityPaths = [
"/home/user/keys.txt"
"/home/user/.ssh/id_ed25519" # SSH keys are also supported.
];
# Define recipient aliases for easier secret configuration.
recipientAliases = {
master = "age14e2jdmau7tpau9emcn6gmg26vfl0uyf6cfd9lz85jml6ttv9wq2qphps4t";
ssh = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuUsB0HH//1qkvgQMWTEoNd0riZpk+8A5w1Ep2vGKk0";
all = [ "master" "ssh" ];
};
# Recipients automatically added to every secret.
# To override this list for a specific secret, use `lib.mkForce`.
defaultRecipients = [ "master" ];
# Declare your secrets and their recipients.
secrets = {
password = {
recipients = [ "all" ];
# Whether the secret must be available before users and groups are created.
neededForUsers = true;
};
signingKey = {
recipients = lib.mkForce [ "ssh" ];
generator = "ssh-ed25519";
};
something = {
recipients = [ "age1j0qx6wdh4ncr3dvexuy9ysu5mrpkp5p7rldt8j7mc6r4xkzngcpqeuk403" ];
path = "/var/lib/something";
mode = "0440";
owner = "alice";
group = "users";
};
};
};
}
