Created
September 30, 2017 00:45
-
-
Save eqyiel/6d968649a9fe60e810e4d1ee71c133cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nix-repl> mkVal = with lib; let mkIndent = depth: concatStrings (builtins.genList (_: " ") (2 * depth)); in { value, depth ? 0 }: 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: "${attrName} = ${mkVal { value = attrValue; depth = depth + 1; }}") | |
value) ++ [ "\n${mkIndent depth}}\n" ])) | |
else value | |
nix-repl> mkRelation = name: value: "${name} = ${mkVal { inherit value; }}" | |
nix-repl> mkRelation "kek" realms | |
"kek = {\n HOSHIJIRO.MAHER.FYI = {\n admin_server = hoshijiro.maher.fyi\n extraConfig = default_principal_flags = +preauth\n\n kdc = hoshijiro.maher.fyi\n \n }\n\n \n}\n" | |
nix-repl> mkVal = with lib; let mkIndent = depth: concatStrings (builtins.genList (_: " ") (2 * depth)); in { value, depth ? 0 }: 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)}" | |
([ "HEY! {" ] ++ (mapAttrsToList | |
(attrName: attrValue: "${attrName} = ${mkVal { value = attrValue; depth = depth + 1; }}") | |
value) ++ [ "\n${mkIndent depth}}\n" ])) | |
else value | |
nix-repl> | |
nix-repl> mkRelation "kek" realms | |
"kek = {\n HOSHIJIRO.MAHER.FYI = {\n admin_server = hoshijiro.maher.fyi\n extraConfig = default_principal_flags = +preauth\n\n kdc = hoshijiro.maher.fyi\n \n }\n\n \n}\n" | |
nix-repl> mkRelation = name: value: "${name} = ${mkVal { inherit value; }}" | |
nix-repl> mkRelation "kek" realms | |
"kek = HEY! {\n HOSHIJIRO.MAHER.FYI = {\n admin_server = hoshijiro.maher.fyi\n extraConfig = default_principal_flags = +preauth\n\n kdc = hoshijiro.maher.fyi\n \n }\n\n \n}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment