From c0ba8c526d2dba4863ee9ed1c5d4c47cae40f0e4 Mon Sep 17 00:00:00 2001
From: Cole Mickens <cole.mickens@gmail.com>
Date: Wed, 28 Apr 2021 11:39:58 -0700
Subject: [PATCH] gpg: can configure scdaemon.conf (#1960)

---
 modules/programs/gpg.nix | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/modules/programs/gpg.nix b/modules/programs/gpg.nix
index f81002c87..516860244 100644
--- a/modules/programs/gpg.nix
+++ b/modules/programs/gpg.nix
@@ -15,6 +15,11 @@ let
     listsAsDuplicateKeys = true;
   } cfg.settings;
 
+  scdaemonCfgText = generators.toKeyValue {
+    inherit mkKeyValue;
+    listsAsDuplicateKeys = true;
+  } cfg.scdaemonSettings;
+
   primitiveType = types.oneOf [ types.str types.bool ];
 in
 {
@@ -44,6 +49,20 @@ in
       '';
     };
 
+    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"/>.
+      '';
+    };
+
     homedir = mkOption {
       type = types.path;
       example = literalExample "\"\${config.xdg.dataHome}/gnupg\"";
@@ -75,11 +94,17 @@ in
       use-agent = mkDefault true;
     };
 
+    programs.gpg.scdaemonSettings = {
+      # no defaults for scdaemon
+    };
+
     home.packages = [ cfg.package ];
     home.sessionVariables = {
       GNUPGHOME = cfg.homedir;
     };
 
     home.file."${cfg.homedir}/gpg.conf".text = cfgText;
+
+    home.file."${cfg.homedir}/scdaemon.conf".text = scdaemonCfgText;
   };
 }