{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://omaflake.dev/schema/module/v4.json",
  "title": "omaflake module (module.toml)",
  "description": "module.toml (plan B142; v2, plan B147: modes, several keys and modes, after, does, own, title_de): what a module is – its version, the capabilities it provides and needs, the modules it enhances, and the actions people can bind keys to. Its Nix is default.nix next to it. v3 (plan B198): `files`, files the module needs to be built. v4 (plan B206): `fields` – what the module asks for, at the build (built into the image, `omaflake.fields.<name>` in its Nix; v3's files are file fields of the build) or for a VM (handed to the `setup` command in the guest, never to Nix) – and `setup`.",
  "type": "object",
  "additionalProperties": false,
  "patternProperties": {
    "^description_[a-z]{2,3}$": {
      "type": "string"
    }
  },
  "required": [
    "$schema",
    "version",
    "author",
    "license",
    "title",
    "description"
  ],
  "properties": {
    "$schema": {
      "const": "https://omaflake.dev/schema/module/v4.json"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
    },
    "author": {
      "type": "string"
    },
    "license": {
      "type": "string"
    },
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "homepage": {
      "type": "string"
    },
    "provides": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Capabilities (capabilities.toml)"
    },
    "needs": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "enhances": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "\"<author>/<name>\" of modules it adds to when they are in the recipe"
    },
    "runs_in": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Capabilities whose programs it runs inside (key overlaps)"
    },
    "desktop": {
      "type": "boolean",
      "description": "All its keys work on the whole desktop"
    },
    "own_keys": {
      "type": "boolean",
      "description": "An editor's keys: the key rule does not apply"
    },
    "unfree": {
      "type": "boolean",
      "description": "Not free software"
    },
    "actions": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "key"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "title_de": {
            "type": "string"
          },
          "key": {
            "oneOf": [
              {
                "type": "string",
                "description": "A chord – modifiers (Super, Ctrl, Alt, Shift) and a key joined by \"+\" (\"Super+Shift+Return\", \"Ctrl+g\") – or chords separated by spaces (\"Space f f\"); Digit and Arrow stand for 1–9 and the arrows"
              },
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "string",
                  "description": "A chord – modifiers (Super, Ctrl, Alt, Shift) and a key joined by \"+\" (\"Super+Shift+Return\", \"Ctrl+g\") – or chords separated by spaces (\"Space f f\"); Digit and Arrow stand for 1–9 and the arrows"
                },
                "description": "Several keys – each does it"
              }
            ]
          },
          "mode": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "string"
                }
              }
            ],
            "description": "Only in this mode of the module, or in these"
          },
          "after": {
            "type": "string",
            "description": "The mode the program is in afterwards; without it, it stays"
          },
          "does": {
            "type": "string",
            "description": "What it does in the program's own words (Zellij's NewPane \"Down\"); a module may write the program's configuration from it"
          },
          "own": {
            "type": "boolean",
            "description": "The program's own key, shown for reference – key binding sets do not change it"
          },
          "desktop": {
            "type": "boolean",
            "description": "Works everywhere on the desktop"
          },
          "context": {
            "type": "string",
            "description": "Bound inside another module's program (\"<author>/<name>\")"
          }
        }
      }
    },
    "modes": {
      "type": "object",
      "description": "The modes of the module's program: its keys differ there",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "title_de": {
            "type": "string"
          },
          "start": {
            "type": "boolean",
            "description": "The program starts in it (exactly one mode)"
          }
        }
      }
    },
    "setup": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "command"
      ],
      "description": "The command in the guest that takes a VM's values (plan B206): called as `<command> --omaflake-setup` over SSH at the VM's first start and after an always field changed, with the VM's name in the variable OMAFLAKE_VM and the host's short name in OMAFLAKE_HOST (from omaflake 0.9.2); reads one JSON object – every create and always field in its own type, null without a value, a file as its path in the guest – on standard input and exits 0 when it is done. Required with fields of when create or always.",
      "properties": {
        "command": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$",
          "description": "A command on the guest's PATH"
        }
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "type",
          "when",
          "title"
        ],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,31}$",
            "description": "The key in the JSON the setup command reads and in the Nix module's omaflake.fields"
          },
          "type": {
            "enum": [
              "text",
              "secret",
              "file",
              "choice",
              "number",
              "switch"
            ],
            "description": "secret: typed hidden, never built into an image (not with when = build); file: for the build a fixed-output path of the Nix Store (store, hash), for a VM copied into it, the command gets its path in the guest"
          },
          "when": {
            "enum": [
              "build",
              "create",
              "always"
            ],
            "description": "build: asked on the build page, built into the image; create: asked once in the New VM form; always: in the New VM form and later in the VM's settings"
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "title_de": {
            "type": "string"
          },
          "help": {
            "type": "string"
          },
          "help_de": {
            "type": "string"
          },
          "placeholder": {
            "type": "string",
            "description": "An example shown in the empty field of a text (\"my-org or my-org/my-repo\"); without one the form says whether it is needed. omaflake before 0.9.1 ignores it"
          },
          "placeholder_de": {
            "type": "string"
          },
          "required": {
            "type": "boolean",
            "default": false,
            "description": "Nothing is handed over (create, always) or built (build) while it has no value; a default counts, a secret counts once the command took one"
          },
          "default": {
            "type": [
              "string",
              "integer",
              "boolean"
            ],
            "description": "The value while none is given – in the field's type; not for secret and file"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1,
            "description": "A choice's values"
          },
          "min": {
            "type": "integer"
          },
          "max": {
            "type": "integer"
          },
          "step": {
            "type": "integer",
            "minimum": 1
          },
          "accept": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^[A-Za-z0-9]+$"
            },
            "description": "A file's extensions, without the dot"
          },
          "keep": {
            "type": "boolean",
            "default": false,
            "description": "A secret kept for the VM (Keychain, Secret Service) after the command took it; else forgotten"
          },
          "store": {
            "type": "string",
            "pattern": "^[^/]+$",
            "description": "A file of the build: the requireFile's name in the Nix Store"
          },
          "hash": {
            "type": "string",
            "pattern": "^sha256-[A-Za-z0-9+/]{43}=$",
            "description": "Its hash in SRI form – the `hash` of the module's `requireFile`"
          },
          "mode": {
            "enum": [
              "recursive",
              "flat"
            ],
            "default": "recursive",
            "description": "recursive: a folder or file as a NAR (`nix-store --add-fixed --recursive`); flat: a file"
          },
          "from": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The file names it may come as on this computer, the download first; a .xip or .zip is unpacked"
          },
          "search": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Where to look for them; ~ is the home folder"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Where to download it"
          }
        }
      },
      "description": "What the module asks for (plan B206)"
    }
  }
}
