Skip to content

Instantly share code, notes, and snippets.

@eqyiel
Created September 30, 2017 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eqyiel/6d968649a9fe60e810e4d1ee71c133cc to your computer and use it in GitHub Desktop.
Save eqyiel/6d968649a9fe60e810e4d1ee71c133cc to your computer and use it in GitHub Desktop.
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