1 { pkgs, config, lib, ... } :
4 inherit (lib) mapAttrs;
5 cfg = config.services.kerberos_server;
6 package = config.security.krb5.package;
8 aclConfigs = lib.pipe cfg.settings.realms [
9 (mapAttrs (name: { acl, ... }: lib.concatMapStringsSep "\n" (
10 { principal, access, target, ... }:
11 "${principal}\t${lib.concatStringsSep "," (lib.toList access)}\t${target}"
13 (lib.mapAttrsToList (name: text:
15 dbname = "/var/lib/heimdal/heimdal";
16 acl_file = pkgs.writeText "${name}.acl" text;
21 finalConfig = cfg.settings // {
22 realms = mapAttrs (_: v: removeAttrs v [ "acl" ]) (cfg.settings.realms or { });
23 kdc = (cfg.settings.kdc or { }) // {
24 database = aclConfigs;
28 format = import ../../../security/krb5/krb5-conf-format.nix { inherit pkgs lib; } { enableKdcACLEntries = true; };
30 kdcConfFile = format.generate "kdc.conf" finalConfig;
34 config = lib.mkIf (cfg.enable && package.passthru.implementation == "heimdal") {
35 environment.etc."heimdal-kdc/kdc.conf".source = kdcConfFile;
37 systemd.tmpfiles.settings."10-heimdal" = let
38 databases = lib.pipe finalConfig.kdc.database [
39 (map (dbAttrs: dbAttrs.dbname or null))
40 (lib.filter (x: x != null))
43 in lib.genAttrs databases (_: {
51 systemd.services.kadmind = {
52 description = "Kerberos Administration Daemon";
53 partOf = [ "kerberos-server.target" ];
54 wantedBy = [ "kerberos-server.target" ];
56 ExecStart = "${package}/libexec/kadmind --config-file=/etc/heimdal-kdc/kdc.conf";
57 Slice = "system-kerberos-server.slice";
58 StateDirectory = "heimdal";
60 restartTriggers = [ kdcConfFile ];
63 systemd.services.kdc = {
64 description = "Key Distribution Center daemon";
65 partOf = [ "kerberos-server.target" ];
66 wantedBy = [ "kerberos-server.target" ];
68 ExecStart = "${package}/libexec/kdc --config-file=/etc/heimdal-kdc/kdc.conf";
69 Slice = "system-kerberos-server.slice";
70 StateDirectory = "heimdal";
72 restartTriggers = [ kdcConfFile ];
75 systemd.services.kpasswdd = {
76 description = "Kerberos Password Changing daemon";
77 partOf = [ "kerberos-server.target" ];
78 wantedBy = [ "kerberos-server.target" ];
80 ExecStart = "${package}/libexec/kpasswdd";
81 Slice = "system-kerberos-server.slice";
82 StateDirectory = "heimdal";
84 restartTriggers = [ kdcConfFile ];