Unverified Commit 6b53949b authored by Johannes Kirschbauer's avatar Johannes Kirschbauer
Browse files

formats.ini: expose INI atom from all ini formats

parent b35c45a2
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -312,6 +312,8 @@ have a predefined type and string generator already declared under
    may be transformed into multiple key-value pairs depending on
    `listToValue`).

    The attribute `lib.type.atom` contains the used INI atom.

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

:   A function taking an attribute set with values
@@ -333,6 +335,8 @@ have a predefined type and string generator already declared under
    attrset of key-value pairs for a single section, the global section which
    preceedes the section definitions.

    The attribute `lib.type.atom` contains the used INI atom.

`pkgs.formats.toml` { }

:   A function taking an empty attribute set (for future extensibility)
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ let
  stateDir = "/var/lib/public-inbox";

  gitIni = pkgs.formats.gitIni { listsAsDuplicateKeys = true; };
  iniAtom = elemAt gitIni.type/*attrsOf*/.functor.wrapped/*attrsOf*/.functor.wrapped/*either*/.functor.wrapped 0;
  iniAtom = gitIni.lib.types.atom;

  useSpamAssassin = cfg.settings.publicinboxmda.spamcheck == "spamc" ||
                    cfg.settings.publicinboxwatch.spamcheck == "spamc";
+19 −13
Original line number Diff line number Diff line
@@ -123,9 +123,9 @@ rec {
          }
        else
          singleIniAtom;
      iniSection = { listsAsDuplicateKeys, listToValue, atomsCoercedToLists }@args:
        attrsOf (iniAtom args) // {
          description = "section of an INI file (attrs of " + (iniAtom args).description + ")";
      iniSection = atom:
        attrsOf atom // {
          description = "section of an INI file (attrs of " + atom.description + ")";
        };

      maybeToList = listToValue: if listToValue != null then lib.mapAttrs (key: val: if lib.isList val then listToValue val else val) else lib.id;
@@ -144,12 +144,14 @@ rec {
        assert atomsCoercedToLists != null -> (listsAsDuplicateKeys || listToValue != null);
        let
          atomsCoercedToLists' = if atomsCoercedToLists == null then false else atomsCoercedToLists;
          atom = iniAtom { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; };
        in
        {

        type = lib.types.attrsOf (
          iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; }
          iniSection atom
        );
        lib.types.atom = atom;

        generate = name: value:
          lib.pipe value
@@ -174,24 +176,26 @@ rec {
        assert atomsCoercedToLists != null -> (listsAsDuplicateKeys || listToValue != null);
        let
          atomsCoercedToLists' = if atomsCoercedToLists == null then false else atomsCoercedToLists;
          atom = iniAtom { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; };
        in
        {
          type = lib.types.submodule {
            options = {
              sections = lib.mkOption rec {
                type = lib.types.attrsOf (
                  iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; }
                  iniSection atom
                );
                default = {};
                description = type.description;
              };
              globalSection = lib.mkOption rec {
                type = iniSection { inherit listsAsDuplicateKeys listToValue; atomsCoercedToLists = atomsCoercedToLists'; };
                type = iniSection atom;
                default = {};
                description = "global " + type.description;
              };
            };
          };
          lib.types.atom = atom;
          generate = name: { sections ? {}, globalSection ? {}, ... }:
            pkgs.writeText name (lib.generators.toINIWithGlobalSection (removeAttrs args ["listToValue" "atomsCoercedToLists"])
            {
@@ -200,15 +204,17 @@ rec {
            });
        };

      gitIni = { listsAsDuplicateKeys ? false, ... }@args: {
        type = let
      gitIni = { listsAsDuplicateKeys ? false, ... }@args:
        let
          atom = iniAtom {
            listsAsDuplicateKeys = listsAsDuplicateKeys;
            inherit listsAsDuplicateKeys;
            listToValue = null;
            atomsCoercedToLists = false;
          };
        in attrsOf (attrsOf (either atom (attrsOf atom)));

        in
        {
          type = attrsOf (attrsOf (either atom (attrsOf atom)));
          lib.types.atom = atom;
          generate = name: value: pkgs.writeText name (lib.generators.toGitINI value);
        };