1 { pkgs, config, lib, ... } :
4 inherit (lib) mapAttrs;
5 cfg = config.services.kerberos_server;
6 package = config.security.krb5.package;
7 PIDFile = "/run/kdc.pid";
9 format = import ../../../security/krb5/krb5-conf-format.nix { inherit pkgs lib; } { enableKdcACLEntries = true; };
12 add = "a"; cpw = "c"; delete = "d"; get = "i"; list = "l"; modify = "m";
16 aclConfigs = lib.pipe cfg.settings.realms [
17 (mapAttrs (name: { acl, ... }: lib.concatMapStringsSep "\n" (
18 { principal, access, target, ... }: let
19 access_code = map (a: aclMap.${a}) (lib.toList access);
20 in "${principal} ${lib.concatStrings access_code} ${target}"
23 (lib.concatMapAttrs (name: text: {
25 acl_file = pkgs.writeText "${name}.acl" text;
30 finalConfig = cfg.settings // {
31 realms = mapAttrs (n: v: (removeAttrs v [ "acl" ]) // aclConfigs.${n}) (cfg.settings.realms or { });
34 kdcConfFile = format.generate "kdc.conf" finalConfig;
36 # What Debian uses, could possibly link directly to Nix store?
37 KRB5_KDC_PROFILE = "/etc/krb5kdc/kdc.conf";
42 config = lib.mkIf (cfg.enable && package.passthru.implementation == "krb5") {
44 etc."krb5kdc/kdc.conf".source = kdcConfFile;
48 systemd.services.kadmind = {
49 description = "Kerberos Administration Daemon";
50 partOf = [ "kerberos-server.target" ];
51 wantedBy = [ "kerberos-server.target" ];
53 ExecStart = "${package}/bin/kadmind -nofork";
54 Slice = "system-kerberos-server.slice";
55 StateDirectory = "krb5kdc";
57 restartTriggers = [ kdcConfFile ];
61 systemd.services.kdc = {
62 description = "Key Distribution Center daemon";
63 partOf = [ "kerberos-server.target" ];
64 wantedBy = [ "kerberos-server.target" ];
68 ExecStart = "${package}/bin/krb5kdc -P ${PIDFile}";
69 Slice = "system-kerberos-server.slice";
70 StateDirectory = "krb5kdc";
72 restartTriggers = [ kdcConfFile ];