Skip to content

Commit

Permalink
Merge pull request #89748 from heinic/krb5-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Sep 3, 2020
2 parents 742c734 + 0bee87c commit 02a2649
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
34 changes: 18 additions & 16 deletions nixos/modules/config/krb5/default.nix
Expand Up @@ -41,31 +41,30 @@ let
value)
else value;

mkIndent = depth: concatStrings (builtins.genList (_: " ") (2 * depth));
indent = " ";

mkRelation = name: value: "${name} = ${mkVal { inherit value; }}";
mkRelation = name: value:
if (isList value) then
concatMapStringsSep "\n" (mkRelation name) value
else "${name} = ${mkVal value}";

mkVal = { value, depth ? 0 }:
mkVal = value:
if (value == true) then "true"
else if (value == false) then "false"
else if (isInt value) then (toString value)
else if (isList value) then
concatMapStringsSep " " mkVal { inherit value depth; }
else if (isAttrs value) then
(concatStringsSep "\n${mkIndent (depth + 1)}"
([ "{" ] ++ (mapAttrsToList
(attrName: attrValue: let
mappedAttrValue = mkVal {
value = attrValue;
depth = depth + 1;
};
in "${attrName} = ${mappedAttrValue}")
value))) + "\n${mkIndent depth}}"
let configLines = concatLists
(map (splitString "\n")
(mapAttrsToList mkRelation value));
in
(concatStringsSep "\n${indent}"
([ "{" ] ++ configLines))
+ "\n}"
else value;

mkMappedAttrsOrString = value: concatMapStringsSep "\n"
(line: if builtins.stringLength line > 0
then "${mkIndent 1}${line}"
then "${indent}${line}"
else line)
(splitString "\n"
(if isAttrs value then
Expand Down Expand Up @@ -114,7 +113,10 @@ in {
{
"ATHENA.MIT.EDU" = {
admin_server = "athena.mit.edu";
kdc = "athena.mit.edu";
kdc = [
"athena01.mit.edu"
"athena02.mit.edu"
];
};
};
'';
Expand Down
8 changes: 6 additions & 2 deletions nixos/tests/krb5/example-config.nix
Expand Up @@ -18,7 +18,10 @@ import ../make-test-python.nix ({ pkgs, ...} : {
realms = {
"ATHENA.MIT.EDU" = {
admin_server = "athena.mit.edu";
kdc = "athena.mit.edu";
kdc = [
"athena01.mit.edu"
"athena02.mit.edu"
];
};
};
domain_realm = {
Expand Down Expand Up @@ -65,7 +68,8 @@ import ../make-test-python.nix ({ pkgs, ...} : {
[realms]
ATHENA.MIT.EDU = {
admin_server = athena.mit.edu
kdc = athena.mit.edu
kdc = athena01.mit.edu
kdc = athena02.mit.edu
}
[domain_realm]
Expand Down

0 comments on commit 02a2649

Please sign in to comment.