summary refs log tree commit diff
path: root/nixos/modules/config
diff options
context:
space:
mode:
authorNico Heitmann <nico.heitmann01@gmx.de>2020-06-07 16:07:47 +0200
committerNico Heitmann <nico.heitmann01@gmx.de>2020-06-07 16:40:40 +0200
commit5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845 (patch)
tree716ba681cec17b2aaa7950647abc0a2879a06aaf /nixos/modules/config
parent0710b5afecd55b059212d7d127a0b7625846661e (diff)
downloadnixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar.gz
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar.bz2
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar.lz
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar.xz
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.tar.zst
nixpkgs-5ed0924e7b445df9b684e6e5c63e0a7eeaf2f845.zip
nixos/krb5: refactor indentation generation
mkVal is no longer aware of the indentation depth. Indentation is
added to each line of the result when it is included in nested
entries.
Diffstat (limited to 'nixos/modules/config')
-rw-r--r--nixos/modules/config/krb5/default.nix26
1 files changed, 12 insertions, 14 deletions
diff --git a/nixos/modules/config/krb5/default.nix b/nixos/modules/config/krb5/default.nix
index ff16ffcf9c6..85ecb8633a3 100644
--- a/nixos/modules/config/krb5/default.nix
+++ b/nixos/modules/config/krb5/default.nix
@@ -41,31 +41,29 @@ let
         value)
     else value;
 
-  mkIndent = depth: concatStrings (builtins.genList (_:  " ") (2 * depth));
+  indent = "  ";
 
-  mkRelation = name: value: "${name} = ${mkVal { inherit value; }}";
+  mkRelation = name: value: "${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; }
+      concatMapStringsSep " " mkVal value
     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