# agenix. The module itself is part of `core`, so `config.age.secrets` always # exists (users.nix, install-facts.nix and the home-manager ssh aspect read # it). The `secrets` aspect decrypts the owner's secrets with the host key. # # Every secret is optional: it is declared only when its .age file exists in # meta.secretsDir, so a fresh clone still evaluates. # -password.age hashed login password (mkpasswd -m yescrypt) # ssh-.age private SSH key of the owner (meta.owner.sshKeys); # home-manager links it to ~/.ssh/ (security/ssh.nix) # Service secrets are declared next to their service (dev/gitea-runner.nix, # network/proxy-suite.nix) with the same pattern. { config, inputs, lib, ... }: let inherit (config.meta) owner secretsDir; secretFile = name: secretsDir + "/${name}.age"; exists = name: builtins.pathExists (secretFile name); passwordSecrets = lib.optionalAttrs (exists "${owner.name}-password") { "${owner.name}-password" = { file = secretFile "${owner.name}-password"; mode = "0400"; }; }; sshSecrets = lib.listToAttrs ( map ( key: lib.nameValuePair "ssh-${key}" { file = secretFile "ssh-${key}"; owner = owner.name; mode = "0400"; } ) (lib.filter (key: exists "ssh-${key}") owner.sshKeys) ); in { flake.modules.nixos.core.imports = [ inputs.agenix.nixosModules.default ]; flake.modules.nixos.secrets = { pkgs, ... }: { # The host key is generated on the install USB (`create-keys`) and copied # to the target, so secrets can be decrypted on the very first boot. age.identityPaths = [ "/etc/ssh/ssh_host_ed25519_key" ]; age.secrets = passwordSecrets // sshSecrets; environment.systemPackages = [ inputs.agenix.packages.${pkgs.stdenv.hostPlatform.system}.default pkgs.age ]; }; }