2023-07-17 09:01:45 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.shb.ldap;
|
|
|
|
|
|
|
|
fqdn = "${cfg.subdomain}.${cfg.domain}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.shb.ldap = {
|
2023-12-01 07:08:38 +01:00
|
|
|
enable = lib.mkEnableOption "the LDAP service";
|
2023-07-17 09:01:45 +02:00
|
|
|
|
|
|
|
dcdomain = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-12-01 07:08:38 +01:00
|
|
|
description = "dc domain to serve.";
|
2023-07-17 09:01:45 +02:00
|
|
|
example = "dc=mydomain,dc=com";
|
|
|
|
};
|
|
|
|
|
|
|
|
subdomain = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-12-01 07:08:38 +01:00
|
|
|
description = "Subdomain under which the LDAP service will be served.";
|
2023-07-17 09:01:45 +02:00
|
|
|
example = "grafana";
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-12-01 07:08:38 +01:00
|
|
|
description = "Domain under which the LDAP service will be served.";
|
2023-07-17 09:01:45 +02:00
|
|
|
example = "mydomain.com";
|
|
|
|
};
|
|
|
|
|
2023-10-17 22:41:33 +02:00
|
|
|
ldapPort = lib.mkOption {
|
2023-10-15 06:17:59 +02:00
|
|
|
type = lib.types.port;
|
|
|
|
description = "Port on which the server listens for the LDAP protocol.";
|
|
|
|
default = 3890;
|
|
|
|
};
|
|
|
|
|
2023-12-01 07:08:38 +01:00
|
|
|
webUIListenPort = lib.mkOption {
|
2023-10-15 06:17:59 +02:00
|
|
|
type = lib.types.port;
|
|
|
|
description = "Port on which the web UI is exposed.";
|
|
|
|
default = 17170;
|
|
|
|
};
|
|
|
|
|
2023-12-01 07:08:38 +01:00
|
|
|
ldapUserPasswordFile = lib.mkOption {
|
2023-07-17 09:01:45 +02:00
|
|
|
type = lib.types.path;
|
2023-12-01 07:08:38 +01:00
|
|
|
description = "File containing the LDAP admin user password.";
|
2023-07-17 09:01:45 +02:00
|
|
|
};
|
2023-07-31 02:44:50 +02:00
|
|
|
|
2023-12-01 07:08:38 +01:00
|
|
|
jwtSecretFile = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
|
|
|
description = "File containing the JWT secret.";
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictAccessIPRange = lib.mkOption {
|
2023-11-18 07:52:29 +01:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
2023-12-01 07:08:38 +01:00
|
|
|
description = "Set a local network range to restrict access to the UI to only those IPs.";
|
2023-07-31 02:44:50 +02:00
|
|
|
example = "192.168.1.1/24";
|
2023-11-18 07:52:29 +01:00
|
|
|
default = null;
|
2023-07-31 02:44:50 +02:00
|
|
|
};
|
2023-12-01 07:08:38 +01:00
|
|
|
|
|
|
|
debug = lib.mkOption {
|
|
|
|
description = "Enable debug logging.";
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2023-07-17 09:01:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
virtualHosts.${fqdn} = {
|
2023-11-18 07:51:35 +01:00
|
|
|
forceSSL = lib.mkIf config.shb.ssl.enable true;
|
|
|
|
sslCertificate = lib.mkIf config.shb.ssl.enable "/var/lib/acme/${cfg.domain}/cert.pem";
|
|
|
|
sslCertificateKey = lib.mkIf config.shb.ssl.enable "/var/lib/acme/${cfg.domain}/key.pem";
|
2023-07-17 09:01:45 +02:00
|
|
|
locations."/" = {
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header Host $host;
|
2023-12-01 07:08:38 +01:00
|
|
|
'' + (if isNull cfg.restrictAccessIPRange then "" else ''
|
|
|
|
allow ${cfg.restrictAccessIPRange};
|
2023-07-31 02:44:50 +02:00
|
|
|
deny all;
|
2023-11-18 07:52:29 +01:00
|
|
|
'');
|
2023-07-17 09:01:45 +02:00
|
|
|
proxyPass = "http://${toString config.services.lldap.settings.http_host}:${toString config.services.lldap.settings.http_port}/";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.lldap = {
|
|
|
|
name = "lldap";
|
|
|
|
group = "lldap";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.lldap = {
|
|
|
|
members = [ "backup" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.lldap = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
environment = {
|
2023-12-01 07:08:38 +01:00
|
|
|
LLDAP_JWT_SECRET_FILE = toString cfg.jwtSecretFile;
|
|
|
|
LLDAP_LDAP_USER_PASS_FILE = toString cfg.ldapUserPasswordFile;
|
2023-07-20 08:19:08 +02:00
|
|
|
|
2023-12-01 07:08:38 +01:00
|
|
|
RUST_LOG = lib.mkIf cfg.debug "debug";
|
2023-07-17 09:01:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = {
|
|
|
|
http_url = "https://${fqdn}";
|
|
|
|
http_host = "127.0.0.1";
|
2023-12-01 07:08:38 +01:00
|
|
|
http_port = cfg.webUIListenPort;
|
2023-07-17 09:01:45 +02:00
|
|
|
|
|
|
|
ldap_host = "127.0.0.1";
|
2023-10-17 22:41:33 +02:00
|
|
|
ldap_port = cfg.ldapPort;
|
2023-07-17 09:01:45 +02:00
|
|
|
|
|
|
|
ldap_base_dn = cfg.dcdomain;
|
2023-07-20 08:19:08 +02:00
|
|
|
|
2023-12-01 07:08:38 +01:00
|
|
|
verbose = cfg.debug;
|
2023-07-17 09:01:45 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
shb.backup.instances.lldap = {
|
|
|
|
sourceDirectories = [
|
|
|
|
"/var/lib/lldap"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|