2019-05-24 09:01:10 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.gpg;
|
|
|
|
|
2021-02-21 06:37:46 +01:00
|
|
|
mkKeyValue = key: value:
|
|
|
|
if isString value
|
|
|
|
then "${key} ${value}"
|
|
|
|
else optionalString value key;
|
2019-05-24 09:01:10 +02:00
|
|
|
|
2021-02-21 06:37:46 +01:00
|
|
|
cfgText = generators.toKeyValue {
|
|
|
|
inherit mkKeyValue;
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
} cfg.settings;
|
|
|
|
|
2021-04-28 20:39:58 +02:00
|
|
|
scdaemonCfgText = generators.toKeyValue {
|
|
|
|
inherit mkKeyValue;
|
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
} cfg.scdaemonSettings;
|
|
|
|
|
2021-02-21 06:37:46 +01:00
|
|
|
primitiveType = types.oneOf [ types.str types.bool ];
|
|
|
|
in
|
|
|
|
{
|
2019-05-24 09:01:10 +02:00
|
|
|
options.programs.gpg = {
|
|
|
|
enable = mkEnableOption "GnuPG";
|
|
|
|
|
2021-04-27 22:40:05 +02:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.gnupg;
|
|
|
|
defaultText = literalExample "pkgs.gnupg";
|
|
|
|
example = literalExample "pkgs.gnupg23";
|
|
|
|
description = "The Gnupg package to use (also used the gpg-agent service).";
|
|
|
|
};
|
|
|
|
|
2019-05-24 09:01:10 +02:00
|
|
|
settings = mkOption {
|
2021-02-21 06:37:46 +01:00
|
|
|
type = types.attrsOf (types.either primitiveType (types.listOf types.str));
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
no-comments = false;
|
|
|
|
s2k-cipher-algo = "AES128";
|
|
|
|
}
|
|
|
|
'';
|
2019-05-24 09:01:10 +02:00
|
|
|
description = ''
|
|
|
|
GnuPG configuration options. Available options are described
|
|
|
|
in the gpg manpage:
|
|
|
|
<link xlink:href="https://gnupg.org/documentation/manpage.html"/>.
|
2021-05-19 06:58:38 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Note that lists are converted to duplicate keys.
|
2019-05-24 09:01:10 +02:00
|
|
|
'';
|
|
|
|
};
|
2019-10-25 17:12:40 +02:00
|
|
|
|
2021-04-28 20:39:58 +02:00
|
|
|
scdaemonSettings = mkOption {
|
|
|
|
type = types.attrsOf (types.either primitiveType (types.listOf types.str));
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
disable-ccid = true;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
SCdaemon configuration options. Available options are described
|
|
|
|
in the gpg scdaemon manpage:
|
|
|
|
<link xlink:href="https://www.gnupg.org/documentation/manuals/gnupg/Scdaemon-Options.html"/>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-10-25 17:12:40 +02:00
|
|
|
homedir = mkOption {
|
|
|
|
type = types.path;
|
2021-04-15 08:53:13 +02:00
|
|
|
example = literalExample "\"\${config.xdg.dataHome}/gnupg\"";
|
2019-10-25 17:12:40 +02:00
|
|
|
default = "${config.home.homeDirectory}/.gnupg";
|
2021-04-15 08:53:13 +02:00
|
|
|
defaultText = literalExample "\"\${config.home.homeDirectory}/.gnupg\"";
|
2019-10-25 17:12:40 +02:00
|
|
|
description = "Directory to store keychains and configuration.";
|
|
|
|
};
|
2019-05-24 09:01:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
programs.gpg.settings = {
|
|
|
|
personal-cipher-preferences = mkDefault "AES256 AES192 AES";
|
|
|
|
personal-digest-preferences = mkDefault "SHA512 SHA384 SHA256";
|
|
|
|
personal-compress-preferences = mkDefault "ZLIB BZIP2 ZIP Uncompressed";
|
|
|
|
default-preference-list = mkDefault "SHA512 SHA384 SHA256 AES256 AES192 AES ZLIB BZIP2 ZIP Uncompressed";
|
|
|
|
cert-digest-algo = mkDefault "SHA512";
|
|
|
|
s2k-digest-algo = mkDefault "SHA512";
|
|
|
|
s2k-cipher-algo = mkDefault "AES256";
|
|
|
|
charset = mkDefault "utf-8";
|
|
|
|
fixed-list-mode = mkDefault true;
|
|
|
|
no-comments = mkDefault true;
|
|
|
|
no-emit-version = mkDefault true;
|
|
|
|
keyid-format = mkDefault "0xlong";
|
|
|
|
list-options = mkDefault "show-uid-validity";
|
|
|
|
verify-options = mkDefault "show-uid-validity";
|
|
|
|
with-fingerprint = mkDefault true;
|
|
|
|
require-cross-certification = mkDefault true;
|
|
|
|
no-symkey-cache = mkDefault true;
|
|
|
|
use-agent = mkDefault true;
|
|
|
|
};
|
|
|
|
|
2021-04-28 20:39:58 +02:00
|
|
|
programs.gpg.scdaemonSettings = {
|
|
|
|
# no defaults for scdaemon
|
|
|
|
};
|
|
|
|
|
2021-04-27 22:40:05 +02:00
|
|
|
home.packages = [ cfg.package ];
|
2019-10-25 17:12:40 +02:00
|
|
|
home.sessionVariables = {
|
|
|
|
GNUPGHOME = cfg.homedir;
|
|
|
|
};
|
2019-05-24 09:01:10 +02:00
|
|
|
|
2019-10-25 17:12:40 +02:00
|
|
|
home.file."${cfg.homedir}/gpg.conf".text = cfgText;
|
2021-04-28 20:39:58 +02:00
|
|
|
|
|
|
|
home.file."${cfg.homedir}/scdaemon.conf".text = scdaemonCfgText;
|
2019-05-24 09:01:10 +02:00
|
|
|
};
|
|
|
|
}
|