nixos-config/modules/server/keycloak.nix

52 lines
1.1 KiB
Nix
Raw Normal View History

2024-12-10 20:04:20 +01:00
{
lib,
config,
extraInfo,
...
}:
let
cfg = config.my.server.sso;
in
with lib;
{
options = {
my.server.sso = {
enable = mkEnableOption "SSO using Keycloak";
dbPasswordFile = mkOption {
type = types.str;
description = "Path to the file containing the database password";
};
};
};
config = mkIf cfg.enable {
services.keycloak = {
enable = true;
database = {
type = "postgresql";
createLocally = true;
passwordFile = cfg.dbPasswordFile;
};
settings = {
hostname = "https://${extraInfo.keycloakURI}";
hostname-admin-url = "https://${extraInfo.keycloakURI}";
http-port = 8081;
proxy-headers = "forwarded";
http-enabled = true;
};
};
services.nginx.virtualHosts.${extraInfo.keycloakURI} = mkIf config.services.nginx.enable {
forceSSL = true;
enableACME = true;
locations."/" = {
recommendedProxySettings = true;
proxyPass = "http://localhost:${toString config.services.keycloak.settings.http-port}";
};
};
};
}