From 14f790e67a46c23477ef4045d147b68ef8acdf1e Mon Sep 17 00:00:00 2001 From: blake Date: Sun, 19 Oct 2025 14:06:42 -0500 Subject: [PATCH] update options to support new syntax --- modules/homelab/.default.nix.template.nix | 2 +- modules/homelab/postfix/default.nix | 5 +- modules/homelab/postfix/default.nix.bak | 101 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 modules/homelab/postfix/default.nix.bak diff --git a/modules/homelab/.default.nix.template.nix b/modules/homelab/.default.nix.template.nix index c8002ab..9d2dbf6 100644 --- a/modules/homelab/.default.nix.template.nix +++ b/modules/homelab/.default.nix.template.nix @@ -9,7 +9,7 @@ sec = config.sops.secrets; homelab = config.homelab; in { - options.modules.services.${service} = { + options.homelab.${service} = { enable = lib.mkEnableOption "enables ${service}"; # set port options diff --git a/modules/homelab/postfix/default.nix b/modules/homelab/postfix/default.nix index 66c263b..767017c 100644 --- a/modules/homelab/postfix/default.nix +++ b/modules/homelab/postfix/default.nix @@ -9,7 +9,7 @@ sec = config.sops.secrets; homelab = config.homelab; in { - options.modules.services.${service} = { + options.homelab.${service} = { enable = lib.mkEnableOption "enables ${service}"; # set port options @@ -63,7 +63,8 @@ in { relayHost = "smtp.gmail.com"; relayPort = cfg.port; config = { - smtp_use_tls = "yes"; + #smtp_use_tls = "yes"; + smtp_tls_security_level = "may"; smtp_sasl_auth_enable = "yes"; smtp_sasl_security_options = ""; smtp_sasl_password_maps = "texthash:${config.sops.secrets."postfix_passwd".path}"; diff --git a/modules/homelab/postfix/default.nix.bak b/modules/homelab/postfix/default.nix.bak new file mode 100644 index 0000000..767017c --- /dev/null +++ b/modules/homelab/postfix/default.nix.bak @@ -0,0 +1,101 @@ +{ + pkgs, + config, + lib, + ... +}: let + service = "postfix"; + cfg = config.homelab.${service}; + sec = config.sops.secrets; + homelab = config.homelab; +in { + options.homelab.${service} = { + enable = lib.mkEnableOption "enables ${service}"; + + # set port options + port = lib.mkOption { + type = lib.types.int; + default = 587; + description = "set port for ${service} (default: ${toString cfg.port}"; + }; + url = lib.mkOption { + type = lib.types.str; + default = "${service}.${homelab.base_domain}"; + description = "set domain for ${service}"; + }; + data_dir = lib.mkOption { + type = lib.types.str; + default = "/var/lib/${service}"; + description = "set data directory for ${service}"; + }; + ids = lib.mkOption { + type = lib.types.int; + default = cfg.port; + description = "set uid and pid of ${service} user (matches port by default)"; + }; + backup = lib.mkOption { + type = lib.types.bool; + default = true; + description = "enable backups for ${service}"; + }; + }; + + config = lib.mkIf cfg.enable { + # declare ${service} group + # users.groups.${service} = { + # gid = lib.mkForce cfg.ids; + # }; + # + # # declare ${service} user + # users.users.${service} = { + # description = "${service} server user"; + # uid = lib.mkForce cfg.ids; + # isSystemUser = true; + # home = cfg.data_dir; + # createHome = true; + # group = service; + # extraGroups = []; + # }; + + # enable the ${service} service + services.postfix = { + enable = true; + relayHost = "smtp.gmail.com"; + relayPort = cfg.port; + config = { + #smtp_use_tls = "yes"; + smtp_tls_security_level = "may"; + smtp_sasl_auth_enable = "yes"; + smtp_sasl_security_options = ""; + smtp_sasl_password_maps = "texthash:${config.sops.secrets."postfix_passwd".path}"; + # optional: Forward mails to root (e.g. from cron jobs, smartd) + # to me privately and to my work email: + virtual_alias_maps = "inline:{ {root=me@blakedheld.xyz, throwedspam@gmail.com} }"; + }; + }; + + # override umask to make permissions work out + # systemd.services.${service}.serviceConfig = { + # UMask = lib.mkForce "0007"; + # User = service; + # Group = service; + #}; + + # open firewall + networking.firewall.allowedTCPPorts = [ cfg.port ]; + + sops.secrets = { + "${service}_passwd" = { + owner = config.services.postfix.user; + group = config.services.postfix.group; + }; + }; + + # add to backups + homelab.backups.baks = { + ${service} = { + paths = [cfg.data_dir]; + }; + }; + }; +}