feat: mailserver
This commit is contained in:
parent
0ebf0d7a29
commit
b8a31b6264
28 changed files with 2446 additions and 1350 deletions
|
|
@ -1,9 +1,14 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
inputs,
|
||||
username,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) optionalAttrs;
|
||||
inherit (builtins) toString;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(import ../../modules/nvidia.nix {
|
||||
|
|
@ -18,28 +23,97 @@
|
|||
./services.nix
|
||||
./nginx.nix
|
||||
./step-ca.nix
|
||||
./mail-server.nix
|
||||
../../modules/presets/minimal.nix
|
||||
../../modules/bluetooth.nix
|
||||
../../modules/gc.nix
|
||||
../../modules/certbot.nix
|
||||
../../modules/mail-server
|
||||
(import ../../modules/prometheus.nix {
|
||||
fqdn = "metrics.net.dn";
|
||||
selfMonitor = true;
|
||||
configureNginx = true;
|
||||
scrapes = [
|
||||
(optionalAttrs config.services.pdns-recursor.enable {
|
||||
job_name = "powerdns_recursor";
|
||||
static_configs = [
|
||||
{
|
||||
targets = [ "localhost:${toString config.services.pdns-recursor.api.port}" ];
|
||||
}
|
||||
];
|
||||
})
|
||||
];
|
||||
})
|
||||
(import ../../modules/actual.nix {
|
||||
fqdn = "actual.net.dn";
|
||||
})
|
||||
(import ../../modules/nextcloud.nix {
|
||||
hostname = "nextcloud.net.dn";
|
||||
dataBackupPath = "/mnt/backup_dn";
|
||||
dbBackupPath = "/mnt/backup_dn";
|
||||
})
|
||||
(import ../../modules/vaultwarden.nix {
|
||||
domain = "https://bitwarden.net.dn";
|
||||
domain = "bitwarden.net.dn";
|
||||
})
|
||||
(import ../../modules/openldap.nix { })
|
||||
../../modules/terraria.nix
|
||||
(import ../../modules/grafana.nix {
|
||||
domain = "grafana.net.dn";
|
||||
passFile = config.sops.secrets."grafana/password".path;
|
||||
smtpHost = config.mail-server.domain;
|
||||
smtpDomain = config.mail-server.domain;
|
||||
extraSettings = {
|
||||
"auth.generic_oauth" =
|
||||
let
|
||||
OIDCBaseUrl = "https://keycloak.net.dn/realms/master/protocol/openid-connect";
|
||||
in
|
||||
{
|
||||
enabled = true;
|
||||
allow_sign_up = true;
|
||||
client_id = "grafana";
|
||||
client_secret = ''$__file{${config.sops.secrets."grafana/client_secret".path}}'';
|
||||
scopes = "openid email profile offline_access roles";
|
||||
email_attribute_path = "email";
|
||||
login_attribute_path = "username";
|
||||
name_attribute_path = "full_name";
|
||||
auth_url = "${OIDCBaseUrl}/auth";
|
||||
token_url = "${OIDCBaseUrl}/token";
|
||||
api_url = "${OIDCBaseUrl}/userinfo";
|
||||
role_attribute_path = "contains(roles[*], 'admin') && 'Admin' || contains(roles[*], 'editor') && 'Editor' || 'Viewer'";
|
||||
};
|
||||
};
|
||||
})
|
||||
../../modules/postgresql.nix
|
||||
];
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
ferium
|
||||
openssl
|
||||
];
|
||||
|
||||
mail-server = {
|
||||
enable = true;
|
||||
mailDir = "~/Maildir";
|
||||
caFile = "" + ../../extra/ca.crt;
|
||||
virtualMailDir = "/var/mail/vhosts";
|
||||
domain = "net.dn";
|
||||
rootAlias = "${settings.personal.username}";
|
||||
networks = [
|
||||
"127.0.0.0/8"
|
||||
"10.0.0.0/24"
|
||||
];
|
||||
virtual = ''
|
||||
admin@net.dn ${settings.personal.username}@net.dn
|
||||
postmaster@net.dn ${settings.personal.username}@net.dn
|
||||
'';
|
||||
openFirewall = true;
|
||||
oauth = {
|
||||
passwordFile = config.sops.secrets."oauth/password".path;
|
||||
};
|
||||
ldap = {
|
||||
passwordFile = config.sops.secrets."ldap/password".path;
|
||||
webEnv = config.sops.secrets."ldap/env".path;
|
||||
};
|
||||
rspamd = {
|
||||
trainerSecret = config.sops.secrets."rspamd-trainer".path;
|
||||
};
|
||||
};
|
||||
|
||||
home-manager = {
|
||||
users."${username}" = {
|
||||
imports = [
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
settings,
|
||||
...
|
||||
}:
|
||||
with builtins;
|
||||
let
|
||||
interfaces = config.networking.wireguard.interfaces;
|
||||
allowedIPs = concatLists [
|
||||
(concatLists (map (interface: interfaces.${interface}.ips) (attrNames interfaces)))
|
||||
[
|
||||
"127.0.0.1"
|
||||
]
|
||||
];
|
||||
fqdn = config.networking.fqdn;
|
||||
# fqdn = "dn-server.daccc.info";
|
||||
in
|
||||
{
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
25
|
||||
587
|
||||
];
|
||||
|
||||
services.postfix = {
|
||||
enable = true;
|
||||
hostname = fqdn;
|
||||
origin = fqdn;
|
||||
networks = allowedIPs;
|
||||
destination = [
|
||||
"localhost"
|
||||
"localhost.${fqdn}"
|
||||
fqdn
|
||||
];
|
||||
|
||||
config = {
|
||||
home_mailbox = "Mailbox";
|
||||
};
|
||||
|
||||
postmasterAlias = "root";
|
||||
rootAlias = settings.personal.username;
|
||||
|
||||
config = {
|
||||
alias_maps = [ "ldap:${config.sops.secrets."postfix/openldap".path}" ];
|
||||
};
|
||||
|
||||
extraAliases = ''
|
||||
mailer-daemon: postmaster
|
||||
nobody: root
|
||||
hostmaster: root
|
||||
usenet: root
|
||||
news: root
|
||||
webmaster: root
|
||||
www: root
|
||||
ftp: root
|
||||
abuse: root
|
||||
noc: root
|
||||
security: root
|
||||
vaultwarden: root
|
||||
'';
|
||||
};
|
||||
|
||||
programs.msmtp.enable = lib.mkForce false;
|
||||
}
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
{ ... }:
|
||||
{ lib, ... }:
|
||||
with lib;
|
||||
{
|
||||
networking = {
|
||||
domain = "net.dn";
|
||||
networkmanager.enable = true;
|
||||
networkmanager = {
|
||||
enable = true;
|
||||
insertNameservers = mkForce [ "127.0.0.1" ];
|
||||
};
|
||||
enableIPv6 = true;
|
||||
firewall = {
|
||||
enable = true;
|
||||
|
|
|
|||
|
|
@ -1,139 +1,35 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
mkProxyHost = (
|
||||
{
|
||||
domain,
|
||||
proxyPass,
|
||||
ssl ? false,
|
||||
}:
|
||||
(
|
||||
if ssl then
|
||||
{
|
||||
forceSSL = true;
|
||||
sslCertificate = "/etc/letsencrypt/live/${domain}/fullchain.pem";
|
||||
sslCertificateKey = "/etc/letsencrypt/live/${domain}/privkey.pem";
|
||||
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 443;
|
||||
ssl = true;
|
||||
}
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
}
|
||||
)
|
||||
// {
|
||||
locations."/" = {
|
||||
proxyPass = proxyPass;
|
||||
extraConfig = ''
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
'';
|
||||
};
|
||||
|
||||
locations."^~ /.well-known/acme-challenge/" = {
|
||||
root = "/var/www/${domain}/html";
|
||||
extraConfig = ''
|
||||
default_type "text/plain";
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = ''
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384';
|
||||
ssl_prefer_server_ciphers on;
|
||||
'';
|
||||
}
|
||||
);
|
||||
|
||||
certScript = pkgs.writeShellScriptBin "genCert" ''
|
||||
acmeWebRoot="/var/www/$1/html/";
|
||||
if [ ! -d "$acmeWebRoot" ]; then
|
||||
mkdir -p "$acmeWebRoot"
|
||||
fi
|
||||
|
||||
REQUESTS_CA_BUNDLE=${../../../system/extra/ca.crt} \
|
||||
${pkgs.certbot}/bin/certbot certonly --webroot \
|
||||
--webroot-path $acmeWebRoot -v \
|
||||
-d "$1" \
|
||||
--server https://ca.net.dn:8443/acme/acme/directory \
|
||||
-m admin@mail.net.dn
|
||||
|
||||
chown nginx:nginx -R /etc/letsencrypt
|
||||
'';
|
||||
|
||||
vaultwarden = {
|
||||
domain = "bitwarden.net.dn";
|
||||
};
|
||||
in
|
||||
{
|
||||
environment.systemPackages = [
|
||||
certScript
|
||||
];
|
||||
security.acme = {
|
||||
acceptTerms = true;
|
||||
defaults = {
|
||||
validMinDays = 2;
|
||||
server = "https://10.0.0.1:${toString config.services.step-ca.port}/acme/acme/directory";
|
||||
renewInterval = "daily";
|
||||
email = "danny@net.dn";
|
||||
dnsProvider = "pdns";
|
||||
dnsPropagationCheck = false;
|
||||
environmentFile = config.sops.secrets."acme/env".path;
|
||||
};
|
||||
};
|
||||
|
||||
users.users.nginx.extraGroups = [ "acme" ];
|
||||
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
enableReload = true;
|
||||
recommendedGzipSettings = true;
|
||||
recommendedOptimisation = true;
|
||||
recommendedTlsSettings = true;
|
||||
recommendedProxySettings = true;
|
||||
|
||||
virtualHosts = {
|
||||
# Nextcloud - Server
|
||||
${config.services.nextcloud.hostName} = {
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 443;
|
||||
ssl = true;
|
||||
}
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
|
||||
locations."^~ /.well-known/acme-challenge/" = {
|
||||
root = "/var/www/${config.services.nextcloud.hostName}/html";
|
||||
extraConfig = ''
|
||||
default_type "text/plain";
|
||||
'';
|
||||
};
|
||||
|
||||
"files.${config.networking.domain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
sslCertificate = "/etc/letsencrypt/live/${config.services.nextcloud.hostName}/fullchain.pem";
|
||||
sslCertificateKey = "/etc/letsencrypt/live/${config.services.nextcloud.hostName}/privkey.pem";
|
||||
|
||||
extraConfig = ''
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384';
|
||||
ssl_prefer_server_ciphers on;
|
||||
'';
|
||||
};
|
||||
|
||||
"files.net.dn" = {
|
||||
listen = [
|
||||
{
|
||||
addr = "0.0.0.0";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
|
||||
root = "/var/www/files";
|
||||
locations."/" = {
|
||||
|
|
@ -153,10 +49,20 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
${vaultwarden.domain} = mkProxyHost {
|
||||
domain = vaultwarden.domain;
|
||||
proxyPass = "http://127.0.0.1:${builtins.toString config.services.vaultwarden.config.ROCKET_PORT}";
|
||||
ssl = true;
|
||||
"webcam.net.dn" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
|
||||
locations."/ws/" = {
|
||||
proxyPass = "http://10.0.0.130:8080/";
|
||||
extraConfig = ''
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
'';
|
||||
};
|
||||
|
||||
locations."/".proxyPass = "http://10.0.0.130:8001/phone.html";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,18 +4,29 @@ nextcloud:
|
|||
adminPassword: ENC[AES256_GCM,data:O2rK18+riVrvloqqLsMUXw==,iv:OosiF0g4l1mrgndbwUOvO2YUqxWVk1hvAZY0rHU9GPE=,tag:yh1ccDmthARLND0NwpLTCA==,type:str]
|
||||
step_ca:
|
||||
password: ENC[AES256_GCM,data:3EWxpk/ktZHJreqnR9ln5pfdPjgigoCC4lyoRWugHas=,iv:q9cWW8xTxYQnRYohBxnPIsbVSpvkZYVpYLRVeZgmsRM=,tag:UHZagnLvorZUrPq43YU+Gw==,type:str]
|
||||
vaultwarden: ENC[AES256_GCM,data:PSKtHBIxw0/z/rmtF83Yg3btHksbVVyWZ80nP0wl4zAHRpFXypvpchZu9/edX7RgREd+9okm21WyjNWRUDoGVTOJYOCFHZCvOUx4KzIL2c/i7jUjXwtvAEmikhL1qlunVrCPhDu0knQ5nvsqpgWyxgcZl52yxuskMSIRAOsMpCRePVwJerWW5tuQ5zteYeOR0GHR8Q0iwBm98YGlCbKvz/37jAjMQVxY5W9DE1Tu1XVyEPBeAVvEwZknFNIZg1ukB+kW9Z/sBwLEVbAGsiBSGjonP6KEsgKmtaIkbBPzpfA3CQ==,iv:X8x3ooFDkFIT2OuHICcP2J1zX8T6xZW8j71ZuaByx6Q=,tag:mfnDFf9riivZ3EBup1l6lw==,type:str]
|
||||
openldap:
|
||||
adminPassword: ENC[AES256_GCM,data:dSaynM6RBrhZLOwcN2djaA==,iv:t2xJuRO2irEFgcnNcZS25qCfXiZXHaoqcCZYcR041aY=,tag:K5DiJRp+AumtKafAOR49/w==,type:str]
|
||||
postfix:
|
||||
openldap: ENC[AES256_GCM,data:8woTLrSJ5qqZU7jizOIK9VGlaPaBuyhq6FOs6LwiE9WHYJzWCAw3D+449SmCVeEE2t+EZWmfRPaOQBceSeIfUY6WZ5vso1E29CWPq8Tk7AuHT2i/K82EhpapXst61IAgSa/y39MchA7LqwaiTzL3A2CJVM1k5Ay5iHUUDfXvLbUsVmn1NlNfOv2QPPd5g+2yR2oGGx5HTbTPQNfoiU77KtvtFmlrubAs413I3DGdhM4uiOS+FI9WgZ4Ia22BucaOLHp2odfWnEMbP+ZIyJFdu3CBcs1lbTnLLVI=,iv:RvPm2+WsTIPFWLlYzv/OyKKDy/fWhtEfut98mBoM/1A=,tag:wkkWK88D0jKfaudN+KpN0Q==,type:str]
|
||||
dovecot:
|
||||
openldap: ENC[AES256_GCM,data:G7jdoSqL2SYDv2alh7q65BaA8Ap898azUPf2KKWd5wbr9pRVsRhFxQxHdZDuTOHDhWcfaa+eqMgc5k9gGLBYIO9EWVyEZ01/QfG4GIHSDjubzZxCElwhJrtsFn1A+Ihv7T1IIGKBCdmQGhUwfBMtwYlIuj8PYZaty4+c/dxIOCfDr5HyM1C6qQ4RCJTDEh6B+Hpx8NlFO0+fRFC9+9tQYX0rjI7JZRSfbg7F23nEdkBATr/xlwQXj8dvXYMLZhUKaswFnRs5TrG97AVQ9t3rMguRHutCAqEROhml2lJvV3Vxb/yMmTrom8qSrbkuw00YfdlDCmUo5/E4Vu9DYL0kv0EnASyQ4vQbmVXz0clYEzEXBLWZIEu4QHGJ7jQWgsKFv+WSTvuunVQyNuij3SFWZLR/zdfJELxU,iv:bsGMMdDo1Mj4GxRbWuRmbH/WrLt25jK3we8JDYQRsLw=,tag:EugvDijjQnYcms70nZq5FQ==,type:str]
|
||||
vaultwarden: ENC[AES256_GCM,data:TDKzc3xPGUiopJ6aXV5a9k8mFN/4NQpfp69vWqQRjpAzWnIM290s4FTnsxJAX0NFfjiuQODhhxTuSmFOXR3+Ti9djSrqJ/ZjrVAMvV4NlpBg6klrCgcDtIfbZ0GqZjdoQYHcCz7V33fQGyTmqehjuVxdlatuLGoekSnuGbfBwY8FQgB+JECy8Y16r+ejplopw60+d43rvYXX4g8v0r4Gey567HVVB/zVizNDocentMaf99UiO/GBSOgbuKlU7+TfC0xhVcekEfZusZd7+LHZshfAjg==,iv:JcExp8YkGwV2nMbCK+n0KSL3+SryJZ0iKtVcU/Q+Cgs=,tag:dnDNa5faICuPUWy4nT49rg==,type:str]
|
||||
ldap:
|
||||
password: ENC[AES256_GCM,data:pqPj3Ar6xBLhHl4Q363sHw==,iv:bX7N9/oNMhtE/KbPah2ge4s87P2VsxHGoFkOyl83dxs=,tag:OaYsvds1tiw/x19UTAyizw==,type:str]
|
||||
env: ENC[AES256_GCM,data:LwrcgbeJf4Sb0Bx+OZ/qCf811bDpDcloltUZIzpQYz0zc1gnRExFxLStLDYeq3vv6DEjgfRdoB61Y1fb,iv:1jK/J2qfKODrbrNpSHl110jPvbNLl0zI//laowerJOc=,tag:TWa//iCY+SuAgp/PSfPkEg==,type:str]
|
||||
oauth:
|
||||
password: ENC[AES256_GCM,data:0iW80Iz4whkuyl8qvHN96Q==,iv:BI1n7Jjklye6WM2ss7jpaGgokrJpAG2Ipil7VrY30XM=,tag:zu//brQdDL7mZEkPOKUqPw==,type:str]
|
||||
powerdns-admin:
|
||||
secret: ENC[AES256_GCM,data:PH5KE++Oo13xo/DcnI9U6+Ht9oIi4T3n5L7c09eDxf6zZesbg4lFLsq0/hrVFiElErXpC5W2k7NOjqGA385UPQ==,iv:xaSgzhqMU9+ud1xfXLVkg3v2xcmIo35BOhml5VfHKBI=,tag:blQXoyYWzfiF5RGO7ynz9g==,type:str]
|
||||
salt: ENC[AES256_GCM,data:GITNFfimGPdPzOi2XD0ri2GMax30i+RwzNQrKL8nCOE=,iv:/lRVfNOpERS963+9JNf8wATIY9FcicT8xQ9Cbw2by/s=,tag:6193YZCQABce52qX6ISvzQ==,type:str]
|
||||
powerdns: ENC[AES256_GCM,data:humQiv+ilGAjU0qMsv0zoKlI20PKxA0VS75ivjkPb/bfzkbvEtH+3u/T8r4OogIhOJtl50+iRZl1imcrXf7drH0A69zUIhBS0xCagmj7,iv:orfh5F4uCYq2IplG0Y7Q/RcSqIm5Xyzn3ejzPsm+/0k=,tag:XeSBbIyYmWSWlyu2gypDzQ==,type:str]
|
||||
rspamd-trainer: ENC[AES256_GCM,data:XTKk0cBe+qIeTsTxlhPTPEbZS0cCoWH+,iv:M/xk7LywcRiKQM9LrnTnCKu3OS/YBf23CRkxh4ll1+c=,tag:LZUEvgTC1GPxS7iD9jVy/w==,type:str]
|
||||
acme:
|
||||
env: ENC[AES256_GCM,data:TWCrj3ZaUHfegDuJJtHQgt516auYu/3qpe35lfha6c3RLHABXtRArD8P6RPZE3HVdpFM0mvxkyme5MW8IMv2yhN9JPz5HLWZv0rjzkbhVyWem0X47c49jF20SnoMZ4yo+X4PZZ9GJKR4fu+0YrQkQXPJB773Yj2scQKx3Glh+iJoRLR8zLcM6JqbaJ4xHH+du6bs1PNyviB5NrGKnxYqzuVmBVLk,iv:ftoFg7i5KyYzdYaYCA8IPBsjHO1Ne/k361XPZ7HYqLo=,tag:v+X6fx/1dU0yoa0bHBLkDw==,type:str]
|
||||
postsrsd:
|
||||
secret: ENC[AES256_GCM,data:9BZPa+A/vE4PLapUdaZIQ7QJ3W0x6DrFTnTPrFUJPc2LC9q2RO2gHXIV2bc=,iv:ydGnCESCLbwyGKc+5witXDkT3OgW27LKen7PkqUL6mU=,tag:XxAJripX3eNM4jGFoZZ1+g==,type:str]
|
||||
grafana:
|
||||
password: ENC[AES256_GCM,data:3g7PymgXA27VxsLJA7U=,iv:09F8yEGw4j1Jd0HXDQyHbFxsr3Vg23mvWF5eZkU2KU8=,tag:y9AwmYwQjE1JB56sI8r8mA==,type:str]
|
||||
client_secret: ENC[AES256_GCM,data:znYMvBZH6eFeUZ7Mit0JEhm8hH97M+TKmCcesC/IS9Y=,iv:qywQIHIpgaS2pUcW1Uau//JU6UdMY52EVYCjhmnWJt4=,tag:Xo1h7ODXOkAnETfSYo4rfw==,type:str]
|
||||
prometheus:
|
||||
powerdns:
|
||||
password: ENC[AES256_GCM,data:pvb/aAvB/F1r0PW4mGJKQEExP88PapnViYpniOedJSf5e89/LwSeqYMd4x36zcGSlCV6myC+Xl/H+QBCw0ezcw==,iv:UI7UuJYJizYCO0ReC4SEPgmdPJNUnNuxgvkrhB1o/EQ=,tag:nUjTP7IQNx1ei8COQCTj+g==,type:str]
|
||||
nginxAuth: ENC[AES256_GCM,data:rYwuXHboAe3rf5e3kcJliKKXZ/Kcg60vnPGP+wukpaDdN8yJ00kk9cCNCjcvIyINEtL7TpEDjBX9oRsZT/E/FfWI6s133tDY,iv:Z/IiEi6oZm1Hv3m8c522GK6eYFf0syFn3A0o4S58DUI=,tag:y4n0Fm+l0OgGVHG+yttHfg==,type:str]
|
||||
sops:
|
||||
kms: []
|
||||
gcp_kms: []
|
||||
azure_kv: []
|
||||
hc_vault: []
|
||||
age:
|
||||
- recipient: age1z6f643a6vqm7cqh6fna5dhmxfkgwxgqy8kg9s0vf9uxhaswtngtspmqsjw
|
||||
enc: |
|
||||
|
|
@ -26,8 +37,7 @@ sops:
|
|||
Qm0wbmNGZDZwZlNTOVl0WVh5RXNxK2cK1Fwbgl5kKAFyrIIhBP+X4ZKFS4Xl39QY
|
||||
11qkglNgro/JBFJ/W7Hj5wtEd8QToiJM1RW0lQaI25sneQ2v6L5pDA==
|
||||
-----END AGE ENCRYPTED FILE-----
|
||||
lastmodified: "2025-05-04T13:11:13Z"
|
||||
mac: ENC[AES256_GCM,data:+V5vP4XbeXQP49gyisV4uQJjUybtK792DaFEWBHzLlKn2HiRj+qqSVR5XQrQMQQ5mKMhzsZXGq7QjjXtzKqgLCz5snItU63HzxQ6OxarNeg5pctk7i8ueNST4JpMxZODKGJncz2Ysq8OGrjZ6Nf4QVjO0XhFxZP6MbZxZL7wbuY=,iv:7jKt3uAY/ks8m/uzpos6XvldkpQjkgCHcLn+oRiY3mk=,tag:d6V+waMu4m2wi/H/J3bMXg==,type:str]
|
||||
pgp: []
|
||||
lastmodified: "2025-08-01T03:07:16Z"
|
||||
mac: ENC[AES256_GCM,data:VNmb5eOR2fEyBKD/MuHwC7IdN+SM2ybf/qtkvos3pakYFMCQcSQlJSCiassuZUxkEBl/rpMJ5NcObvuOJDAZZ/B7IAVTMJ8DkQy9cdIMLCRASNxd4EeWdZx517As8OslVdXKpPv15+i7buzj3X/QAPTVy2UUtyjWO2eqZ8ute0A=,iv:PpZmtmKsRKguFFkH2aqbLt54Ox7tOQwq1qtoQVN47Cs=,tag:kQ5kG6BODCqxuNl58EMvmQ==,type:str]
|
||||
unencrypted_suffix: _unencrypted
|
||||
version: 3.9.4
|
||||
version: 3.10.2
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
username,
|
||||
...
|
||||
|
|
@ -13,58 +12,6 @@ let
|
|||
sshPorts = [ 30072 ];
|
||||
sshPortsString = builtins.concatStringsSep ", " (builtins.map (p: builtins.toString p) sshPorts);
|
||||
|
||||
getCleanAddress =
|
||||
ip:
|
||||
with builtins;
|
||||
let
|
||||
result = replaceStrings [ "/24" "/32" ] [ "" "" ] ip;
|
||||
in
|
||||
result;
|
||||
|
||||
getReverseFilename =
|
||||
ip:
|
||||
with builtins;
|
||||
with lib.lists;
|
||||
with lib.strings;
|
||||
let
|
||||
octets = take 3 (splitString "." (getCleanAddress ip));
|
||||
reversedFilename = "db." + (concatStringsSep "." (reverseList octets));
|
||||
in
|
||||
reversedFilename;
|
||||
|
||||
getSubAddress =
|
||||
ip:
|
||||
with builtins;
|
||||
with lib.lists;
|
||||
with lib.strings;
|
||||
let
|
||||
octets = reverseList (splitString "." (getCleanAddress ip));
|
||||
sub = head octets;
|
||||
in
|
||||
sub;
|
||||
|
||||
reverseIP =
|
||||
ip:
|
||||
with builtins;
|
||||
with lib.lists;
|
||||
with lib.strings;
|
||||
let
|
||||
octets = splitString "." (getCleanAddress ip);
|
||||
reversedIP = (concatStringsSep "." (reverseList octets)) + ".in-addr.arpa";
|
||||
in
|
||||
reversedIP;
|
||||
|
||||
reverseZone =
|
||||
ip:
|
||||
with builtins;
|
||||
with lib.lists;
|
||||
with lib.strings;
|
||||
let
|
||||
octets = take 3 (splitString "." (getCleanAddress ip));
|
||||
reversedZone = (concatStringsSep "." (reverseList octets)) + ".in-addr.arpa";
|
||||
in
|
||||
reversedZone;
|
||||
|
||||
personal = {
|
||||
ip = "10.0.0.1/24";
|
||||
interface = "wg0";
|
||||
|
|
@ -131,8 +78,8 @@ let
|
|||
}
|
||||
{
|
||||
# ken
|
||||
dns = "ken";
|
||||
publicKey = "iWjBGArok96mFzFHXYjTxwyRHGQ4U0V77txoi6WS2QU=";
|
||||
dns = "phone.ken";
|
||||
publicKey = "knRpD7qb2JejioJBP5HZgWCrDEOWUq27+ueWPYwnWws=";
|
||||
allowedIPs = [ "10.0.0.134/32" ];
|
||||
}
|
||||
{
|
||||
|
|
@ -187,39 +134,12 @@ let
|
|||
allowedIPs = [ "10.0.0.144/32" ];
|
||||
}
|
||||
{
|
||||
dns = "rasp";
|
||||
publicKey = "z+2d+4FhSClGlSiAtaGnTgU6utxElfdRqiwPpCJFRn8=";
|
||||
# ken
|
||||
dns = "pc.ken";
|
||||
publicKey = "ERLMpSbSIYRN5HoKmvsk2852/aAvzjvMV7tOs0oupxI=";
|
||||
allowedIPs = [ "10.0.0.145/32" ];
|
||||
}
|
||||
];
|
||||
|
||||
dnsRecords =
|
||||
with builtins;
|
||||
concatStringsSep "\n" (
|
||||
map (
|
||||
r:
|
||||
let
|
||||
ip = getCleanAddress (elemAt r.allowedIPs 0);
|
||||
in
|
||||
''
|
||||
${r.dns} IN A ${ip}
|
||||
''
|
||||
) (fullRoute ++ meshRoute)
|
||||
);
|
||||
|
||||
dnsReversedRecords =
|
||||
with builtins;
|
||||
concatStringsSep "\n" (
|
||||
map (
|
||||
r:
|
||||
let
|
||||
reversed = getSubAddress (getCleanAddress (elemAt r.allowedIPs 0));
|
||||
in
|
||||
''
|
||||
${reversed} IN PTR ${r.dns}.${personal.domain}.
|
||||
''
|
||||
) (fullRoute ++ meshRoute)
|
||||
);
|
||||
in
|
||||
{
|
||||
networking = {
|
||||
|
|
@ -334,6 +254,27 @@ in
|
|||
extraHosts = "${kube.masterIP} ${kube.masterHostname}";
|
||||
};
|
||||
|
||||
services.postgresql = {
|
||||
enable = lib.mkDefault true;
|
||||
authentication = ''
|
||||
host powerdnsadmin powerdnsadmin 127.0.0.1/32 trust
|
||||
'';
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "powerdnsadmin";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
{
|
||||
name = "pdns";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
ensureDatabases = [
|
||||
"powerdnsadmin"
|
||||
"pdns"
|
||||
];
|
||||
};
|
||||
|
||||
services = {
|
||||
dbus.enable = true;
|
||||
blueman.enable = true;
|
||||
|
|
@ -348,97 +289,58 @@ in
|
|||
};
|
||||
};
|
||||
|
||||
bind = {
|
||||
powerdns = {
|
||||
enable = true;
|
||||
forwarders = [
|
||||
"8.8.8.8"
|
||||
"8.8.4.4"
|
||||
];
|
||||
cacheNetworks = [
|
||||
"127.0.0.0/24"
|
||||
"::1/128"
|
||||
personal.range
|
||||
kube.range
|
||||
];
|
||||
zones = {
|
||||
"${personal.domain}" = {
|
||||
master = true;
|
||||
allowQuery = [
|
||||
"127.0.0.0/24"
|
||||
"::1/128"
|
||||
personal.range
|
||||
kube.range
|
||||
];
|
||||
file =
|
||||
let
|
||||
serverIP = getCleanAddress personal.ip;
|
||||
kubeIP = getCleanAddress kube.ip;
|
||||
origin = "${personal.domain}.";
|
||||
hostname = config.networking.hostName;
|
||||
in
|
||||
pkgs.writeText "db.${personal.domain}" ''
|
||||
$ORIGIN ${origin}
|
||||
$TTL 1h
|
||||
@ IN SOA dns.${origin} admin.dns.${origin} (
|
||||
1 ; Serial
|
||||
3h ; Refresh
|
||||
1h ; Retry
|
||||
1w ; Expire
|
||||
1h) ; Negative Cache TTL
|
||||
IN NS dns.${origin}
|
||||
@ IN A ${serverIP}
|
||||
IN AAAA fe80::3319:e2bb:fc15:c9df
|
||||
@ IN MX 10 mail.${origin}
|
||||
IN TXT "v=spf1 mx"
|
||||
dns IN A ${serverIP}
|
||||
files IN A ${serverIP}
|
||||
nextcloud IN A ${serverIP}
|
||||
bitwarden IN A ${serverIP}
|
||||
ca IN A ${serverIP}
|
||||
${hostname} IN A ${serverIP}
|
||||
mail IN A ${serverIP}
|
||||
api-kube IN A ${kubeIP}
|
||||
vmail IN A 10.0.0.130
|
||||
${dnsRecords}
|
||||
'';
|
||||
};
|
||||
extraConfig = ''
|
||||
launch=gpgsql
|
||||
webserver-password=$WEB_PASSWORD
|
||||
api=yes
|
||||
api-key=$WEB_PASSWORD
|
||||
gpgsql-host=/var/run/postgresql
|
||||
gpgsql-dbname=pdns
|
||||
gpgsql-user=pdns
|
||||
webserver=yes
|
||||
webserver-port=8081
|
||||
local-port=5359
|
||||
'';
|
||||
secretFile = config.sops.secrets.powerdns.path;
|
||||
};
|
||||
|
||||
"${reverseZone personal.ip}" = {
|
||||
master = true;
|
||||
allowQuery = [
|
||||
"127.0.0.0/24"
|
||||
"::1/128"
|
||||
personal.range
|
||||
kube.range
|
||||
];
|
||||
file =
|
||||
let
|
||||
serverIP = getSubAddress personal.ip;
|
||||
hostname = config.networking.hostName;
|
||||
in
|
||||
pkgs.writeText "${getReverseFilename personal.ip}" ''
|
||||
$TTL 86400
|
||||
@ IN SOA dns.${personal.domain}. admin.dns.${personal.domain}. (
|
||||
1 ; Serial
|
||||
3h ; Refresh
|
||||
1h ; Retry
|
||||
1w ; Expire
|
||||
1h) ; Negative Cache TTL
|
||||
IN NS dns.${personal.domain}.
|
||||
|
||||
${serverIP} IN PTR dns.${personal.domain}.
|
||||
${serverIP} IN PTR mail.${personal.domain}.
|
||||
${serverIP} IN PTR ${hostname}.${personal.domain}.
|
||||
${serverIP} IN PTR nextcloud.${personal.domain}.
|
||||
${serverIP} IN PTR files.${personal.domain}.
|
||||
${serverIP} IN PTR bitwarden.${personal.domain}.
|
||||
${serverIP} IN PTR ca.${personal.domain}.
|
||||
130 IN PTR vmail.${personal.domain}.
|
||||
${dnsReversedRecords}
|
||||
'';
|
||||
|
||||
};
|
||||
pdns-recursor = {
|
||||
enable = true;
|
||||
forwardZones = {
|
||||
"${config.networking.domain}." = "127.0.0.1:5359";
|
||||
};
|
||||
forwardZonesRecurse = {
|
||||
"." = "8.8.8.8";
|
||||
};
|
||||
dnssecValidation = "off";
|
||||
dns.allowFrom = [
|
||||
"127.0.0.0/8"
|
||||
"10.0.0.0/24"
|
||||
"192.168.100.0/24"
|
||||
"::1/128"
|
||||
"fc00::/7"
|
||||
"fe80::/10"
|
||||
];
|
||||
yaml-settings = {
|
||||
webservice.webserver = true;
|
||||
};
|
||||
};
|
||||
|
||||
powerdns-admin = {
|
||||
enable = true;
|
||||
secretKeyFile = config.sops.secrets."powerdns-admin/secret".path;
|
||||
saltFile = config.sops.secrets."powerdns-admin/salt".path;
|
||||
config =
|
||||
# python
|
||||
''
|
||||
import cachelib
|
||||
|
||||
SESSION_TYPE = 'cachelib'
|
||||
SESSION_CACHELIB = cachelib.simple.SimpleCache()
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://powerdnsadmin@/powerdnsadmin?host=localhost'
|
||||
'';
|
||||
};
|
||||
|
||||
xserver = {
|
||||
|
|
@ -459,6 +361,39 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
oci-containers = {
|
||||
backend = "docker";
|
||||
containers = {
|
||||
uptime-kuma = {
|
||||
extraOptions = [ "--network=host" ];
|
||||
image = "louislam/uptime-kuma:1";
|
||||
volumes = [
|
||||
"/var/lib/uptime-kuma:/app/data"
|
||||
"${config.security.pki.caBundle}:/etc/ca.crt:ro"
|
||||
];
|
||||
environment = {
|
||||
NODE_EXTRA_CA_CERTS = "/etc/ca.crt";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts = {
|
||||
"powerdns.${config.networking.domain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass = "http://localhost:8000";
|
||||
};
|
||||
|
||||
"uptime.${config.networking.domain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass = "http://localhost:3001";
|
||||
};
|
||||
};
|
||||
|
||||
nix.settings.trusted-users = [
|
||||
username
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{ config, ... }:
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
inherit (lib) mkIf;
|
||||
in
|
||||
{
|
||||
sops = {
|
||||
secrets = {
|
||||
|
|
@ -6,10 +9,56 @@
|
|||
"nextcloud/adminPassword" = { };
|
||||
"step_ca/password" = { };
|
||||
vaultwarden = { };
|
||||
"postfix/openldap" = { };
|
||||
"openldap/adminPassword" = {
|
||||
owner = config.users.users.openldap.name;
|
||||
group = config.users.users.openldap.group;
|
||||
"oauth/password" = { };
|
||||
"ldap/password" = lib.mkIf config.mail-server.enable {
|
||||
mode = "0660";
|
||||
owner = config.services.openldap.user;
|
||||
group = config.services.openldap.group;
|
||||
};
|
||||
"ldap/env" = lib.mkIf config.mail-server.enable {
|
||||
mode = "0660";
|
||||
group = config.users.groups.docker.name;
|
||||
};
|
||||
"powerdns-admin/secret" = {
|
||||
mode = "0660";
|
||||
owner = "powerdnsadmin";
|
||||
group = "powerdnsadmin";
|
||||
};
|
||||
"powerdns-admin/salt" = {
|
||||
mode = "0660";
|
||||
owner = "powerdnsadmin";
|
||||
group = "powerdnsadmin";
|
||||
};
|
||||
powerdns = {
|
||||
mode = "0660";
|
||||
owner = "pdns";
|
||||
group = "pdns";
|
||||
};
|
||||
rspamd-trainer = { };
|
||||
"acme/env" = mkIf config.security.acme.acceptTerms {
|
||||
mode = "0660";
|
||||
owner = "acme";
|
||||
group = "acme";
|
||||
};
|
||||
"postsrsd/secret" = mkIf config.services.postsrsd.enable {
|
||||
mode = "0660";
|
||||
owner = config.services.postsrsd.user;
|
||||
group = config.services.postsrsd.group;
|
||||
};
|
||||
"grafana/password" = mkIf config.services.grafana.enable {
|
||||
mode = "0660";
|
||||
owner = "grafana";
|
||||
group = "grafana";
|
||||
};
|
||||
"grafana/client_secret" = mkIf config.services.grafana.enable {
|
||||
mode = "0660";
|
||||
owner = "grafana";
|
||||
group = "grafana";
|
||||
};
|
||||
"prometheus/powerdns/password" = mkIf config.services.prometheus.enable {
|
||||
mode = "0660";
|
||||
owner = "prometheus";
|
||||
group = config.users.users.prometheus.group;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,12 +32,14 @@ Bq-3sY8n13Dv0E6yx2hVIAlzLj3aE29LC4A2j81vW5MtpaM27lMpg.cwlqZ-8l1iZNeeS9.idRpRJ9zB
|
|||
x = "o-Srd0v3IY7zU9U2COE9BOsjyIPjBvNT2WKPTo8ePZI";
|
||||
y = "y5OFjciRMVg8ePaEsjSPWbKp_NjQ6U4CtbplRx7z3Bw";
|
||||
};
|
||||
name = "danny@smallstep.net.dn";
|
||||
name = "danny@net.dn";
|
||||
type = "JWK";
|
||||
}
|
||||
{
|
||||
claims = {
|
||||
maxTLSCertDuration = "8760h";
|
||||
minTLSCertDuration = "32h";
|
||||
maxTLSCertDuration = "72h";
|
||||
defaultTLSCertDuration = "72h";
|
||||
};
|
||||
name = "acme";
|
||||
options = {
|
||||
|
|
@ -73,7 +75,6 @@ Bq-3sY8n13Dv0E6yx2hVIAlzLj3aE29LC4A2j81vW5MtpaM27lMpg.cwlqZ-8l1iZNeeS9.idRpRJ9zB
|
|||
minVersion = 1.2;
|
||||
renegotiation = false;
|
||||
};
|
||||
|
||||
};
|
||||
port = 8443;
|
||||
openFirewall = true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,16 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIB0TCCAXegAwIBAgIRAINOgtMhBOgnEO8vDGPMgJwwCgYIKoZIzj0EAwIwMjET
|
||||
MBEGA1UEChMKc3RlcC1jYS1kbjEbMBkGA1UEAxMSc3RlcC1jYS1kbiBSb290IENB
|
||||
MB4XDTI1MDQxODE0NTY1NloXDTM1MDQxNjE0NTY1NlowOjETMBEGA1UEChMKc3Rl
|
||||
cC1jYS1kbjEjMCEGA1UEAxMac3RlcC1jYS1kbiBJbnRlcm1lZGlhdGUgQ0EwWTAT
|
||||
BgcqhkjOPQIBBggqhkjOPQMBBwNCAAQ6KmC7bEeVgjTCYXfzlizToJyc++SFFfWO
|
||||
F7VJ+wpsaIa/Rg6/M8K2HeZCUDRz6inzBoE9tXtZhwMSGvPUJemmo2YwZDAOBgNV
|
||||
HQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBADAdBgNVHQ4EFgQUvbzEHd3+
|
||||
ibxSROeCMteBg5JHcM0wHwYDVR0jBBgwFoAU2Cr1FiPu24tU5Asobi0Zt3R9HvUw
|
||||
CgYIKoZIzj0EAwIDSAAwRQIgaMQwCoSw+dDYyQrODv6CQbyN83bSn/zsARhtzovQ
|
||||
ZmQCIQC318dCE9AgP+vBFQrVnalkev9JusznTW9nT1iCof3+5g==
|
||||
-----END CERTIFICATE-----
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIBqDCCAU2gAwIBAgIQBnU3DLmknEy9zgvkjtIhEjAKBggqhkjOPQQDAjAyMRMw
|
||||
EQYDVQQKEwpzdGVwLWNhLWRuMRswGQYDVQQDExJzdGVwLWNhLWRuIFJvb3QgQ0Ew
|
||||
HhcNMjUwNDE4MTQ1NjU1WhcNMzUwNDE2MTQ1NjU1WjAyMRMwEQYDVQQKEwpzdGVw
|
||||
|
|
|
|||
36
system/modules/actual.nix
Normal file
36
system/modules/actual.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
fqdn ? null,
|
||||
}:
|
||||
{ config, ... }:
|
||||
let
|
||||
inherit (builtins) toString;
|
||||
finalFqdn = if fqdn != null then fqdn else config.networking.fqdn;
|
||||
in
|
||||
{
|
||||
services.actual = {
|
||||
enable = true;
|
||||
settings = {
|
||||
port = 31000;
|
||||
hostname = "127.0.0.1";
|
||||
serverFiles = "/var/lib/actual/server-files";
|
||||
userFiles = "/var/lib/actual/user-files";
|
||||
loginMethod = "openid";
|
||||
};
|
||||
};
|
||||
|
||||
services.actual-budget-api = {
|
||||
enable = true;
|
||||
listenPort = 31001;
|
||||
listenHost = "127.0.0.1";
|
||||
serverURL = "https://${finalFqdn}";
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts."${finalFqdn}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
|
||||
locations."/api/".proxyPass =
|
||||
"http://localhost:${toString config.services.actual-budget-api.listenPort}/";
|
||||
locations."/".proxyPass = "http://localhost:${toString config.services.actual.settings.port}";
|
||||
};
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{
|
||||
systemd.timers."certbot-renew" = {
|
||||
enable = true;
|
||||
description = "certbot renew";
|
||||
timerConfig = {
|
||||
Persistent = true;
|
||||
OnCalendar = "*-*-* 16:30:00";
|
||||
Unit = "certbot-renew.service";
|
||||
};
|
||||
wantedBy = [ "timers.target" ];
|
||||
};
|
||||
|
||||
systemd.timers."certbot-nginx-reload" = lib.mkIf config.services.nginx.enable {
|
||||
enable = true;
|
||||
description = "certbot renew";
|
||||
timerConfig = {
|
||||
Persistent = true;
|
||||
OnCalendar = "*-*-* 16:32:00";
|
||||
Unit = "nginx-config-reload.service";
|
||||
};
|
||||
wantedBy = [ "timers.target" ];
|
||||
};
|
||||
|
||||
systemd.services."certbot-renew" = {
|
||||
enable = true;
|
||||
after = (if config.services.nginx.enable then [ "nginx.service" ] else [ ]) ++ [
|
||||
"network.target"
|
||||
];
|
||||
environment = {
|
||||
"REQUESTS_CA_BUNDLE" = ../extra/ca.crt;
|
||||
};
|
||||
serviceConfig = {
|
||||
ExecStart = ''${pkgs.certbot}/bin/certbot renew --no-random-sleep-on-renew --force-renewal'';
|
||||
ExecStartPost = lib.mkIf config.services.nginx.enable "${pkgs.busybox}/bin/chown nginx:nginx -R /etc/letsencrypt";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services."nginx-config-reload" = lib.mkIf config.services.nginx.enable {
|
||||
after = [ "certbot-renew.service" ];
|
||||
wantedBy = [ "certbot-renew.service" ];
|
||||
serviceConfig = {
|
||||
User = "root";
|
||||
ExecStartPre = "${pkgs.busybox}/bin/chown -R nginx:nginx /etc/letsencrypt/";
|
||||
};
|
||||
};
|
||||
}
|
||||
100
system/modules/dns-server/default.nix
Normal file
100
system/modules/dns-server/default.nix
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.dns-server;
|
||||
in
|
||||
with lib;
|
||||
{
|
||||
options.dns-server = {
|
||||
enable = mkEnableOption "PowerDNS server and PowerDNS Recursor";
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Open 53 port in firewall
|
||||
'';
|
||||
};
|
||||
|
||||
webAdmin = {
|
||||
enable = mkEnableOption "Enable PowerDNS Admin";
|
||||
saltFile = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Slat value for serialization, can be generated with `openssl rand -hex 16`
|
||||
'';
|
||||
};
|
||||
apiSecretFile = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
The file content should be
|
||||
```
|
||||
YOUR_PASSWORD
|
||||
```
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
networking.firewall = mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [ 53 ];
|
||||
allowedUDPPorts = [ 53 ];
|
||||
};
|
||||
|
||||
services = {
|
||||
powerdns = {
|
||||
enable = true;
|
||||
extraConfig = ''
|
||||
launch=gpgsql
|
||||
webserver-password=$WEB_PASSWORD
|
||||
api=yes
|
||||
api-key=$WEB_PASSWORD
|
||||
gpgsql-host=/var/run/postgresql
|
||||
gpgsql-dbname=pdns
|
||||
gpgsql-user=pdns
|
||||
webserver=yes
|
||||
local-port=5359
|
||||
'';
|
||||
secretFile = config.sops.secrets.powerdns.path;
|
||||
};
|
||||
|
||||
pdns-recursor = {
|
||||
enable = true;
|
||||
forwardZones = {
|
||||
"net.dn" = "127.0.0.1:5359";
|
||||
};
|
||||
forwardZonesRecurse = {
|
||||
"" = "8.8.8.8;8.8.4.4";
|
||||
};
|
||||
dnssecValidation = "off";
|
||||
dns.allowFrom = [
|
||||
"127.0.0.0/8"
|
||||
"10.0.0.0/24"
|
||||
"192.168.100.0/24"
|
||||
"::1/128"
|
||||
"fc00::/7"
|
||||
"fe80::/10"
|
||||
];
|
||||
};
|
||||
|
||||
powerdns-admin = {
|
||||
enable = true;
|
||||
secretKeyFile = config.sops.secrets."powerdns-admin/secret".path;
|
||||
saltFile = config.sops.secrets."powerdns-admin/salt".path;
|
||||
config =
|
||||
# python
|
||||
''
|
||||
import cachelib
|
||||
|
||||
SESSION_TYPE = 'cachelib'
|
||||
SESSION_CACHELIB = cachelib.simple.SimpleCache()
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://powerdnsadmin@/powerdnsadmin?host=localhost'
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
50
system/modules/grafana.nix
Normal file
50
system/modules/grafana.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
passFile,
|
||||
smtpHost,
|
||||
smtpDomain,
|
||||
domain,
|
||||
extraSettings ? { },
|
||||
}:
|
||||
{ config, ... }:
|
||||
let
|
||||
email = "grafana@${smtpDomain}";
|
||||
in
|
||||
{
|
||||
services.grafana = {
|
||||
enable = true;
|
||||
settings = (
|
||||
{
|
||||
server = {
|
||||
http_addr = "127.0.0.1";
|
||||
http_port = 31003;
|
||||
root_url = "https://${domain}";
|
||||
domain = domain;
|
||||
};
|
||||
smtp = {
|
||||
enabled = true;
|
||||
user = "grafana";
|
||||
password = "$__file{${passFile}}";
|
||||
host = smtpHost;
|
||||
from_address = email;
|
||||
cert_file = config.security.pki.caBundle;
|
||||
};
|
||||
security = {
|
||||
admin_email = email;
|
||||
admin_password = "$__file{${passFile}}";
|
||||
};
|
||||
}
|
||||
// extraSettings
|
||||
);
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts."${domain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString config.services.grafana.settings.server.http_port}";
|
||||
proxyWebsockets = true;
|
||||
recommendedProxySettings = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,322 +0,0 @@
|
|||
{
|
||||
fqdn ? null,
|
||||
origin ? null,
|
||||
destination ? null,
|
||||
networks ? null,
|
||||
rootAlias ? "root",
|
||||
extraAliases ? "",
|
||||
enableOpenldap ? true,
|
||||
dovecotLdapSecretFile,
|
||||
openldapAdmPassPath,
|
||||
sslKeyPath,
|
||||
sslCertPath,
|
||||
}:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
postfixFqdn = if fqdn != null then fqdn else config.networking.fqdn;
|
||||
postfixOrigin = if origin != null then origin else postfixFqdn;
|
||||
postfixDest =
|
||||
if destination != null then
|
||||
destination
|
||||
else
|
||||
[
|
||||
"localhost"
|
||||
"localhost.${postfixFqdn}"
|
||||
];
|
||||
|
||||
postfixNet =
|
||||
if networks != null then
|
||||
networks
|
||||
else
|
||||
[
|
||||
"127.0.0.0/8"
|
||||
"[::1]/128"
|
||||
];
|
||||
|
||||
postfixMailDir = "~/Maildir";
|
||||
mailLocationPrefix = "/var/mail/vhosts";
|
||||
mailLocation = "${mailLocationPrefix}/%d/%n/";
|
||||
|
||||
dcList = lib.strings.splitString "." postfixFqdn;
|
||||
domain = lib.strings.concatStringsSep "," (lib.lists.forEach dcList (x: "dc=" + x));
|
||||
|
||||
dovecotSecretPath = "/run/dovecot2-secret";
|
||||
ldapSecretConf = "${dovecotSecretPath}/dovecot-ldap.conf.ext";
|
||||
|
||||
ldapDefaultConf = pkgs.writeText "dovecot-ldap.conf.ext" ''
|
||||
ldap_version = 3
|
||||
auth_bind_userdn = uid=%u,ou=mail,${domain}
|
||||
auth_bind = yes
|
||||
hosts = ${postfixFqdn}
|
||||
dn = cn=admin,${domain}
|
||||
base = ou=mail,${domain}
|
||||
pass_filter = (&(objectClass=inetorgperson)(uid=%u))
|
||||
|
||||
user_filter = (&(objectClass=inetorgperson)(uid=%u))
|
||||
'';
|
||||
|
||||
mailUser = "vmail";
|
||||
in
|
||||
with builtins;
|
||||
{
|
||||
environment.sessionVariables = {
|
||||
MAILDIR = postfixMailDir;
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = [
|
||||
25 # SMTP
|
||||
465 # SMTPS
|
||||
587 # STARTTLS
|
||||
80
|
||||
143 # IMAP STARTTLS
|
||||
993 # IMAPS
|
||||
110 # POP3 STARTTLS
|
||||
995 # POP3S
|
||||
];
|
||||
|
||||
users.groups.${mailUser} = {
|
||||
gid = 5000;
|
||||
};
|
||||
|
||||
users.users.${mailUser} = {
|
||||
isSystemUser = true;
|
||||
uid = 5000;
|
||||
group = mailUser;
|
||||
};
|
||||
|
||||
services.postfix = {
|
||||
inherit rootAlias;
|
||||
|
||||
enable = lib.mkDefault true;
|
||||
hostname = postfixFqdn;
|
||||
origin = postfixOrigin;
|
||||
destination = postfixDest;
|
||||
networks = postfixNet;
|
||||
sslKey = sslKeyPath;
|
||||
sslCert = sslCertPath;
|
||||
|
||||
config = {
|
||||
virtual_uid_maps = [
|
||||
"static:${toString config.users.users.vmail.uid}"
|
||||
];
|
||||
virtual_gid_maps = [
|
||||
"static:${toString config.users.groups.vmail.gid}"
|
||||
];
|
||||
virtual_mailbox_domains = [ postfixFqdn ];
|
||||
virtual_transport = "lmtp:unix:private/dovecot-lmtp";
|
||||
|
||||
tls_preempt_cipherlist = "yes";
|
||||
smtpd_use_tls = "yes";
|
||||
smtpd_tls_security_level = "may";
|
||||
smtpd_sasl_type = "dovecot";
|
||||
smtpd_sasl_path = "private/auth";
|
||||
smtpd_sasl_auth_enable = "yes";
|
||||
smtpd_recipient_restrictions = "permit_sasl_authenticated,reject";
|
||||
smtpd_relay_restrictions = "permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination";
|
||||
|
||||
home_mailbox = postfixMailDir;
|
||||
};
|
||||
|
||||
postmasterAlias = "root";
|
||||
extraAliases = ''
|
||||
mailer-daemon: postmaster
|
||||
nobody: root
|
||||
hostmaster: root
|
||||
usenet: root
|
||||
news: root
|
||||
webmaster: root
|
||||
www: root
|
||||
ftp: root
|
||||
abuse: root
|
||||
noc: root
|
||||
security: root
|
||||
''
|
||||
+ extraAliases;
|
||||
};
|
||||
|
||||
services.dovecot2 = {
|
||||
enable = lib.mkDefault true;
|
||||
enableImap = true;
|
||||
enablePop3 = true;
|
||||
enableLmtp = true;
|
||||
mailLocation = lib.mkDefault "maildir:${mailLocation}";
|
||||
mailUser = mailUser;
|
||||
mailGroup = mailUser;
|
||||
sslServerKey = sslKeyPath;
|
||||
sslServerCert = sslCertPath;
|
||||
sslCACert = config.security.pki.caBundle;
|
||||
|
||||
extraConfig = ''
|
||||
log_path = /var/log/dovecot.log
|
||||
auth_debug = yes
|
||||
mail_debug = yes
|
||||
|
||||
auth_mechanisms = plain login
|
||||
ssl = yes
|
||||
ssl_dh_parameters_length = 2048
|
||||
ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL
|
||||
ssl_prefer_server_ciphers = yes
|
||||
|
||||
service auth {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
|
||||
mode = 0660
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
}
|
||||
}
|
||||
|
||||
service lmtp {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/dovecot-lmtp {
|
||||
mode = 0600
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
}
|
||||
}
|
||||
|
||||
passdb ldap {
|
||||
driver = ldap
|
||||
args = ${ldapSecretConf}
|
||||
}
|
||||
|
||||
userdb {
|
||||
driver = static
|
||||
args = uid=${mailUser} gid=${mailUser} home=${mailLocation}
|
||||
}
|
||||
|
||||
lda_mailbox_autosubscribe = yes
|
||||
lda_mailbox_autocreate = yes
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.dovecot2 = {
|
||||
serviceConfig = {
|
||||
RuntimeDirectory = [ "dovecot2-secret" ];
|
||||
RuntimeDirectoryMode = "0640";
|
||||
ExecStartPre = [
|
||||
''${pkgs.busybox.out}/bin/mkdir -p ${mailLocationPrefix}''
|
||||
''${pkgs.busybox.out}/bin/chown -R ${mailUser}:${mailUser} ${mailLocationPrefix}''
|
||||
''${pkgs.busybox.out}/bin/chmod 770 ${mailLocationPrefix}''
|
||||
''${pkgs.busybox.out}/bin/sh -c "${pkgs.busybox.out}/bin/cat ${ldapDefaultConf} ${dovecotLdapSecretFile} > ${ldapSecretConf}"''
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.openldap = lib.mkIf enableOpenldap {
|
||||
enable = true;
|
||||
urlList = [ "ldap:///" ];
|
||||
|
||||
settings = {
|
||||
attrs = {
|
||||
olcLogLevel = "conns config";
|
||||
};
|
||||
|
||||
children = {
|
||||
"cn=schema".includes = [
|
||||
"${pkgs.openldap}/etc/schema/core.ldif"
|
||||
"${pkgs.openldap}/etc/schema/cosine.ldif"
|
||||
"${pkgs.openldap}/etc/schema/inetorgperson.ldif"
|
||||
"${pkgs.openldap}/etc/schema/nis.ldif"
|
||||
];
|
||||
|
||||
"olcDatabase={1}mdb".attrs = {
|
||||
objectClass = [
|
||||
"olcDatabaseConfig"
|
||||
"olcMdbConfig"
|
||||
];
|
||||
|
||||
olcDatabase = "{1}mdb";
|
||||
olcDbDirectory = "/var/lib/openldap/data";
|
||||
olcSuffix = "${domain}";
|
||||
|
||||
olcRootDN = "cn=admin,${domain}";
|
||||
olcRootPW.path = openldapAdmPassPath;
|
||||
|
||||
olcAccess = [
|
||||
''
|
||||
{0}to attrs=userPassword
|
||||
by dn="cn=admin,${domain}" read
|
||||
by self write
|
||||
by anonymous auth
|
||||
by * none
|
||||
''
|
||||
''
|
||||
{1}to *
|
||||
by * read
|
||||
''
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
environment.etc."openldap/base.ldif" = {
|
||||
mode = "0770";
|
||||
user = config.services.openldap.user;
|
||||
group = config.services.openldap.group;
|
||||
text = ''
|
||||
dn: ${domain}
|
||||
objectClass: top
|
||||
objectClass: domain
|
||||
dc: ${elemAt dcList 0}
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.openldap-init-base = {
|
||||
wantedBy = [ "openldap.service" ];
|
||||
requires = [ "openldap.service" ];
|
||||
after = [ "openldap.service" ];
|
||||
serviceConfig = {
|
||||
User = config.services.openldap.user;
|
||||
Group = config.services.openldap.group;
|
||||
Type = "oneshot";
|
||||
ExecStart =
|
||||
let
|
||||
dcScript = pkgs.writeShellScriptBin "openldap-init" ''
|
||||
BASE_DN="${domain}"
|
||||
LDIF_FILE="/etc/openldap/base.ldif"
|
||||
ADMIN_DN="cn=admin,${domain}"
|
||||
${pkgs.openldap}/bin/ldapsearch -x -b "$BASE_DN" -s base "(objectclass=*)" > /dev/null 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Base DN $BASE_DN not exist, import $LDIF_FILE"
|
||||
${pkgs.openldap}/bin/ldapadd -x -D "$ADMIN_DN" -y ${openldapAdmPassPath} -W -f "$LDIF_FILE"
|
||||
else
|
||||
echo "Base DN $BASE_DN exists, skip"
|
||||
fi
|
||||
'';
|
||||
in
|
||||
"${dcScript}/bin/openldap-init";
|
||||
};
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
docker = {
|
||||
enable = lib.mkDefault true;
|
||||
rootless = {
|
||||
enable = true;
|
||||
setSocketVariable = true;
|
||||
};
|
||||
};
|
||||
|
||||
oci-containers = {
|
||||
backend = "docker";
|
||||
containers = {
|
||||
lam = {
|
||||
image = "ghcr.io/ldapaccountmanager/lam:9.2";
|
||||
extraOptions = [ "--network=host" ];
|
||||
autoStart = true;
|
||||
environment = {
|
||||
LDAP_DOMAIN = postfixFqdn;
|
||||
LDAP_SERVER = "ldap://${postfixFqdn}";
|
||||
LDAP_USERS_DN = "ou=mail,${domain}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -7,6 +7,13 @@ with lib;
|
|||
{
|
||||
options.mail-server = {
|
||||
enable = mkEnableOption "mail-server";
|
||||
caFile = mkOption {
|
||||
type = types.path;
|
||||
default = config.security.pki.caBundle;
|
||||
description = ''
|
||||
Extra CA certification to trust;
|
||||
'';
|
||||
};
|
||||
|
||||
openFirewall = mkOption {
|
||||
type = types.bool;
|
||||
|
|
@ -26,6 +33,23 @@ with lib;
|
|||
'';
|
||||
};
|
||||
|
||||
rootAlias = mkOption {
|
||||
type = with types; uniq str;
|
||||
default = "";
|
||||
description = "Root alias";
|
||||
example = ''
|
||||
<your username>
|
||||
'';
|
||||
};
|
||||
|
||||
virtual = mkOption {
|
||||
type = lib.types.lines;
|
||||
default = "";
|
||||
description = ''
|
||||
Entries for the virtual alias map, cf. man-page {manpage}`virtual(5)`.
|
||||
'';
|
||||
};
|
||||
|
||||
extraAliases = mkOption {
|
||||
type = with types; str;
|
||||
default = "";
|
||||
|
|
@ -86,37 +110,44 @@ with lib;
|
|||
description = "Postfix networks";
|
||||
};
|
||||
|
||||
sslKey = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to the SSL key";
|
||||
example = "/etc/ssl/private/key.pem";
|
||||
};
|
||||
|
||||
sslCert = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to the SSL Certification";
|
||||
example = "/etc/ssl/private/cert.pem";
|
||||
};
|
||||
|
||||
dovecot = {
|
||||
ldapFile = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to the dovecot openldap config file";
|
||||
example = "/run/secrets/dovecot/ldap";
|
||||
oauth = {
|
||||
username = mkOption {
|
||||
type = with types; uniq str;
|
||||
default = "keycloak";
|
||||
description = "Keycloak username";
|
||||
};
|
||||
};
|
||||
|
||||
openldap = {
|
||||
passwordFile = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to the openldap admin password file";
|
||||
example = "/run/secrets/openldap/passwd";
|
||||
description = "Path to the keycloak password file";
|
||||
example = "/run/secrets/keycloak/password";
|
||||
};
|
||||
};
|
||||
|
||||
ldap = {
|
||||
passwordFile = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to the openldap password file";
|
||||
example = "/run/secrets/ldap/password";
|
||||
};
|
||||
|
||||
enableWebUI = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Use docker to run Ldap Account Manager for using web ui.";
|
||||
webEnv = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to phpLDAPadmin env file";
|
||||
example = "/run/secrets/ldap/env";
|
||||
};
|
||||
};
|
||||
|
||||
rspamd = {
|
||||
trainerSecret = mkOption {
|
||||
type = with types; path;
|
||||
description = "Path to rspamd trainer secret";
|
||||
example = "/run/secrets/rspamd-trainer/secret";
|
||||
};
|
||||
port = mkOption {
|
||||
type = with types; int;
|
||||
default = 11334;
|
||||
description = "Port for rspamd webUI";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,155 +4,452 @@
|
|||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
cfg = config.mail-server;
|
||||
dcList = strings.splitString "." cfg.domain;
|
||||
ldapDomain = strings.concatStringsSep "," (lists.forEach dcList (dc: "dc=" + dc));
|
||||
|
||||
dcList = lib.strings.splitString "." cfg.domain;
|
||||
ldapDomain = lib.strings.concatStringsSep "," (lib.lists.forEach dcList (x: "dc=" + x));
|
||||
dovecotSecretPath = "/run/dovecot-secret";
|
||||
authBaseConf = pkgs.writeText "dovecot-auth.conf.ext" ''
|
||||
passdb ldap {
|
||||
auth_username_format = %{user | lower}
|
||||
ldap_bind = no
|
||||
ldap_filter = (&(objectClass=inetOrgPerson)(uid=%{user | username}))
|
||||
use_worker = no
|
||||
|
||||
dovecotSecretPath = "/run/dovecot2-secret";
|
||||
ldapDefaultConf = pkgs.writeText "dovecot-ldap.conf.ext" ''
|
||||
ldap_version = 3
|
||||
auth_bind_userdn = uid=%u,ou=mail,${ldapDomain}
|
||||
auth_bind = yes
|
||||
hosts = ${cfg.domain}
|
||||
dn = cn=admin,${ldapDomain}
|
||||
base = ou=mail,${ldapDomain}
|
||||
pass_filter = (&(objectClass=inetorgperson)(uid=%u))
|
||||
|
||||
user_filter = (&(objectClass=inetorgperson)(uid=%u))
|
||||
fields {
|
||||
user = %{ldap:mail}
|
||||
password = %{ldap:userPassword}
|
||||
}
|
||||
}
|
||||
ldap_auth_dn = cn=admin,${ldapDomain}
|
||||
ldap_auth_dn_password = $LDAP_PASSWORD
|
||||
ldap_uris = ldap://localhost
|
||||
ldap_base = ${ldapDomain}
|
||||
'';
|
||||
ldapSecretConf = "${dovecotSecretPath}/dovecot-ldap.conf.ext";
|
||||
authConf = "${dovecotSecretPath}/dovecot-auth.conf.ext";
|
||||
|
||||
oauthConf = pkgs.writeText "dovecot-oauth.conf.ext" ''
|
||||
oauth2 {
|
||||
client_id = dovecot
|
||||
client_secret = 1l9EyvmaDQBMUHXgPkH69RwNcm7gDFbB
|
||||
introspection_mode = post
|
||||
introspection_url = https://keycloak.net.dn/realms/master/protocol/openid-connect/token/introspect
|
||||
username_attribute = email
|
||||
}
|
||||
'';
|
||||
|
||||
dovecotDomain = config.services.postfix.hostname;
|
||||
in
|
||||
with builtins;
|
||||
with lib;
|
||||
{
|
||||
config = mkIf cfg.enable {
|
||||
security.acme.certs = {
|
||||
"${config.services.postfix.hostname}" = {
|
||||
dnsProvider = null;
|
||||
webroot = "/var/lib/acme/acme-challenge";
|
||||
postRun = ''
|
||||
systemctl restart postfix.service
|
||||
systemctl restart dovecot.service
|
||||
systemctl restart rspamd-trainer.service
|
||||
'';
|
||||
};
|
||||
"${cfg.domain}" = {
|
||||
dnsProvider = null;
|
||||
webroot = "/var/lib/acme/acme-challenge";
|
||||
};
|
||||
};
|
||||
|
||||
# ===== opendkim ===== #
|
||||
services.opendkim = {
|
||||
enable = true;
|
||||
domains = "csl:${cfg.domain}";
|
||||
selector = "mail";
|
||||
};
|
||||
|
||||
# ===== Postfix ===== #
|
||||
environment.sessionVariables = {
|
||||
MAILDIR = cfg.mailDir;
|
||||
};
|
||||
|
||||
systemd.services.postfix = {
|
||||
requires = [
|
||||
"acme-finished-${config.services.postfix.hostname}.target"
|
||||
];
|
||||
serviceConfig.LoadCredential =
|
||||
let
|
||||
certDir = config.security.acme.certs."${config.services.postfix.hostname}".directory;
|
||||
in
|
||||
[
|
||||
"cert.pem:${certDir}/cert.pem"
|
||||
"key.pem:${certDir}/key.pem"
|
||||
];
|
||||
};
|
||||
|
||||
services.postfix = {
|
||||
enable = true;
|
||||
hostname = cfg.domain;
|
||||
hostname = "mail.${cfg.domain}";
|
||||
origin = cfg.origin;
|
||||
destination = cfg.destination;
|
||||
networks = cfg.networks;
|
||||
|
||||
config = {
|
||||
virtual_uid_maps = [
|
||||
"static:${toString cfg.uid}"
|
||||
];
|
||||
virtual_gid_maps = [
|
||||
"static:${toString cfg.gid}"
|
||||
];
|
||||
|
||||
virtual_mailbox_domains = [ cfg.domain ];
|
||||
virtual_transport = "lmtp:unix:private/dovecot-lmtp";
|
||||
|
||||
tls_preempt_cipherlist = "yes";
|
||||
smtpd_use_tls = "yes";
|
||||
smtpd_tls_security_level = "may";
|
||||
smtpd_sasl_type = "dovecot";
|
||||
smtpd_sasl_path = "private/auth";
|
||||
smtpd_sasl_auth_enable = "yes";
|
||||
smtpd_recipient_restrictions = "permit_sasl_authenticated,reject";
|
||||
virtual = cfg.virtual;
|
||||
enableSubmissions = true;
|
||||
relayPort = 465;
|
||||
submissionOptions = {
|
||||
milter_macro_daemon_name = "ORIGINATING";
|
||||
smtpd_client_restrictions = "permit_mynetworks, permit_sasl_authenticated, reject";
|
||||
smtpd_relay_restrictions = "permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination";
|
||||
|
||||
home_mailbox = cfg.mailDir;
|
||||
smtpd_tls_security_level = "encrypt";
|
||||
smtpd_tls_loglevel = "10";
|
||||
};
|
||||
|
||||
config =
|
||||
let
|
||||
credsDir = "/run/credentials/postfix.service";
|
||||
certDir = "${credsDir}/cert.pem";
|
||||
keyDir = "${credsDir}/key.pem";
|
||||
in
|
||||
{
|
||||
virtual_uid_maps = [
|
||||
"static:${toString cfg.uid}"
|
||||
];
|
||||
virtual_gid_maps = [
|
||||
"static:${toString cfg.gid}"
|
||||
];
|
||||
|
||||
virtual_mailbox_domains = [ cfg.domain ];
|
||||
virtual_transport = "lmtp:unix:private/dovecot-lmtp";
|
||||
smtpd_sasl_type = "dovecot";
|
||||
smtpd_sasl_path = "private/auth";
|
||||
smtpd_sasl_auth_enable = "yes";
|
||||
tls_random_source = "dev:/dev/urandom";
|
||||
|
||||
smtp_tls_security_level = "may";
|
||||
smtp_tls_chain_files = [
|
||||
keyDir
|
||||
certDir
|
||||
];
|
||||
|
||||
smtpd_tls_chain_files = [
|
||||
keyDir
|
||||
certDir
|
||||
];
|
||||
|
||||
home_mailbox = cfg.mailDir;
|
||||
}
|
||||
// optionalAttrs config.services.opendkim.enable (
|
||||
let
|
||||
opendkimSocket = strings.removePrefix "local:" config.services.opendkim.socket;
|
||||
in
|
||||
{
|
||||
smtpd_milters = [ "unix:${opendkimSocket}" ];
|
||||
non_smtpd_milters = [ "unix:${opendkimSocket}" ];
|
||||
milter_default_action = "accept";
|
||||
}
|
||||
);
|
||||
|
||||
rootAlias = cfg.rootAlias;
|
||||
postmasterAlias = "root";
|
||||
extraAliases =
|
||||
''
|
||||
mailer-daemon: postmaster
|
||||
nobody: root
|
||||
hostmaster: root
|
||||
usenet: root
|
||||
news: root
|
||||
webmaster: root
|
||||
www: root
|
||||
ftp: root
|
||||
abuse: root
|
||||
noc: root
|
||||
security: root
|
||||
''
|
||||
+ cfg.extraAliases;
|
||||
extraAliases = ''
|
||||
mailer-daemon: postmaster
|
||||
nobody: root
|
||||
hostmaster: root
|
||||
usenet: root
|
||||
news: root
|
||||
webmaster: root
|
||||
www: root
|
||||
ftp: root
|
||||
abuse: root
|
||||
noc: root
|
||||
security: root
|
||||
''
|
||||
+ cfg.extraAliases;
|
||||
};
|
||||
|
||||
services.rspamd = {
|
||||
enable = true;
|
||||
postfix.enable = true;
|
||||
workers = {
|
||||
normal = {
|
||||
includes = [ "$CONFDIR/worker-normal.inc" ];
|
||||
bindSockets = [
|
||||
{
|
||||
socket = "/run/rspamd/rspamd.sock";
|
||||
mode = "0660";
|
||||
owner = "${config.services.rspamd.user}";
|
||||
group = "${config.services.rspamd.group}";
|
||||
}
|
||||
];
|
||||
};
|
||||
controller = {
|
||||
includes = [ "$CONFDIR/worker-controller.inc" ];
|
||||
bindSockets = [ "127.0.0.1:${toString cfg.rspamd.port}" ];
|
||||
extraConfig = ''
|
||||
password=$2$w3asngzxwp3hoa67gimtrgmdxzmpq1n1$knfe5cyb1f769zro4rsi3j8ipc1p7ewh3u4cz63ngidmpjs8955y
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# ===== rspamd trainer ===== #
|
||||
services.rspamd-trainer = {
|
||||
enable = true;
|
||||
settings = {
|
||||
HOST = dovecotDomain;
|
||||
USERNAME = "spam@${cfg.domain}";
|
||||
INBOXPREFIX = "INBOX.";
|
||||
};
|
||||
secrets = [
|
||||
cfg.rspamd.trainerSecret
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.rspamd-trainer = lib.mkIf config.services.rspamd-trainer.enable {
|
||||
after = [
|
||||
"postfix.service"
|
||||
"dovecot.service"
|
||||
"rspamd-trainer-pre.service"
|
||||
];
|
||||
requires = [ "rspamd-trainer-pre.service" ];
|
||||
};
|
||||
|
||||
# ===== Create Mailbox for rspamd trainer ===== #
|
||||
systemd.services.rspamd-trainer-pre = lib.mkIf config.services.rspamd-trainer.enable {
|
||||
serviceConfig = {
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellScript "rspamd-trainer-pre.sh" ''
|
||||
set -euo pipefail
|
||||
|
||||
username=${config.services.rspamd-trainer.settings.USERNAME}
|
||||
domain="${cfg.domain}"
|
||||
mailbox_list=("report_spam" "report_ham" "report_spam_reply")
|
||||
for mailbox in ''\${mailbox_list[@]}; do
|
||||
echo "Creating $mailbox..."
|
||||
${pkgs.dovecot}/bin/doveadm mailbox create -u "$username@$domain" "INBOX.$mailbox" 2>/dev/null || true
|
||||
done
|
||||
'';
|
||||
in
|
||||
"${pkgs.bash}/bin/bash ${script}";
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
|
||||
# ===== Dovecot ===== #
|
||||
services.dovecot2 = {
|
||||
enable = lib.mkDefault true;
|
||||
enableImap = true;
|
||||
enablePop3 = true;
|
||||
enableLmtp = true;
|
||||
mailLocation = lib.mkDefault "maildir:${cfg.virtualMailDir}";
|
||||
mailUser = "vmail";
|
||||
mailGroup = "vmail";
|
||||
sslServerKey = cfg.sslKey;
|
||||
sslServerCert = cfg.sslCert;
|
||||
sslCACert = config.security.pki.caBundle;
|
||||
|
||||
extraConfig = ''
|
||||
log_path = /var/log/dovecot.log
|
||||
auth_debug = yes
|
||||
mail_debug = yes
|
||||
|
||||
auth_mechanisms = plain login
|
||||
ssl = yes
|
||||
ssl_dh_parameters_length = 2048
|
||||
ssl_cipher_list = ALL:!LOW:!SSLv2:!EXP:!aNULL
|
||||
ssl_prefer_server_ciphers = yes
|
||||
|
||||
service auth {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
|
||||
mode = 0660
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
}
|
||||
}
|
||||
|
||||
service lmtp {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/dovecot-lmtp {
|
||||
mode = 0600
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
}
|
||||
}
|
||||
|
||||
passdb ldap {
|
||||
driver = ldap
|
||||
args = ${ldapSecretConf}
|
||||
}
|
||||
|
||||
userdb {
|
||||
driver = static
|
||||
args = uid=${toString cfg.uid} gid=${toString cfg.gid} home=${cfg.virtualMailDir}/%d/%n/
|
||||
}
|
||||
|
||||
lda_mailbox_autosubscribe = yes
|
||||
lda_mailbox_autocreate = yes
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.dovecot2 = {
|
||||
systemd.services.dovecot = {
|
||||
requires = [ "acme-finished-${dovecotDomain}.target" ];
|
||||
serviceConfig = {
|
||||
RuntimeDirectory = [ "dovecot2-secret" ];
|
||||
RuntimeDirectory = [ "dovecot-secret" ];
|
||||
RuntimeDirectoryMode = "0640";
|
||||
ExecStartPre = [
|
||||
''${pkgs.busybox.out}/bin/mkdir -p ${cfg.virtualMailDir}''
|
||||
''${pkgs.busybox.out}/bin/chown -R vmail:vmail ${cfg.virtualMailDir}''
|
||||
''${pkgs.busybox.out}/bin/chmod 770 ${cfg.virtualMailDir}''
|
||||
''${pkgs.busybox.out}/bin/sh -c "${pkgs.busybox.out}/bin/cat ${ldapDefaultConf} ${cfg.dovecot.ldapFile} > ${ldapSecretConf}"''
|
||||
''${pkgs.bash}/bin/bash -c "LDAP_PASSWORD=$(cat ${cfg.ldap.passwordFile}) ${pkgs.gettext.out}/bin/envsubst < ${authBaseConf} > ${authConf}"''
|
||||
''${pkgs.busybox.out}/bin/chown ${config.services.dovecot.user}:${config.services.dovecot.group} ${authConf}''
|
||||
''${pkgs.busybox.out}/bin/chmod 660 ${authConf}''
|
||||
];
|
||||
|
||||
LoadCredential =
|
||||
let
|
||||
certDir = config.security.acme.certs."${dovecotDomain}".directory;
|
||||
in
|
||||
[
|
||||
"cert.pem:${certDir}/cert.pem"
|
||||
"key.pem:${certDir}/key.pem"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.dovecot =
|
||||
let
|
||||
credsDir = "/run/credentials/dovecot.service";
|
||||
certDir = "${credsDir}/cert.pem";
|
||||
keyDir = "${credsDir}/key.pem";
|
||||
in
|
||||
{
|
||||
enable = true;
|
||||
enablePAM = false;
|
||||
enableImap = true;
|
||||
enablePop3 = true;
|
||||
enableLmtp = true;
|
||||
enableHealthCheck = true;
|
||||
mailLocation = lib.mkDefault "${cfg.mailDir}";
|
||||
mailUser = "vmail";
|
||||
mailGroup = "vmail";
|
||||
sslServerKey = keyDir;
|
||||
sslServerCert = certDir;
|
||||
|
||||
mailboxes = {
|
||||
Junk = {
|
||||
specialUse = "Junk";
|
||||
auto = "subscribe";
|
||||
};
|
||||
Drafts = {
|
||||
specialUse = "Drafts";
|
||||
auto = "subscribe";
|
||||
};
|
||||
Archive = {
|
||||
specialUse = "Archive";
|
||||
auto = "subscribe";
|
||||
};
|
||||
Sent = {
|
||||
specialUse = "Sent";
|
||||
auto = "subscribe";
|
||||
};
|
||||
};
|
||||
|
||||
extraConfig = ''
|
||||
# authentication debug logging
|
||||
log_path = /dev/stderr
|
||||
log_debug = (category=auth-client) OR (event=auth_client_passdb_lookup_started)
|
||||
|
||||
auth_mechanisms = plain login oauthbearer
|
||||
ssl = required
|
||||
|
||||
service auth {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/auth {
|
||||
mode = 0660
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
type = postfix
|
||||
}
|
||||
}
|
||||
|
||||
service lmtp {
|
||||
unix_listener ${config.services.postfix.config.queue_directory}/private/dovecot-lmtp {
|
||||
mode = 0660
|
||||
user = ${config.services.postfix.user}
|
||||
group = ${config.services.postfix.group}
|
||||
type = postfix
|
||||
}
|
||||
}
|
||||
|
||||
userdb static {
|
||||
fields {
|
||||
uid = ${toString cfg.uid}
|
||||
gid = ${toString cfg.gid}
|
||||
home = ${cfg.virtualMailDir}/%{user | domain}/%{user | username}
|
||||
}
|
||||
}
|
||||
|
||||
lda_mailbox_autosubscribe = yes
|
||||
lda_mailbox_autocreate = yes
|
||||
|
||||
!include ${authConf}
|
||||
!include ${oauthConf}
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.dovecot-healthcheck = mkIf config.services.dovecot.enableHealthCheck (
|
||||
let
|
||||
pythonServer =
|
||||
pkgs.writeScript "dovecot-healthcheck"
|
||||
# python
|
||||
''
|
||||
#!${pkgs.python3}/bin/python3
|
||||
import socket
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
DOVECOT_HOST = '127.0.0.1'
|
||||
DOVECOT_PORT = ${toString config.services.dovecot.healthCheckPort}
|
||||
|
||||
class HealthCheckHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path != '/ping':
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
return
|
||||
try:
|
||||
with socket.create_connection((DOVECOT_HOST, DOVECOT_PORT), timeout=5) as sock:
|
||||
sock.sendall(b"PING\n")
|
||||
data = sock.recv(1024).strip()
|
||||
except Exception as e:
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Error connecting to healthcheck service")
|
||||
return
|
||||
|
||||
if data == b"PONG":
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"PONG")
|
||||
else:
|
||||
self.send_response(500)
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Unexpected response")
|
||||
|
||||
if __name__ == '__main__':
|
||||
server = HTTPServer(('0.0.0.0', 5002), HealthCheckHandler)
|
||||
print("HTTP healthcheck proxy running on port 5002")
|
||||
server.serve_forever()
|
||||
'';
|
||||
in
|
||||
{
|
||||
requires = [ "dovecot.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "dovecot.service" ];
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = pythonServer;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# ===== Firewall ===== #
|
||||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [
|
||||
80 # HTTP
|
||||
443 # HTTPS
|
||||
25 # SMTP
|
||||
465 # SMTPS
|
||||
587 # STARTTLS
|
||||
143 # IMAP STARTTLS
|
||||
993 # IMAPS
|
||||
110 # POP3 STARTTLS
|
||||
995 # POP3S
|
||||
389 # LDAP
|
||||
];
|
||||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [ "keycloak" ];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "keycloak";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
# ===== OAuth keycloak ===== #
|
||||
services.keycloak = {
|
||||
enable = true;
|
||||
|
||||
database = {
|
||||
type = "postgresql";
|
||||
host = "localhost";
|
||||
name = "keycloak";
|
||||
createLocally = false;
|
||||
passwordFile = cfg.oauth.passwordFile;
|
||||
};
|
||||
|
||||
settings = {
|
||||
hostname = "keycloak.${cfg.domain}";
|
||||
proxy-headers = "xforwarded";
|
||||
http-port = 38080;
|
||||
http-enabled = true;
|
||||
health-enabled = true;
|
||||
http-management-port = 38081;
|
||||
truststore-paths = cfg.caFile;
|
||||
};
|
||||
};
|
||||
|
||||
# ==== LDAP ===== #
|
||||
services.openldap = {
|
||||
enable = true;
|
||||
urlList = [ "ldap:///" ];
|
||||
|
||||
urlList = [ "ldap:///" ];
|
||||
settings = {
|
||||
attrs = {
|
||||
olcLogLevel = "conns config";
|
||||
|
|
@ -163,91 +460,127 @@ with lib;
|
|||
"${pkgs.openldap}/etc/schema/core.ldif"
|
||||
"${pkgs.openldap}/etc/schema/cosine.ldif"
|
||||
"${pkgs.openldap}/etc/schema/inetorgperson.ldif"
|
||||
"${pkgs.openldap}/etc/schema/nis.ldif"
|
||||
];
|
||||
|
||||
"olcDatabase={1}mdb".attrs = {
|
||||
objectClass = [
|
||||
"olcDatabaseConfig"
|
||||
"olcMdbConfig"
|
||||
];
|
||||
"olcDatabase={1}mdb" = {
|
||||
attrs = {
|
||||
objectClass = [
|
||||
"olcDatabaseConfig"
|
||||
"olcMdbConfig"
|
||||
];
|
||||
|
||||
olcDatabase = "{1}mdb";
|
||||
olcDbDirectory = "/var/lib/openldap/data";
|
||||
olcSuffix = "${ldapDomain}";
|
||||
olcDatabase = "{1}mdb";
|
||||
olcDbDirectory = "/var/lib/openldap/data";
|
||||
|
||||
olcRootDN = "cn=admin,${ldapDomain}";
|
||||
olcRootPW.path = cfg.openldap.passwordFile;
|
||||
olcSuffix = ldapDomain;
|
||||
|
||||
olcAccess = [
|
||||
''
|
||||
{0}to attrs=userPassword
|
||||
by dn="cn=admin,${ldapDomain}" read
|
||||
by self write
|
||||
by anonymous auth
|
||||
by * none
|
||||
''
|
||||
''
|
||||
{1}to *
|
||||
by * read
|
||||
''
|
||||
];
|
||||
olcRootDN = "cn=admin,${ldapDomain}";
|
||||
olcRootPW.path = cfg.ldap.passwordFile;
|
||||
|
||||
olcAccess = [
|
||||
''
|
||||
{0}to attrs=userPassword
|
||||
by dn.exact="cn=admin,${ldapDomain}" read
|
||||
by dn.exact="uid=admin@${cfg.domain},ou=people,${ldapDomain}" write
|
||||
by self write
|
||||
by anonymous auth
|
||||
by * none
|
||||
''
|
||||
''
|
||||
{1}to *
|
||||
by dn.exact="uid=admin@${cfg.domain},ou=people,${ldapDomain}" write
|
||||
by * read
|
||||
''
|
||||
];
|
||||
};
|
||||
|
||||
children = {
|
||||
"olcOverlay={2}ppolicy".attrs = {
|
||||
objectClass = [
|
||||
"olcOverlayConfig"
|
||||
"olcPPolicyConfig"
|
||||
"top"
|
||||
];
|
||||
olcOverlay = "{2}ppolicy";
|
||||
olcPPolicyHashCleartext = "TRUE";
|
||||
};
|
||||
|
||||
"olcOverlay={3}memberof".attrs = {
|
||||
objectClass = [
|
||||
"olcOverlayConfig"
|
||||
"olcMemberOf"
|
||||
"top"
|
||||
];
|
||||
olcOverlay = "{3}memberof";
|
||||
olcMemberOfRefInt = "TRUE";
|
||||
olcMemberOfDangling = "ignore";
|
||||
olcMemberOfGroupOC = "groupOfNames";
|
||||
olcMemberOfMemberAD = "member";
|
||||
olcMemberOfMemberOfAD = "memberOf";
|
||||
};
|
||||
|
||||
"olcOverlay={4}refint".attrs = {
|
||||
objectClass = [
|
||||
"olcOverlayConfig"
|
||||
"olcRefintConfig"
|
||||
"top"
|
||||
];
|
||||
olcOverlay = "{4}refint";
|
||||
olcRefintAttribute = "memberof member manager owner";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Openldap auto create baseDN
|
||||
environment.etc."openldap/base.ldif" = {
|
||||
mode = "0770";
|
||||
user = config.services.openldap.user;
|
||||
group = config.services.openldap.group;
|
||||
text = ''
|
||||
dn: ${ldapDomain}
|
||||
objectClass: top
|
||||
objectClass: domain
|
||||
dc: ${elemAt dcList 0}
|
||||
'';
|
||||
};
|
||||
|
||||
systemd.services.openldap-init-base = {
|
||||
wantedBy = [ "openldap.service" ];
|
||||
requires = [ "openldap.service" ];
|
||||
after = [ "openldap.service" ];
|
||||
serviceConfig = {
|
||||
User = config.services.openldap.user;
|
||||
Group = config.services.openldap.group;
|
||||
Type = "oneshot";
|
||||
ExecStart =
|
||||
let
|
||||
dcScript = pkgs.writeShellScriptBin "openldap-init" ''
|
||||
BASE_DN="${ldapDomain}"
|
||||
LDIF_FILE="/etc/openldap/base.ldif"
|
||||
ADMIN_DN="cn=admin,${ldapDomain}"
|
||||
${pkgs.openldap}/bin/ldapsearch -x -b "$BASE_DN" -s base "(objectclass=*)" > /dev/null 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Base DN $BASE_DN not exist, import $LDIF_FILE"
|
||||
${pkgs.openldap}/bin/ldapadd -x -D "$ADMIN_DN" -y ${cfg.openldap.passwordFile} -W -f "$LDIF_FILE"
|
||||
else
|
||||
echo "Base DN $BASE_DN exists, skip"
|
||||
fi
|
||||
'';
|
||||
in
|
||||
"${dcScript}/bin/openldap-init";
|
||||
# ==== postsrsd ==== #
|
||||
services.postsrsd = {
|
||||
enable = true;
|
||||
configurePostfix = true;
|
||||
secretsFile = config.sops.secrets."postsrsd/secret".path;
|
||||
settings = {
|
||||
srs-domain = cfg.domain;
|
||||
domains = [ cfg.domain ];
|
||||
};
|
||||
};
|
||||
|
||||
# ===== Firewall ===== #
|
||||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [
|
||||
25 # SMTP
|
||||
465 # SMTPS
|
||||
587 # STARTTLS
|
||||
143 # IMAP STARTTLS
|
||||
993 # IMAPS
|
||||
110 # POP3 STARTTLS
|
||||
995 # POP3S
|
||||
];
|
||||
virtualisation = {
|
||||
docker = {
|
||||
enable = true;
|
||||
rootless = {
|
||||
enable = true;
|
||||
setSocketVariable = true;
|
||||
};
|
||||
};
|
||||
oci-containers = {
|
||||
backend = "docker";
|
||||
containers = {
|
||||
phpLDAPadmin = {
|
||||
extraOptions = [ "--network=host" ];
|
||||
image = "phpldapadmin/phpldapadmin";
|
||||
volumes = [
|
||||
"/var/lib/pla/logs:/app/storage/logs"
|
||||
"/var/lib/pla/sessions:/app/storage/framework/sessions"
|
||||
];
|
||||
environment = {
|
||||
APP_URL = "https://ldap.${cfg.domain}";
|
||||
ASSET_URL = "https://ldap.${cfg.domain}";
|
||||
APP_TIMEZONE = "Asia/Taipei";
|
||||
LDAP_HOST = "127.0.0.1";
|
||||
SERVER_NAME = ":8080";
|
||||
LDAP_LOGIN_OBJECTCLASS = "inetOrgPerson";
|
||||
LDAP_BASE_DN = "${ldapDomain}";
|
||||
LDAP_LOGIN_ATTR = "dn";
|
||||
LDAP_LOGIN_ATTR_DESC = "Username";
|
||||
};
|
||||
environmentFiles = [
|
||||
cfg.ldap.webEnv
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# ===== Virtual Mail User ===== #
|
||||
users.groups.vmail = {
|
||||
|
|
@ -259,28 +592,36 @@ with lib;
|
|||
group = "vmail";
|
||||
};
|
||||
|
||||
virtualisation = mkIf cfg.openldap.enableWebUI {
|
||||
docker = {
|
||||
enable = lib.mkDefault true;
|
||||
rootless = {
|
||||
enable = true;
|
||||
setSocketVariable = true;
|
||||
};
|
||||
};
|
||||
services.nginx = {
|
||||
enable = mkDefault true;
|
||||
recommendedGzipSettings = mkDefault true;
|
||||
recommendedOptimisation = mkDefault true;
|
||||
recommendedTlsSettings = mkDefault true;
|
||||
recommendedProxySettings = mkDefault true;
|
||||
|
||||
oci-containers = {
|
||||
backend = "docker";
|
||||
containers = {
|
||||
lam = {
|
||||
image = "ghcr.io/ldapaccountmanager/lam:9.2";
|
||||
extraOptions = [ "--network=host" ];
|
||||
autoStart = true;
|
||||
environment = {
|
||||
LDAP_DOMAIN = cfg.domain;
|
||||
LDAP_SERVER = "ldap://${cfg.domain}";
|
||||
LDAP_USERS_DN = "ou=mail,${ldapDomain}";
|
||||
};
|
||||
};
|
||||
virtualHosts = {
|
||||
"${config.services.postfix.hostname}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/dovecot/ping".proxyPass = "http://localhost:${toString 5002}/ping";
|
||||
};
|
||||
"ldap.${cfg.domain}" = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass = "http://localhost:${toString 8080}/";
|
||||
};
|
||||
"rspamd.${cfg.domain}" = mkIf config.services.rspamd.enable {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass = "http://localhost:${toString cfg.rspamd.port}/";
|
||||
};
|
||||
"${config.services.keycloak.settings.hostname}" = mkIf config.services.keycloak.enable {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass =
|
||||
"http://localhost:${toString config.services.keycloak.settings.http-port}";
|
||||
locations."/health".proxyPass =
|
||||
"http://localhost:${toString config.services.keycloak.settings.http-management-port}/health";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,6 +11,14 @@
|
|||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
nextcloudPkg = pkgs.nextcloud31.overrideAttrs (oldAttr: rec {
|
||||
caBundle = config.security.pki.caBundle;
|
||||
postPatch = ''
|
||||
cp ${caBundle} resources/config/ca-bundle.crt
|
||||
'';
|
||||
});
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
"${
|
||||
|
|
@ -23,10 +31,6 @@
|
|||
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
authentication = lib.mkOverride 10 ''
|
||||
#type database DBuser origin-address auth-method
|
||||
local all all trust
|
||||
'';
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "nextcloud";
|
||||
|
|
@ -40,7 +44,7 @@
|
|||
|
||||
services.nextcloud = {
|
||||
enable = true;
|
||||
package = pkgs.nextcloud31;
|
||||
package = nextcloudPkg;
|
||||
configureRedis = true;
|
||||
hostName = hostname;
|
||||
https = if https then true else false;
|
||||
|
|
@ -50,8 +54,6 @@
|
|||
imagick
|
||||
];
|
||||
|
||||
maxUploadSize = "10240M";
|
||||
|
||||
extraApps = {
|
||||
inherit (config.services.nextcloud.package.packages.apps)
|
||||
contacts
|
||||
|
|
@ -64,6 +66,12 @@
|
|||
sha256 = "sha256-aiMUSJQVbr3xlJkqOaE3cNhdZu3CnPEIWTNVOoG4HSo=";
|
||||
license = "agpl3Plus";
|
||||
};
|
||||
|
||||
user_oidc = pkgs.fetchNextcloudApp {
|
||||
url = "https://github.com/nextcloud-releases/user_oidc/releases/download/v7.2.0/user_oidc-v7.2.0.tar.gz";
|
||||
sha256 = "sha256-nXDWfRP9n9eH+JGg1a++kD5uLMsXh5BHAaTAOgLI9W4=";
|
||||
license = "agpl3Plus";
|
||||
};
|
||||
};
|
||||
extraAppsEnable = true;
|
||||
|
||||
|
|
@ -74,7 +82,8 @@
|
|||
};
|
||||
|
||||
settings = {
|
||||
log_type = "file";
|
||||
allow_local_remote_servers = true;
|
||||
log_type = "syslog";
|
||||
enabledPreviewProviders = [
|
||||
"OC\\Preview\\BMP"
|
||||
"OC\\Preview\\GIF"
|
||||
|
|
@ -89,12 +98,15 @@
|
|||
"OC\\Preview\\HEIC"
|
||||
"OC\\Preview\\SVG"
|
||||
"OC\\Preview\\FONT"
|
||||
"OC\\Preview\\Imaginary"
|
||||
"OC\\Preview\\ImaginaryPDF"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts.${hostname} = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
};
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
exiftool
|
||||
];
|
||||
|
|
@ -115,59 +127,57 @@
|
|||
};
|
||||
};
|
||||
|
||||
services = lib.mkIf (dataBackupPath != null || dbBackupPath != null) {
|
||||
"nextcloud-backup" = {
|
||||
enable = true;
|
||||
serviceConfig = {
|
||||
User = "nextcloud";
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellScriptBin "backup" (
|
||||
''
|
||||
nextcloudPath="${config.services.nextcloud.datadir}"
|
||||
services."nextcloud-backup" = lib.mkIf (dataBackupPath != null || dbBackupPath != null) {
|
||||
enable = true;
|
||||
serviceConfig = {
|
||||
User = "nextcloud";
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeShellScriptBin "backup" (
|
||||
''
|
||||
nextcloudPath="${config.services.nextcloud.datadir}"
|
||||
|
||||
if [ ! -d "$nextcloudPath" ]; then
|
||||
echo "nextcloud path not found: $nextcloudPath"
|
||||
exit 1
|
||||
fi
|
||||
''
|
||||
+ (
|
||||
if dataBackupPath != null then
|
||||
''
|
||||
backupPath="${dataBackupPath}"
|
||||
nextcloudBakPath="$backupPath"
|
||||
if [ ! -d "$nextcloudPath" ]; then
|
||||
echo "nextcloud path not found: $nextcloudPath"
|
||||
exit 1
|
||||
fi
|
||||
''
|
||||
+ (
|
||||
if dataBackupPath != null then
|
||||
''
|
||||
backupPath="${dataBackupPath}"
|
||||
nextcloudBakPath="$backupPath"
|
||||
|
||||
if [ ! -d "$backupPath" ]; then
|
||||
echo "Backup device is not mounted: $backupPath"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$backupPath" ]; then
|
||||
echo "Backup device is not mounted: $backupPath"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Start syncing..."
|
||||
${pkgs.rsync}/bin/rsync -rh --delete "$nextcloudPath" "$nextcloudBakPath"
|
||||
echo "Data dir backup completed."
|
||||
''
|
||||
else
|
||||
""
|
||||
)
|
||||
+ (
|
||||
if dbBackupPath != null then
|
||||
''
|
||||
nextcloudDBBakPath="${dbBackupPath}/nextcloud-db.bak.tar"
|
||||
if [ ! -d "$nextcloudBakPath" ]; then
|
||||
mkdir -p "$nextcloudBakPath"
|
||||
fi
|
||||
echo "Start syncing..."
|
||||
${pkgs.rsync}/bin/rsync -rh --delete "$nextcloudPath" "$nextcloudBakPath"
|
||||
echo "Data dir backup completed."
|
||||
''
|
||||
else
|
||||
""
|
||||
)
|
||||
+ (
|
||||
if dbBackupPath != null then
|
||||
''
|
||||
nextcloudDBBakPath="${dbBackupPath}/nextcloud-db.bak.tar"
|
||||
if [ ! -d "$nextcloudBakPath" ]; then
|
||||
mkdir -p "$nextcloudBakPath"
|
||||
fi
|
||||
|
||||
echo "Try backing up database (postgresql)"
|
||||
${pkgs.postgresql}/bin/pg_dump -F t nextcloud -f "$nextcloudDBBakPath"
|
||||
echo "Database backup completed."
|
||||
''
|
||||
else
|
||||
""
|
||||
)
|
||||
);
|
||||
in
|
||||
"${script}/bin/backup";
|
||||
};
|
||||
echo "Try backing up database (postgresql)"
|
||||
${pkgs.postgresql}/bin/pg_dump -F t nextcloud -f "$nextcloudDBBakPath"
|
||||
echo "Database backup completed."
|
||||
''
|
||||
else
|
||||
""
|
||||
)
|
||||
);
|
||||
in
|
||||
"${script}/bin/backup";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
10
system/modules/postgresql.nix
Normal file
10
system/modules/postgresql.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
services.postgresql = {
|
||||
enable = lib.mkDefault true;
|
||||
authentication = ''
|
||||
#type database DBuser origin-address auth-method
|
||||
local all all trust
|
||||
'';
|
||||
};
|
||||
}
|
||||
53
system/modules/prometheus.nix
Normal file
53
system/modules/prometheus.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
fqdn,
|
||||
selfMonitor ? true,
|
||||
configureNginx ? true,
|
||||
scrapes ? [ ],
|
||||
}:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkIf optionalAttrs;
|
||||
inherit (builtins) toString;
|
||||
in
|
||||
{
|
||||
services.prometheus.exporters.node = mkIf selfMonitor {
|
||||
enable = true;
|
||||
port = 9000;
|
||||
enabledCollectors = [ "systemd" ];
|
||||
};
|
||||
|
||||
services.prometheus = {
|
||||
enable = true;
|
||||
webExternalUrl = "https://${fqdn}";
|
||||
globalConfig = {
|
||||
scrape_interval = "10s";
|
||||
};
|
||||
scrapeConfigs = (
|
||||
[
|
||||
{
|
||||
job_name = "master-server";
|
||||
static_configs = [
|
||||
(optionalAttrs selfMonitor {
|
||||
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
|
||||
})
|
||||
];
|
||||
}
|
||||
]
|
||||
++ scrapes
|
||||
);
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts."${fqdn}" = mkIf configureNginx {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
|
||||
locations."/" = {
|
||||
proxyPass = "http://localhost:${toString config.services.prometheus.port}";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
{ pkgs, ... }:
|
||||
let
|
||||
serverPkg = pkgs.tmodloader-server.overrideAttrs (
|
||||
final: prev: rec {
|
||||
version = "v2025.04.3.0";
|
||||
name = "tmodloader-${version}";
|
||||
url = "https://github.com/tModLoader/tModLoader/releases/download/${version}/tModLoader.zip";
|
||||
|
||||
src = pkgs.fetchurl {
|
||||
inherit url;
|
||||
hash = "sha256-cu98vb3T2iGC9W3e3nfls3mYTUQ4sviRHyViL0Qexn0=";
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
services.tmodloader = {
|
||||
enable = true;
|
||||
servers.pokemon = {
|
||||
enable = true;
|
||||
openFirewall = true;
|
||||
port = 7777;
|
||||
autoStart = true;
|
||||
package = serverPkg;
|
||||
world = "/var/lib/tmodloader/pokemon/Worlds/default.wld";
|
||||
autocreate = "large";
|
||||
install = [
|
||||
3039823461
|
||||
2619954303
|
||||
2563851005
|
||||
3378168037
|
||||
3173371762
|
||||
2800050107
|
||||
2785100219
|
||||
3018447913
|
||||
2565540604
|
||||
2563309347
|
||||
2908170107
|
||||
2669644269
|
||||
3439924021
|
||||
2599842771
|
||||
2797518634
|
||||
2565639705
|
||||
3497111954
|
||||
2563815443
|
||||
2707400823
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
dbBackend = "postgresql";
|
||||
environmentFile = config.sops.secrets.vaultwarden.path;
|
||||
config = {
|
||||
DOMAIN = domain;
|
||||
DOMAIN = "https://${domain}";
|
||||
SIGNUPS_ALLOWED = true;
|
||||
SIGNUPS_VERIFY = true;
|
||||
ROCKET_PORT = 8222;
|
||||
|
|
@ -29,4 +29,11 @@
|
|||
DATABASE_URL = "postgresql:///vaultwarden";
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts.${domain} = {
|
||||
enableACME = true;
|
||||
forceSSL = true;
|
||||
locations."/".proxyPass =
|
||||
"http://localhost:${toString config.services.vaultwarden.config.ROCKET_PORT}/";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue