No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

85 líneas
2.7KB

  1. {
  2. description = "NixOS Mail server";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
  5. # https://nixos-mailserver.readthedocs.io/en/latest/flakes.html
  6. simple-nixos-mailserver = {
  7. url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-25.11";
  8. inputs.nixpkgs.follows = "nixpkgs";
  9. };
  10. };
  11. outputs = { self, nixpkgs, simple-nixos-mailserver, ... }: {
  12. nixosModules.mail = { config, lib, pkgs, ... }:
  13. let
  14. cfg = config.mail;
  15. ldapOptions = let
  16. inherit (config.services) openldap;
  17. in {
  18. name = "ldap";
  19. security-protocol = "LDAPS";
  20. host = "localhost";
  21. port = "389";
  22. bind-dn = "uid=${openldap.services.mail.uid},ou=services,dc=${openldap.organization},dc=${openldap.extension}";
  23. bind-password = openldap.services.mail.passwordFile;
  24. user-search-base = "ou=people,dc=${openldap.organization},dc=${openldap.extension}";
  25. user-filter = "(&(objectclass=*)(|(uniqueIdentifier=%[1]s)(mail=%[1]s)))";
  26. #admin-filter = "(isMemberOf=cn=mail-admins,ou=groups,${ldap.suffix})";
  27. username-attribute = "uniqueIdentifier";
  28. firstname-attribute = "givenName";
  29. surname-attribute = "sn";
  30. email-attribute = "mail";
  31. };
  32. in
  33. {
  34. options.mail = {
  35. enable = lib.mkOption {type = lib.types.bool;};
  36. domain = lib.mkOption {type = lib.types.str;};
  37. fqdn = lib.mkOption {type = lib.types.str;};
  38. };
  39. config = lib.mkIf cfg.enable {
  40. mailserver = {
  41. enable = true;
  42. stateVersion = 4;
  43. fqdn = cfg.fqdn;
  44. domains = [ cfg.domain ];
  45. # Reference the existing ACME configuration created by nginx
  46. x509.useACMEHost = cfg.fqdn;
  47. # LDAP
  48. # https://nixos-mailserver.readthedocs.io/en/latest/ldap.html
  49. ldap = {
  50. enable = true;
  51. uris = [
  52. "ldaps://localhost:389"
  53. ];
  54. bind = {
  55. dn = ldapOptions.bind-dn;
  56. passwordFile = ldapOptions.bind-password;
  57. };
  58. base = ldapOptions.user-search-base;
  59. scope = "one";
  60. };
  61. };
  62. # nginx virtual host
  63. services.nginx.virtualHosts.${cfg.hostName} = {
  64. enableACME = true;
  65. acmeRoot = null;
  66. addSSL = true;
  67. # directs traffic to the appropriate port
  68. locations."/" = {
  69. proxyPass = "http://localhost:${cfg.port}";
  70. proxyWebsockets = true;
  71. };
  72. };
  73. };
  74. };
  75. };
  76. }