4 # - https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html
5 # - https://manpages.debian.org/unstable/heimdal-docs/krb5.conf.5heimdal.en.html
8 inherit (lib) boolToString concatMapStringsSep concatStringsSep filter
9 isAttrs isBool isList mapAttrsToList mkOption singleton splitString;
10 inherit (lib.types) attrsOf bool coercedTo either enum int listOf oneOf
14 enableKdcACLEntries ? false
18 (listOf (attrsOf value))
22 value = either (listOf atom) atom;
23 atom = oneOf [int str bool];
27 aclEntry = submodule {
29 principal = mkOption {
31 description = "Which principal the rule applies to";
35 (listOf (enum ["add" "cpw" "delete" "get" "list" "modify"]))
38 description = "The changes the principal is allowed to make.";
43 description = "The principals that 'access' applies to.";
48 realm = submodule ({ name, ... }: {
49 freeformType = sectionType;
52 type = listOf aclEntry;
54 { principal = "*/admin"; access = "all"; }
55 { principal = "admin"; access = "all"; }
58 The privileges granted to a user.
64 freeformType = attrsOf sectionType;
69 Files to include in the Kerberos configuration.
71 type = coercedTo path singleton (listOf path);
73 includedir = mkOption {
76 Directories containing files to include in the Kerberos configuration.
78 type = coercedTo path singleton (listOf path);
83 Modules to obtain Kerberos configuration from.
85 type = coercedTo path singleton (listOf path);
90 (lib.optionalAttrs enableKdcACLEntries {
94 The realm(s) to serve keys for.
101 indent = str: concatMapStringsSep "\n" (line: " " + line) (splitString "\n" str);
103 formatToplevel = args @ {
109 sections = removeAttrs args [ "include" "includedir" "module" ];
110 in concatStringsSep "\n" (filter (x: x != "") [
111 (concatStringsSep "\n" (mapAttrsToList formatSection sections))
112 (concatMapStringsSep "\n" (m: "module ${m}") module)
113 (concatMapStringsSep "\n" (i: "include ${i}") include)
114 (concatMapStringsSep "\n" (i: "includedir ${i}") includedir)
117 formatSection = name: section: ''
119 ${indent (concatStringsSep "\n" (mapAttrsToList formatRelation section))}
122 formatRelation = name: relation:
126 ${indent (concatStringsSep "\n" (mapAttrsToList formatValue relation))}
128 else if isList relation
130 concatMapStringsSep "\n" (formatRelation name) relation
131 else formatValue name relation;
133 formatValue = name: value:
135 then concatMapStringsSep "\n" (formatAtom name) value
136 else formatAtom name value;
138 formatAtom = name: atom: let
139 v = if isBool atom then boolToString atom else toString atom;
142 name: value: pkgs.writeText name ''
143 ${formatToplevel value}