blob: 32291921f2666f3fc6bde40b26d168b83f8c0697 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
{
pkgs,
config,
lib,
...
}:
let
cfg = config.wilkuu.mjmap;
inherit (lib)
mkEnableOption
mkOption
types
mkIf
;
# TODO: Once the mjmap patch is upstreamed, use this.
#mjmap_wrap = (pkgs.writeScriptBin "mjmap" ''
# #! ${pkgs.bash}/bin/bash
# export MJMAP_CONFIG=${config.sops.secrets."mjmap-creds".path};
# exec ${pkgs.mjmap} "$@"
# '');
# Workaround since the current version does not support setting config path;
mjmap_wrap = (
pkgs.writeScriptBin "mjmap-send" ''
#! ${pkgs.bash}/bin/bash
export XDG_CONFIG_DIR=/etc/;
exec ${pkgs.mjmap}/bin/mjmap "$@"
''
);
sendmail_wrap = pkgs.symlinkJoin {
name = "sendmail-wrapper";
paths = [ mjmap_wrap ];
postBuild = ''
ln -s $out/bin/mjmap-send $out/bin/sendmail
'';
};
in
{
options.wilkuu.mjmap = {
enable = mkEnableOption "mjmap jmap email";
users = mkOption {
type = types.listOf types.str;
description = "users that are allowed to view the credentials file and thus use mjmail";
};
};
config = mkIf cfg.enable {
users.groups.mjmap = mkIf (cfg.users != [ ]) { };
users.users = lib.genAttrs cfg.users (_: {
extraGroups = [ "mjmap" ];
packages = [
mjmap_wrap
sendmail_wrap
];
});
sops.secrets."mjmap-creds" = mkIf (cfg.users != [ ]) {
sopsFile = ../secrets/${config.networking.hostName}/mjmap.scfg.bin;
key = "";
format = "binary";
group = "mjmap";
mode = "440";
};
environment.etc."mjmap/config.scfg" = mkIf (cfg.users != [ ]) {
source = config.sops.secrets."mjmap-creds".path;
};
environment.systemPackages = [ pkgs.mjmap ];
};
}
|