Home Explore Blog Models CI



nixpkgs

3rd chunk of `nixos/doc/manual/development/settings-options.section.md`
1e7e416b2871b5282f636f8a1cafae7f4dacbe177427e4790000000100000fcd
            failure to fetch the substitution value.

        `value`

        :   The name of the variable to use for
            substitution.

        See upstream documentation for semantics
        behind the substitution functionality.

        `Example usage:`

        ```nix
          let
            format = pkgs.formats.hocon { };
          in {
            a = 1;
            b = format.lib.mkSubstitution "a";
            c = format.lib.mkSubstitution "SOME_ENVVAR";
            d = format.lib.mkSubstitution {
              value = "SOME_OPTIONAL_ENVVAR";
              optional = true;
            };
          }
        ```

    `Implementation notes:`

    - classpath includes are not implemented in pyhocon,
      which is used for validating the HOCON output. This
      means that if you are using classpath includes,
      you will want to either use an alternative validator
      or set `doCheck = false` in the format options.

`pkgs.formats.libconfig` { *`generator`* ? `<derivation>`, *`validator`* ? `<derivation>` }

:  A function taking an attribute set with values

    `generator`

    :   A derivation used for converting the JSON output
        from the nix settings into libconfig. This might be
        useful if your libconfig variant is slightly different
        from the original one, or for testing purposes.

    `validator`

    :   A derivation used for verifying that the libconfig
        output is correct and parsable. This might be
        useful if your libconfig variant is slightly different
        from the original one, or for testing purposes.

    It returns an attrset with a `type`, `generate` function,
    and a `lib` attset, as specified [below](#pkgs-formats-result).
    Some of the lib functions will be best understood if you have
    read the reference specification. You can find this
    specification here:

    <https://hyperrealm.github.io/libconfig/libconfig_manual.html#Configuration-Files>

    Inside of `lib`, you will find these functions

    `mkHex`, `mkOctal`, `mkFloat`

    :   Use these to specify numbers in other formats.

        `Example usage:`

        ```nix
          let
            format = pkgs.formats.libconfig { };
          in {
            myHexValue = format.lib.mkHex "0x1FC3";
            myOctalValue = format.lib.mkOctal "0027";
            myFloatValue = format.lib.mkFloat "1.2E-3";
          }
        ```

    `mkArray`, `mkList`

    :   Use these to differentiate between whether
        a nix list should be considered as a libconfig
        array or a libconfig list. See the upstream
        documentation for the semantics behind these types.

        `Example usage:`

        ```nix
          let
            format = pkgs.formats.libconfig { };
          in {
            myList = format.lib.mkList [ "foo" 1 true ];
            myArray = format.lib.mkArray [ 1 2 3 ];
          }
        ```

    `Implementation notes:`

    - Since libconfig does not allow setting names to start with an underscore,
      this is used as a prefix for both special types and include directives.

    - The difference between 32bit and 64bit values became optional in libconfig
      1.5, so we assume 64bit values for all numbers.

`pkgs.formats.json` { }

:   A function taking an empty attribute set (for future extensibility)
    and returning a set with JSON-specific attributes `type` and
    `generate` as specified [below](#pkgs-formats-result).

`pkgs.formats.yaml` { }

:   A function taking an empty attribute set (for future extensibility)
    and returning a set with YAML-specific attributes `type` and
    `generate` as specified [below](#pkgs-formats-result).

`pkgs.formats.ini` { *`listsAsDuplicateKeys`* ? false, *`listToValue`* ? null, \.\.\. }

:   A function taking an attribute set with values

    `listsAsDuplicateKeys`

    :   A boolean for controlling whether list values can be used to
        represent duplicate INI keys

    `listToValue`

    :   A function for turning a list of values into a single value.

Title: Nix Formats: HOCON mkSubstitution, libconfig, JSON, YAML, and INI
Summary
This chunk begins with an example illustrating the usage of HOCON's `mkSubstitution` function, including how to define optional substitutions. It then provides implementation notes for HOCON, specifically mentioning that `classpath` includes are not supported by the `pyhocon` validator. The document then introduces `pkgs.formats.libconfig`, detailing its `generator` and `validator` options for custom behavior. It outlines `libconfig` specific `lib` functions like `mkHex`, `mkOctal`, `mkFloat` for number formatting, and `mkArray`, `mkList` for distinguishing list types, all with examples. Implementation notes for `libconfig` cover the use of underscores as prefixes and the assumption of 64-bit numbers. Finally, it briefly introduces `pkgs.formats.json`, `pkgs.formats.yaml`, and `pkgs.formats.ini`, with `ini` offering options for `listsAsDuplicateKeys` and `listToValue`.