nixos/modules/system/sops.nix

31 lines
1.2 KiB
Nix
Raw Normal View History

2023-09-02 22:11:08 +08:00
inputs:
{
options.nixos.system.sops = let inherit (inputs.lib) mkOption types; in
{
2023-11-19 17:29:15 +08:00
enable = mkOption { type = types.bool; default = true; };
keyPathPrefix = mkOption { type = types.str; default = "/nix/persistent"; };
2023-09-02 22:11:08 +08:00
};
2024-09-14 20:44:45 +08:00
config = let inherit (inputs.config.nixos.system) sops; in inputs.lib.mkIf sops.enable
{
sops =
2023-09-02 22:11:08 +08:00
{
2024-09-14 20:44:45 +08:00
defaultSopsFile =
let deviceDir =
if (inputs.config.nixos.system.cluster == null) then
"${inputs.topInputs.self}/devices/${inputs.config.nixos.system.networking.hostname}"
else
"${inputs.topInputs.self}/devices/${inputs.config.nixos.system.cluster.clusterName}"
+ "/${inputs.config.nixos.system.cluster.nodeName}";
in inputs.lib.mkMerge
[
(inputs.lib.mkIf (builtins.pathExists "${deviceDir}/secrets.yaml") "${deviceDir}/secrets.yaml")
(inputs.lib.mkIf (builtins.pathExists "${deviceDir}/secrets/default.yaml")
"${deviceDir}/secrets/default.yaml")
];
# sops start before impermanence, so we need to use the absolute path
age.sshKeyPaths = [ "${sops.keyPathPrefix}/etc/ssh/ssh_host_ed25519_key" ];
gnupg.sshKeyPaths = [ "${sops.keyPathPrefix}/etc/ssh/ssh_host_rsa_key" ];
2023-09-02 22:11:08 +08:00
};
2024-09-14 20:44:45 +08:00
};
2023-09-02 22:11:08 +08:00
}