2025-07-23 21:39:18 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2025-07-18 15:44:34 +00:00
|
|
|
with lib;
|
|
|
|
|
{
|
|
|
|
|
options.myModules.authentik.enable = mkEnableOption "custom authentik configuration";
|
|
|
|
|
|
|
|
|
|
config = mkIf config.myModules.authentik.enable {
|
2025-09-09 13:01:14 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
|
pkgs.authentik
|
|
|
|
|
];
|
|
|
|
|
services.authentik = {
|
|
|
|
|
enable = true;
|
|
|
|
|
environmentFile = "/run/secrets/authentik-env";
|
|
|
|
|
settings = {
|
|
|
|
|
database = {
|
|
|
|
|
host = "127.0.0.1";
|
|
|
|
|
name = "authentik";
|
|
|
|
|
};
|
|
|
|
|
email = {
|
|
|
|
|
host = "smtp.forwardemail.net";
|
|
|
|
|
port = 2465;
|
|
|
|
|
use_tls = false;
|
|
|
|
|
use_ssl = true;
|
|
|
|
|
from = "auth@corp.gleipnir.technology";
|
|
|
|
|
};
|
|
|
|
|
listen = {
|
2026-01-13 14:58:11 +00:00
|
|
|
debug = "127.0.0.1:9900";
|
|
|
|
|
debug_py = "127.0.0.1:9901";
|
|
|
|
|
http = "127.0.0.1:10030";
|
|
|
|
|
https = "127.0.0.1:10031";
|
|
|
|
|
ldap = "127.0.0.1:3389";
|
|
|
|
|
ldaps = "127.0.0.1:6636";
|
|
|
|
|
radius = "127.0.0.1:1812";
|
|
|
|
|
metrics = "127.0.0.1:9300";
|
2025-09-09 13:01:14 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-07-18 22:45:02 +00:00
|
|
|
services.caddy.virtualHosts."auth.gleipnir.technology".extraConfig = ''
|
2025-10-01 19:25:29 +00:00
|
|
|
reverse_proxy http://127.0.0.1:10030
|
2025-07-18 22:45:02 +00:00
|
|
|
'';
|
2025-09-09 13:01:14 +00:00
|
|
|
services.postgresql = {
|
|
|
|
|
ensureDatabases = [ "authentik" ];
|
|
|
|
|
ensureUsers = [{
|
|
|
|
|
ensureClauses.login = true;
|
|
|
|
|
ensureDBOwnership = true;
|
|
|
|
|
name = "authentik";
|
|
|
|
|
}];
|
|
|
|
|
};
|
2026-01-12 00:48:54 +00:00
|
|
|
services.restic.backups."authentik-db" = {
|
|
|
|
|
# We can use this due to overridding restic with unstable
|
|
|
|
|
command = [
|
|
|
|
|
"${lib.getExe pkgs.sudo}"
|
|
|
|
|
"-u postgres"
|
|
|
|
|
"${pkgs.postgresql}/bin/pg_dump authentik"
|
|
|
|
|
];
|
|
|
|
|
environmentFile = "/var/run/secrets/restic-env";
|
|
|
|
|
extraBackupArgs = [
|
|
|
|
|
"--tag database"
|
|
|
|
|
];
|
|
|
|
|
passwordFile = "/var/run/secrets/restic-password";
|
|
|
|
|
pruneOpts = [
|
|
|
|
|
"--keep-daily 14"
|
|
|
|
|
"--keep-weekly 4"
|
|
|
|
|
"--keep-monthly 2"
|
|
|
|
|
"--group-by tags"
|
|
|
|
|
];
|
|
|
|
|
repository = "s3:s3.us-west-004.backblazeb2.com/gleipnir-backup-corp/authentik";
|
|
|
|
|
};
|
|
|
|
|
services.restic.backups."authentik-files" = {
|
|
|
|
|
environmentFile = "/var/run/secrets/restic-env";
|
|
|
|
|
extraBackupArgs = [
|
|
|
|
|
"--tag files"
|
|
|
|
|
];
|
|
|
|
|
initialize = true;
|
|
|
|
|
passwordFile = "/var/run/secrets/restic-password";
|
|
|
|
|
paths = [
|
|
|
|
|
"/opt/authentik/certs"
|
|
|
|
|
"/opt/authentik/media"
|
|
|
|
|
"/opt/authentik/templates"
|
|
|
|
|
];
|
|
|
|
|
repository = "s3:s3.us-west-004.backblazeb2.com/gleipnir-backup-corp/authentik";
|
|
|
|
|
};
|
2025-07-18 17:10:24 +00:00
|
|
|
sops.secrets.authentik-env = with config.virtualisation.oci-containers; {
|
|
|
|
|
format = "dotenv";
|
2025-07-18 15:44:34 +00:00
|
|
|
group = "authentik";
|
|
|
|
|
mode = "0440";
|
|
|
|
|
owner = "authentik";
|
2025-09-09 13:01:14 +00:00
|
|
|
restartUnits = ["authentik" "authentik-migrate" "authentik-worker"];
|
2025-07-18 17:00:35 +00:00
|
|
|
sopsFile = ../../secrets/authentik.env;
|
2025-07-18 15:44:34 +00:00
|
|
|
};
|
2025-07-18 16:52:52 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
|
"d /opt/authentik/certs 0755 authentik authentik"
|
|
|
|
|
"d /opt/authentik/media 0755 authentik authentik"
|
|
|
|
|
"d /opt/authentik/templates 0755 authentik authentik"
|
|
|
|
|
];
|
2025-07-18 15:44:34 +00:00
|
|
|
users.groups.authentik = {};
|
|
|
|
|
users.users.authentik = {
|
|
|
|
|
group = "authentik";
|
|
|
|
|
isNormalUser = false;
|
|
|
|
|
isSystemUser = true;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|