aboutsummaryrefslogtreecommitdiff
path: root/tools/gridss-configFile.nix
blob: 838c29239f60ac7ac6d8a39f1b925638f2e938a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{bionix, nixpkgs}:

with nixpkgs;

let
    attrsToGridssConfigString = attrsToGridssConfigStringPrepend "";

    attrsToGridssConfigStringPrepend = prepend: attrs:
        lib.concatStringsSep "\n" (
            lib.attrValues (
                lib.mapAttrs
                    (name: attr: prepend + (iniLine name attr))
                    attrs));

    iniLine = name: attr:
        let attrType = builtins.typeOf attr;
        in
            if (iniLineByAttrType ? ${attrType})
            then (iniLineByAttrType.${attrType} name attr)
            else builtins.throw (
               "`gridssConfig` cannot convert attribute of type \"" + attrType + "\".");

    iniLineByAttrType = {
        string = name: attr: name + " = " + attr;
        int    = name: attr: name + " = " + builtins.toString attr;
        float  = name: attr: name + " = " + (
                    builtins.head (
                        builtins.match "([0-9]+\.0?[1-9]*)0+" (builtins.toString attr)));
        bool   = name: attr: name + " = " + (if attr == true then "true" else "false");
        attrs  = name: attr: attrsToGridssConfigStringPrepend (name + ".") attr;
        # Allows for repeated fields (e.g. for adapters):
        list   = name: attr: concatStringsSep "\n" (map (x: iniLine name x) attr);
    };
in configAttrs: (writeText
        "gridss.properties.override"
        (attrsToGridssConfigString configAttrs))