Home Explore Blog Models CI



nixpkgs

5th chunk of `nixos/doc/manual/development/settings-options.section.md`
2446273bd5e67c58a2a7b7ea89449232fec38361b12449bf0000000100000dc8
    :   Input format. Because XML can not be translated one-to-one, we have to use intermediate formats. Possible values:
      - `"badgerfish"`: Uses [badgerfish](http://www.sklar.com/badgerfish/) conversion.

    `withHeader`

    :   Outputs the xml with header.

`pkgs.formats.cdn` { }

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

`pkgs.formats.elixirConf { elixir ? pkgs.elixir }`

:   A function taking an attribute set with values

    `elixir`

    :   The Elixir package which will be used to format the generated output

    It returns a set with Elixir-Config-specific attributes `type`, `lib`, and
    `generate` as specified [below](#pkgs-formats-result).

    The `lib` attribute contains functions to be used in settings, for
    generating special Elixir values:

    `mkRaw elixirCode`

    :   Outputs the given string as raw Elixir code

    `mkGetEnv { envVariable, fallback ? null }`

    :   Makes the configuration fetch an environment variable at runtime

    `mkAtom atom`

    :   Outputs the given string as an Elixir atom, instead of the default
        Elixir binary string. Note: lowercase atoms still needs to be prefixed
        with `:`

    `mkTuple array`

    :   Outputs the given array as an Elixir tuple, instead of the default
        Elixir list

    `mkMap attrset`

    :   Outputs the given attribute set as an Elixir map, instead of the
        default Elixir keyword list

`pkgs.formats.lua { asBindings ? false, multiline ? true, columnWidth ? 100, indentWidth ? 2, indentUsingTabs ? false }`

:   A function taking an attribute set with values

    `asBindings` (default `false`)

    :   Whether to treat attributes as variable bindings

    `multiline` (default `true`)

    :   Whether to produce a multiline output. The output may still wrap across
        multiple lines if it would otherwise exceed `columnWidth`.

    `columnWidth` (default `100`)

    :   The column width to use to attempt to wrap lines.

    `indentWidth` (default `2`)

    :   The width of a single indentation level.

    `indentUsingTabs` (default `false`)

    :   Whether the indentation should use tabs instead of spaces.

`pkgs.formats.php { finalVariable }` []{#pkgs-formats-php}

:   A function taking an attribute set with values

    `finalVariable`

    :   The variable that will store generated expression (usually `config`). If set to `null`, generated expression will contain `return`.

    It returns a set with PHP-Config-specific attributes `type`, `lib`, and
    `generate` as specified [below](#pkgs-formats-result).

    The `lib` attribute contains functions to be used in settings, for
    generating special PHP values:

    `mkRaw phpCode`

    :   Outputs the given string as raw PHP code

    `mkMixedArray list set`

    :   Creates PHP array that contains both indexed and associative values. For example, `lib.mkMixedArray [ "hello" "world" ] { "nix" = "is-great"; }` returns `['hello', 'world', 'nix' => 'is-great']`

[]{#pkgs-formats-result}
These functions all return an attribute set with these values:

`type`

:   A module system type representing a value of the format

`lib`

:   Utility functions for convenience, or special interactions with the format.
    This attribute is optional. It may contain inside a `types` attribute
    containing types specific to this format.

Title: Nix Formats: CDN, ElixirConf, Lua, and PHP with Utility Functions
Summary
This document continues the description of Nix `pkgs.formats` for various configuration types. It introduces `pkgs.formats.cdn` as a simple function for CDN-specific attributes. `pkgs.formats.elixirConf` takes an `elixir` package and returns `type`, `lib`, and `generate` attributes; the `lib` provides utilities like `mkRaw`, `mkGetEnv`, `mkAtom`, `mkTuple`, and `mkMap` for generating specific Elixir values. `pkgs.formats.lua` offers fine-grained control over output with options such as `asBindings`, `multiline`, `columnWidth`, `indentWidth`, and `indentUsingTabs`. `pkgs.formats.php` requires a `finalVariable` and also includes a `lib` attribute with `mkRaw` and `mkMixedArray` for handling mixed indexed and associative arrays in PHP. Finally, it specifies that all these `pkgs.formats` functions consistently return an attribute set containing a `type` (representing the format's value in the module system) and an optional `lib` attribute for format-specific utility functions.