sops: generate the config with nix

This commit is contained in:
SebastianStork 2025-07-22 22:18:34 +02:00
parent 021473a99d
commit 5e18975b9b
12 changed files with 85 additions and 74 deletions

View file

@ -7,30 +7,36 @@
}@moduleArgs:
let
cfg = config.custom.sops;
absoluteSecretsPath = "${self}/" + cfg.secretsFile;
in
{
imports = [ inputs.sops-nix.homeManagerModules.sops ];
options.custom.sops = {
enable = lib.mkEnableOption "";
agePublicKey = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "";
};
hostName = lib.mkOption {
type = lib.types.nonEmptyStr;
default = moduleArgs.osConfig.networking.hostName or "";
};
defaultSopsFile = lib.mkOption {
type = lib.types.path;
default = "${self}/users/${config.home.username}/@${cfg.hostName}/secrets.json";
secretsFile = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "users/${config.home.username}/@${cfg.hostName}/secrets.json";
};
secrets = lib.mkOption {
type = lib.types.anything;
default = cfg.defaultSopsFile |> builtins.readFile |> builtins.fromJSON;
default = absoluteSecretsPath |> builtins.readFile |> builtins.fromJSON;
};
};
config = lib.mkIf cfg.enable {
sops = {
age.sshKeyPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
inherit (cfg) defaultSopsFile;
defaultSopsFile = absoluteSecretsPath;
};
};
}