Before the change, modules of the form
```nix
{ lib, ... }: {
foo.bar = lib.mkOption {
# ...
};
}
```
or
```nix
{ lib, ... }: {
foo = lib.mkOption {
type = lib.types.subModule {
bar = lib.mkOption {
# ...
};
};
};
}
```
would not render with `foo` as required, which is not faithful to the
module system's semantics.
This change also tests that fields with defaults are not marked required.
Note that submodule options cannot have their defaults rendered to JSON
schema, and are therefore always marked required.
Architecturally this change is rather unfortunate: So far the checks for
defaults happen in the rendering (using `isDefault`) and not in the parsing,
but here we're adding a field to `$exportedModuleInfo`. While strictly
speaking we probably don't want to consider requiredness as module-level
information, it seems more reasonable to me to do it that way since at
the JSON schema level we have lost the distinction between `attrs`,
`attrsOf`, `submodule`.
99 lines
2.8 KiB
JSON
99 lines
2.8 KiB
JSON
{
|
||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||
"$exportedModuleInfo": { "path": [] },
|
||
"type": "object",
|
||
"additionalProperties": false,
|
||
"required": [ "services" ],
|
||
"properties": {
|
||
"name": {
|
||
"$exportedModuleInfo": { "path": ["name"] },
|
||
"type": "string",
|
||
"default": "John Doe",
|
||
"description": "The name of the user"
|
||
},
|
||
"age": {
|
||
"$exportedModuleInfo": { "path": ["age"] },
|
||
"type": "integer",
|
||
"default": 42,
|
||
"description": "The age of the user"
|
||
},
|
||
"isAdmin": {
|
||
"$exportedModuleInfo": { "path": ["isAdmin"] },
|
||
"type": "boolean",
|
||
"default": false,
|
||
"description": "Is the user an admin?"
|
||
},
|
||
"kernelModules": {
|
||
"$exportedModuleInfo": { "path": ["kernelModules"] },
|
||
"type": "array",
|
||
"items": {
|
||
"$exportedModuleInfo": { "path": ["kernelModules"] },
|
||
"type": "string"
|
||
},
|
||
"default": ["nvme", "xhci_pci", "ahci"],
|
||
"description": "A list of enabled kernel modules"
|
||
},
|
||
"userIds": {
|
||
"$exportedModuleInfo": { "path": ["userIds"] },
|
||
"type": "object",
|
||
"default": {
|
||
"horst": 1,
|
||
"peter": 2,
|
||
"albrecht": 3
|
||
},
|
||
"additionalProperties": {
|
||
"$exportedModuleInfo": { "path": ["userIds"] },
|
||
"type": "integer"
|
||
},
|
||
"description": "Some attributes"
|
||
},
|
||
"colour": {
|
||
"$exportedModuleInfo": { "path": ["colour"] },
|
||
"default": "red",
|
||
"description": "The colour of the user",
|
||
"enum": ["red", "blue", "green"]
|
||
},
|
||
"services": {
|
||
"$exportedModuleInfo": { "path": ["services"] },
|
||
"type": "object",
|
||
"additionalProperties": false,
|
||
"properties": {
|
||
"opt": {
|
||
"$exportedModuleInfo": { "path": ["services", "opt"] },
|
||
"type": "string",
|
||
"default": "foo",
|
||
"description": "A submodule option"
|
||
}
|
||
}
|
||
},
|
||
"destinations": {
|
||
"$exportedModuleInfo": { "path": ["destinations"] },
|
||
"additionalProperties": {
|
||
"$exportedModuleInfo": { "path": ["destinations", "<name>"] },
|
||
"properties": {
|
||
"name": {
|
||
"$exportedModuleInfo": {
|
||
"path": ["destinations", "<name>", "name"]
|
||
},
|
||
"default": "‹name›",
|
||
"description": "the name of the backup job",
|
||
"type": "string"
|
||
},
|
||
"repo": {
|
||
"$exportedModuleInfo": {
|
||
"path": ["destinations", "<name>", "repo"]
|
||
},
|
||
"description": "the borgbackup repository to backup to",
|
||
"type": "string"
|
||
}
|
||
},
|
||
"required": ["repo"],
|
||
"additionalProperties": false,
|
||
"type": "object"
|
||
},
|
||
"default": {},
|
||
"type": "object"
|
||
}
|
||
}
|
||
}
|