Created
September 30, 2017 00:44
-
-
Save eqyiel/4204ddb6744a490727b4e3a72e4aae1f to your computer and use it in GitHub Desktop.
This file contains 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 "kek" realms | |
error: undefined variable ‘mkVal’ at (string):8:54 | |
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)}" | |
([ "{" ] ++ (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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment