Files
clan-core/lib/jsonschema/example-interface.nix
Valentin Gagarin 6a2e81373c lib/jsonschema: render defaults for submodule options
this relaxes the constraint that options of type `submodule` are always
required, and will render benign default values.
2025-04-16 16:55:46 +02:00

105 lines
2.5 KiB
Nix

# An example nixos module declaring an interface.
{ lib, ... }:
{
options = {
# str
name = lib.mkOption {
type = lib.types.str;
default = "John Doe";
description = "The name of the user";
};
# int
age = lib.mkOption {
type = lib.types.int;
default = 42;
description = "The age of the user";
};
# bool
isAdmin = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Is the user an admin?";
};
# a submodule option without default
services = lib.mkOption {
type = lib.types.submodule {
options.opt = lib.mkOption {
type = lib.types.str;
default = "foo";
description = "A submodule option";
};
};
};
# a submodule option with default
programs = lib.mkOption {
type = lib.types.submodule {
options.opt = lib.mkOption {
type = lib.types.str;
default = "bar";
description = "Another submodule option";
};
};
default = { };
};
# attrs of int
userIds = lib.mkOption {
type = lib.types.attrsOf lib.types.int;
description = "Some attributes";
default = {
horst = 1;
peter = 2;
albrecht = 3;
};
};
# attrs of submodule
userModules = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule {
options.foo = lib.mkOption { };
}
);
};
# list of str
kernelModules = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [
"nvme"
"xhci_pci"
"ahci"
];
description = "A list of enabled kernel modules";
};
# enum
colour = lib.mkOption {
type = lib.types.enum [
"red"
"blue"
"green"
];
default = "red";
description = "The colour of the user";
};
destinations = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule (
{ name, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.strMatching "^[a-zA-Z0-9._-]+$";
default = name;
description = "the name of the backup job";
};
repo = lib.mkOption {
type = lib.types.str;
description = "the borgbackup repository to backup to";
};
};
}
)
);
default = { };
};
};
}