gpg: cleanup

This commit is contained in:
北雁 Cryolitia 2024-05-09 22:08:34 +08:00
parent 5790fc2285
commit b07ca35531
No known key found for this signature in database
GPG key ID: 3E5D1772FC8A8EDD

View file

@ -8,20 +8,10 @@ let
mkKeyValue = key: value: mkKeyValue = key: value:
if isString value then "${key} ${value}" else optionalString value key; if isString value then "${key} ${value}" else optionalString value key;
cfgText = generators.toKeyValue { generateCfgText = generators.toKeyValue {
inherit mkKeyValue; inherit mkKeyValue;
listsAsDuplicateKeys = true; listsAsDuplicateKeys = true;
} cfg.settings; };
scdaemonCfgText = generators.toKeyValue {
inherit mkKeyValue;
listsAsDuplicateKeys = true;
} cfg.scdaemonSettings;
dirmngrCfgText = generators.toKeyValue {
inherit mkKeyValue;
listsAsDuplicateKeys = true;
} cfg.dirmngrSettings;
primitiveType = types.oneOf [ types.str types.bool ]; primitiveType = types.oneOf [ types.str types.bool ];
@ -160,6 +150,7 @@ in {
settings = mkOption { settings = mkOption {
type = type =
types.attrsOf (types.either primitiveType (types.listOf types.str)); types.attrsOf (types.either primitiveType (types.listOf types.str));
default = { };
example = literalExpression '' example = literalExpression ''
{ {
no-comments = false; no-comments = false;
@ -180,6 +171,7 @@ in {
scdaemonSettings = mkOption { scdaemonSettings = mkOption {
type = type =
types.attrsOf (types.either primitiveType (types.listOf types.str)); types.attrsOf (types.either primitiveType (types.listOf types.str));
default = { };
example = literalExpression '' example = literalExpression ''
{ {
disable-ccid = true; disable-ccid = true;
@ -197,6 +189,7 @@ in {
dirmngrSettings = mkOption { dirmngrSettings = mkOption {
type = type =
types.attrsOf (types.either primitiveType (types.listOf types.str)); types.attrsOf (types.either primitiveType (types.listOf types.str));
default = { };
example = literalExpression '' example = literalExpression ''
{ {
keyserver = "keyserver.ubuntu.com"; keyserver = "keyserver.ubuntu.com";
@ -265,31 +258,21 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
# To prevent error: The option `programs.gpg.settings' is used but not defined.
programs.gpg.settings = {
# no defaults for gpg
};
programs.gpg.scdaemonSettings = {
# no defaults for scdaemon
};
programs.gpg.dirmngrSettings = {
# no defaults for dirmngr
};
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.sessionVariables = { GNUPGHOME = cfg.homedir; }; home.sessionVariables = { GNUPGHOME = cfg.homedir; };
home.file."${cfg.homedir}/gpg.conf".text = cfgText; home.file = {
"${cfg.homedir}/gpg.conf".text = generateCfgText cfg.settings;
home.file."${cfg.homedir}/scdaemon.conf".text = scdaemonCfgText; "${cfg.homedir}/scdaemon.conf".text =
generateCfgText cfg.scdaemonSettings;
home.file."${cfg.homedir}/dirmngr.conf".text = dirmngrCfgText; "${cfg.homedir}/dirmngr.conf".text = generateCfgText cfg.dirmngrSettings;
# Link keyring if keys are not mutable # Link keyring if keys are not mutable
home.file."${cfg.homedir}/pubring.kbx" = "${cfg.homedir}/pubring.kbx" =
mkIf (!cfg.mutableKeys && cfg.publicKeys != [ ]) { mkIf (!cfg.mutableKeys && cfg.publicKeys != [ ]) {
source = "${keyringFiles}/pubring.kbx"; source = "${keyringFiles}/pubring.kbx";
}; };
};
home.activation = { home.activation = {
createGpgHomedir = createGpgHomedir =