diff --git a/modules/programs/aerc/accounts.nix b/modules/programs/aerc/accounts.nix index 050352ee9..466c2fbc5 100644 --- a/modules/programs/aerc/accounts.nix +++ b/modules/programs/aerc/accounts.nix @@ -3,6 +3,8 @@ lib, confSections, confSection, + writeText, + writeShellScript, ... }: let @@ -288,11 +290,40 @@ in pgp-opportunistic-encrypt = account.gpg.encryptByDefault; }; + signatureCfg = + account: + # TODO: aerc does not support attaching signatures yet. + # Until someone needs it, we will just ignore it for now. + if account.signature.showSignature == "append" then + if account.signature.command != null then + { + signature-cmd = writeShellScript "aerc-signature.sh" ( + lib.concatStringsSep "\n" [ + ''printf '%s\n' "${account.signature.delimiter}"'' + account.signature.command + ] + ); + } + else + { + signature-file = writeText "aerc-signature.txt" ( + lib.concatStringsSep "\n" [ + account.signature.delimiter + account.signature.text + ] + ); + } + else + { }; + in - (basicCfg account) - // (sourceCfg account) - // (outgoingCfg account) - // (gpgCfg account) + builtins.foldl' (acc: f: acc // f account) { } [ + basicCfg + sourceCfg + outgoingCfg + gpgCfg + signatureCfg + ] // account.aerc.extraAccounts; mkAccountConfig = name: account: mapAttrNames (addAccountName name) account.aerc.extraConfig; diff --git a/modules/programs/aerc/default.nix b/modules/programs/aerc/default.nix index 8ee5546a1..804e5113f 100644 --- a/modules/programs/aerc/default.nix +++ b/modules/programs/aerc/default.nix @@ -40,11 +40,11 @@ let accounts = import ./accounts.nix { inherit config - pkgs lib confSection confSections ; + inherit (pkgs) writeText writeShellScript; }; aerc-accounts = attrsets.filterAttrs (_: v: v.aerc.enable) config.accounts.email.accounts; diff --git a/tests/modules/programs/aerc/extraAccounts.expected b/tests/modules/programs/aerc/extraAccounts.expected index 0697d9611..050c92939 100644 --- a/tests/modules/programs/aerc/extraAccounts.expected +++ b/tests/modules/programs/aerc/extraAccounts.expected @@ -91,3 +91,11 @@ from = test outgoing = imap+plain://intentionallyWrong:PaSsWorD@smtp.host.invalid:1337 postpone = dRaFts source = smtp+plain://intentionallyWrong:PaSsWorD@smtp.host.invalid:1337 + +[q_signature_text] +from = Foo Bar +signature-file = /nix/store/00000000000000000000000000000000-aerc-signature.txt + +[r_signature_command] +from = Foo Bar +signature-cmd = /nix/store/00000000000000000000000000000000-aerc-signature.sh diff --git a/tests/modules/programs/aerc/settings.nix b/tests/modules/programs/aerc/settings.nix index 32682be5a..de8d3308c 100644 --- a/tests/modules/programs/aerc/settings.nix +++ b/tests/modules/programs/aerc/settings.nix @@ -10,13 +10,18 @@ "home-files/.config/aerc"; in '' - assertFileContent ${dir}/accounts.conf ${./extraAccounts.expected} - assertFileContent ${dir}/binds.conf ${./extraBinds.expected} - assertFileContent ${dir}/aerc.conf ${./extraConfig.expected} - assertFileContent ${dir}/templates/bar ${./templates.expected} - assertFileContent ${dir}/templates/foo ${./templates.expected} - assertFileContent ${dir}/stylesets/default ${./stylesets.expected} - assertFileContent ${dir}/stylesets/asLines ${./stylesets.expected} + assertFileContent $(normalizeStorePaths ${dir}/accounts.conf) ${./extraAccounts.expected} + assertFileContent $(normalizeStorePaths ${dir}/binds.conf) ${./extraBinds.expected} + assertFileContent $(normalizeStorePaths ${dir}/aerc.conf) ${./extraConfig.expected} + assertFileContent $(normalizeStorePaths ${dir}/templates/bar) ${./templates.expected} + assertFileContent $(normalizeStorePaths ${dir}/templates/foo) ${./templates.expected} + assertFileContent $(normalizeStorePaths ${dir}/stylesets/default) ${./stylesets.expected} + assertFileContent $(normalizeStorePaths ${dir}/stylesets/asLines) ${./stylesets.expected} + assertFileContent $(normalizeStorePaths ${dir}/stylesets/asLines) ${./stylesets.expected} + + assertFileContent $(normalizeStorePaths /nix/store/*-aerc-signature.sh) ${./signature-command.expected} + assertFileContent $(normalizeStorePaths /nix/store/*-aerc-signature.txt) ${./signature-file.expected} + assertFileContent $(normalizeStorePaths /nix/store/*-user-signature.sh) ${./signature-command-script.expected} ''; programs.aerc = { @@ -291,6 +296,26 @@ }; }; }; + q_signature_text = basics // { + signature = { + showSignature = "append"; + delimiter = "~~~"; + text = '' + some signature + goes here + ''; + }; + }; + r_signature_command = basics // { + signature = { + showSignature = "append"; + delimiter = "~~~"; + command = pkgs.writeShellScript "user-signature.sh" '' + echo "some signature" + echo "goes here" + ''; + }; + }; }; }; } diff --git a/tests/modules/programs/aerc/signature-command-script.expected b/tests/modules/programs/aerc/signature-command-script.expected new file mode 100644 index 000000000..177fe54c4 --- /dev/null +++ b/tests/modules/programs/aerc/signature-command-script.expected @@ -0,0 +1,4 @@ +#!/nix/store/00000000000000000000000000000000-bash/bin/bash +echo "some signature" +echo "goes here" + diff --git a/tests/modules/programs/aerc/signature-command.expected b/tests/modules/programs/aerc/signature-command.expected new file mode 100644 index 000000000..f240d3ef5 --- /dev/null +++ b/tests/modules/programs/aerc/signature-command.expected @@ -0,0 +1,3 @@ +#!/nix/store/00000000000000000000000000000000-bash/bin/bash +printf '%s\n' "~~~" +/nix/store/00000000000000000000000000000000-user-signature.sh diff --git a/tests/modules/programs/aerc/signature-file.expected b/tests/modules/programs/aerc/signature-file.expected new file mode 100644 index 000000000..083e2d522 --- /dev/null +++ b/tests/modules/programs/aerc/signature-file.expected @@ -0,0 +1,3 @@ +~~~ +some signature +goes here