about summary refs log tree commit diff stats
path: root/modules/home.legacy/conf/mail/default.nix
blob: 5e35c00203a5bc7a3799f8d821e9f15bc7dedb24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  config,
  pkgs,
  lib,
  ...
}: let
  benedikt = import ./accounts/benedikt.nix {inherit pkgs;};
  soispha = import ./accounts/soispha.nix {inherit pkgs;};

  accounts = {inherit soispha benedikt;};

  mkHelper = {
    userName,
    passwordCommand,
    ...
  }:
    builtins.toString (pkgs.writeShellScript "git-credential-keepassxc-libsecret"
      # bash
      ''
        [ "$1" = "get" ] || {
          exit 1
        }
        if cat | grep "username=${userName}" -q; then
          ${passwordCommand}
        else
          # Not our business.
          exit 1
        fi
      '');
  accountCredentials =
    # TODO: This will result in only one of them being defined, as we duplicate the
    # attribute key<2025-02-03>
    lib.mapAttrs' (_: value: {
      name = "credential";
      value = {
        "smtp://${value.smtp.host}:${builtins.toString value.smtp.port}" = mkHelper value;
      };
    })
    accounts;
in {
  accounts.email = {
    maildirBasePath = "${config.xdg.dataHome}/maildir";
    inherit accounts;
  };

  programs.git.extraConfig = accountCredentials;
}