at 24.11-pre 1.6 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.go-autoconfig; 8 format = pkgs.formats.yaml { }; 9 configFile = format.generate "config.yml" cfg.settings; 10 11in { 12 options = { 13 services.go-autoconfig = { 14 15 enable = mkEnableOption "IMAP/SMTP autodiscover feature for mail clients"; 16 17 settings = mkOption { 18 default = { }; 19 description = '' 20 Configuration for go-autoconfig. See 21 <https://github.com/L11R/go-autoconfig/blob/master/config.yml> 22 for more information. 23 ''; 24 type = types.submodule { 25 freeformType = format.type; 26 }; 27 example = literalExpression '' 28 { 29 service_addr = ":1323"; 30 domain = "autoconfig.example.org"; 31 imap = { 32 server = "example.org"; 33 port = 993; 34 }; 35 smtp = { 36 server = "example.org"; 37 port = 465; 38 }; 39 } 40 ''; 41 }; 42 43 }; 44 }; 45 46 config = mkIf cfg.enable { 47 48 systemd = { 49 services.go-autoconfig = { 50 wantedBy = [ "multi-user.target" ]; 51 description = "IMAP/SMTP autodiscover server"; 52 after = [ "network.target" ]; 53 serviceConfig = { 54 ExecStart = "${pkgs.go-autoconfig}/bin/go-autoconfig -config ${configFile}"; 55 Restart = "on-failure"; 56 WorkingDirectory = ''${pkgs.go-autoconfig}/''; 57 DynamicUser = true; 58 }; 59 }; 60 }; 61 62 }; 63 64 meta.maintainers = with lib.maintainers; [ onny ]; 65 66}