2023-10-28 13:05:30 +00:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
{
|
2024-08-24 14:21:48 +00:00
|
|
|
options.pub-solar-os.auth = with lib; {
|
|
|
|
enable = mkEnableOption "Enable keycloak to run on the node";
|
2024-05-08 17:47:47 +00:00
|
|
|
|
2024-08-24 14:21:48 +00:00
|
|
|
realm = mkOption {
|
2024-05-08 17:47:47 +00:00
|
|
|
description = "Name of the realm";
|
2024-08-24 14:21:48 +00:00
|
|
|
type = types.str;
|
2024-05-08 17:47:47 +00:00
|
|
|
default = config.pub-solar-os.networking.domain;
|
|
|
|
};
|
2023-10-28 13:05:30 +00:00
|
|
|
|
2024-08-24 14:21:48 +00:00
|
|
|
database-password-file = mkOption {
|
|
|
|
description = "Database password file path";
|
|
|
|
type = types.str;
|
2024-05-08 17:47:47 +00:00
|
|
|
};
|
2024-08-24 14:21:48 +00:00
|
|
|
};
|
2023-10-28 19:34:45 +00:00
|
|
|
|
2024-08-24 14:21:48 +00:00
|
|
|
config = lib.mkIf config.pub-solar-os.auth.enable {
|
2024-05-08 17:47:47 +00:00
|
|
|
services.nginx.virtualHosts."auth.${config.pub-solar-os.networking.domain}" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
2023-10-28 19:28:01 +00:00
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
locations = {
|
|
|
|
"= /" = {
|
|
|
|
extraConfig = ''
|
|
|
|
return 302 /realms/${config.pub-solar-os.auth.realm}/account;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
"/" = {
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_pass http://127.0.0.1:8080;
|
|
|
|
proxy_buffer_size 8k;
|
|
|
|
'';
|
|
|
|
};
|
2023-10-28 19:34:45 +00:00
|
|
|
};
|
2023-10-28 19:28:01 +00:00
|
|
|
};
|
2023-10-28 13:05:30 +00:00
|
|
|
|
2024-05-08 17:47:47 +00:00
|
|
|
# keycloak
|
|
|
|
services.keycloak = {
|
|
|
|
enable = true;
|
2024-08-24 14:21:48 +00:00
|
|
|
database.passwordFile = config.pub-solar-os.auth.database-password-file;
|
2024-05-08 17:47:47 +00:00
|
|
|
settings = {
|
|
|
|
hostname = "auth.${config.pub-solar-os.networking.domain}";
|
|
|
|
http-host = "127.0.0.1";
|
|
|
|
http-port = 8080;
|
|
|
|
proxy = "edge";
|
|
|
|
};
|
|
|
|
themes = {
|
|
|
|
"pub.solar" =
|
|
|
|
flake.inputs.keycloak-theme-pub-solar.legacyPackages.${pkgs.system}.keycloak-theme-pub-solar;
|
|
|
|
};
|
2023-10-28 13:05:30 +00:00
|
|
|
};
|
2023-11-05 21:54:09 +00:00
|
|
|
|
2024-08-24 14:21:48 +00:00
|
|
|
pub-solar-os.backups.backups.keycloak = {
|
2024-05-08 17:47:47 +00:00
|
|
|
paths = [ "/tmp/keycloak-backup.sql" ];
|
|
|
|
timerConfig = {
|
2024-05-15 19:00:41 +00:00
|
|
|
OnCalendar = "*-*-* 03:00:00 Etc/UTC";
|
2024-05-08 17:47:47 +00:00
|
|
|
};
|
|
|
|
initialize = true;
|
|
|
|
backupPrepareCommand = ''
|
|
|
|
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dump -d keycloak > /tmp/keycloak-backup.sql
|
|
|
|
'';
|
|
|
|
backupCleanupCommand = ''
|
|
|
|
rm /tmp/keycloak-backup.sql
|
|
|
|
'';
|
|
|
|
pruneOpts = [
|
|
|
|
"--keep-daily 7"
|
|
|
|
"--keep-weekly 4"
|
|
|
|
"--keep-monthly 3"
|
|
|
|
];
|
2023-11-18 21:28:12 +00:00
|
|
|
};
|
|
|
|
};
|
2023-10-28 13:05:30 +00:00
|
|
|
}
|