1
0
Fork 0
mirror of https://github.com/Mic92/sops-nix.git synced 2024-12-14 11:57:52 +00:00
sops-nix/modules/home-manager/templates.nix

109 lines
3.5 KiB
Nix
Raw Permalink Normal View History

2024-11-17 11:17:45 +00:00
{
config,
pkgs,
lib,
options,
...
}:
2024-11-17 10:35:16 +00:00
let
inherit (lib)
mkOption
mkDefault
mapAttrs
types
2024-11-17 11:17:45 +00:00
;
hmConfig = config;
2024-11-17 11:17:45 +00:00
in
{
2024-11-17 10:35:16 +00:00
options.sops = {
templates = mkOption {
description = "Templates for secret files";
2024-11-17 11:17:45 +00:00
type = types.attrsOf (
types.submodule (
{ config, ... }:
{
options = {
name = mkOption {
type = types.singleLineStr;
default = config._module.args.name;
description = ''
Name of the file used in /run/secrets/rendered
'';
};
path = mkOption {
description = "Path where the rendered file will be placed";
type = types.singleLineStr;
# Keep this in sync with `RenderedSubdir` in `pkgs/sops-install-secrets/main.go`
default = "${hmConfig.xdg.configHome}/sops-nix/secrets/rendered/${config.name}";
2024-11-17 11:17:45 +00:00
};
content = mkOption {
type = types.lines;
default = "";
description = ''
Content of the file
'';
};
mode = mkOption {
type = types.singleLineStr;
default = "0400";
description = ''
Permissions mode of the rendered secret file in octal.
'';
};
file = mkOption {
type = types.path;
default = pkgs.writeText config.name config.content;
defaultText = lib.literalExpression ''pkgs.writeText config.name config.content'';
example = "./configuration-template.conf";
description = ''
File used as the template. When this value is specified, `sops.templates.<name>.content` is ignored.
'';
};
restartUnits = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "sshd.service" ];
description = ''
Names of units that should be restarted when the rendered template changes.
This works the same way as <xref linkend="opt-systemd.services._name_.restartTriggers" />.
'';
};
reloadUnits = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "sshd.service" ];
description = ''
Names of units that should be reloaded when the rendered template changes.
This works the same way as <xref linkend="opt-systemd.services._name_.reloadTriggers" />.
'';
};
};
}
)
);
2024-11-17 10:35:16 +00:00
default = { };
};
placeholder = mkOption {
2024-11-17 11:17:45 +00:00
type = types.attrsOf (
types.mkOptionType {
name = "coercibleToString";
description = "value that can be coerced to string";
check = lib.strings.isConvertibleWithToString;
merge = lib.mergeEqualOption;
}
);
2024-11-17 10:35:16 +00:00
default = { };
visible = false;
};
};
2024-11-17 11:17:45 +00:00
config = lib.optionalAttrs (options ? sops.secrets) (
lib.mkIf (hmConfig.sops.templates != { }) {
2024-11-17 11:17:45 +00:00
sops.placeholder = mapAttrs (
name: _: mkDefault "<SOPS:${builtins.hashString "sha256" name}:PLACEHOLDER>"
) hmConfig.sops.secrets;
2024-11-17 11:17:45 +00:00
}
);
2024-11-17 10:35:16 +00:00
}