2021-01-19 22:30:12 -08:00
|
|
|
# modules/agenix.nix -- encrypt secrets in nix store
|
|
|
|
|
|
|
|
{ options, config, inputs, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with builtins;
|
|
|
|
with lib;
|
|
|
|
with lib.my;
|
|
|
|
let inherit (inputs) agenix;
|
2021-03-03 19:23:50 -08:00
|
|
|
secretsDir = "${toString ../hosts}/${config.networking.hostName}/secrets";
|
2021-01-19 22:30:12 -08:00
|
|
|
secretsFile = "${secretsDir}/secrets.nix";
|
|
|
|
in {
|
|
|
|
imports = [ agenix.nixosModules.age ];
|
|
|
|
environment.systemPackages = [ agenix.defaultPackage.x86_64-linux ];
|
|
|
|
|
|
|
|
age = {
|
|
|
|
secrets =
|
|
|
|
if pathExists secretsFile
|
|
|
|
then mapAttrs' (n: _: nameValuePair (removeSuffix ".age" n) {
|
|
|
|
file = "${secretsDir}/${n}";
|
|
|
|
owner = mkDefault config.user.name;
|
|
|
|
}) (import secretsFile)
|
|
|
|
else {};
|
|
|
|
sshKeyPaths =
|
|
|
|
options.age.sshKeyPaths.default ++ (filter pathExists [
|
|
|
|
"${config.user.home}/.ssh/id_ed25519"
|
|
|
|
"${config.user.home}/.ssh/id_rsa"
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|