Skip to content

Inventory

This provides an overview of the available attributes of the inventory model.

It can be set via the inventory attribute of the buildClan function, or via the clan.inventory attribute of flake-parts.

machines

Attribute: inventory.machines

Machines in the inventory.

Each machine declared here can be referencd via its attributeName by the inventory.services roles.

Type: attribute set of (submodule)

Default:

{ }

interface.nix

machines.description

Attribute: inventory.machines.<name>.description

Optional freeform description

Type: null or string

Default:

null

interface.nix

machines.icon

Attribute: inventory.machines.<name>.icon

Under construction, will be used for the UI

Type: null or string

Default:

null

interface.nix

machines.name

Attribute: inventory.machines.<name>.name

Name of the machine or service

Type: string

Default:

"β€Ήnameβ€Ί"

interface.nix

machines.tags

Attribute: inventory.machines.<name>.tags

List of tags for the machine.

The machine can be referenced by its tags in inventory.services

Example
inventory.machines.machineA.tags = [ "tag1" "tag2" ];
services.borgbackup."instance_1".roles.client.tags = [ "tag1" ];

Note

Tags can be used to determine the membership of the machine in the services. Without changing the service configuration, the machine can be added to a service by adding the correct tags to the machine.

Type: list of string

Default:

[ ]

interface.nix

machines.deploy.targetHost

Attribute: inventory.machines.<name>.deploy.targetHost

Configuration for the deployment of the machine

Type: null or string

Default:

null

interface.nix

meta

Attribute: inventory.meta

This option has no description.

Type: submodule

interface.nix

meta.description

Attribute: inventory.meta.description

Optional freeform description

Type: null or string

Default:

null

meta-interface.nix

meta.icon

Attribute: inventory.meta.icon

Under construction, will be used for the UI

Type: null or string

Default:

null

meta-interface.nix

meta.name

Attribute: inventory.meta.name

Name of the clan.

Needs to be (globally) unique, as this determines the folder name where the flake gets downloaded to.

Type: string

meta-interface.nix

modules

Attribute: inventory.modules

A mapping of module names to their path.

Each module can be referenced by its attributeName in the inventory.services attribute set.

Important

Each module MUST fullfill the following requirements to be usable with the inventory:

  • The module MUST have a README.md file with a description.
  • The module MUST have at least features = [ "inventory" ] in the frontmatter section.
  • The module MUST have a subfolder roles with at least one {roleName}.nix file.

For further information see: Module Authoring Guide.

Example
buildClan {
    # 1. Add the module to the avilable inventory modules
    inventory.modules = {
      custom-module = ./modules/my_module;
    };
    # 2. Use the module in the inventory
    inventory.services = {
      custom-module.instance_1 = {
          roles.default.machines = [ "machineA" ];
      };
    };
};

Type: attribute set of path

Default:

"clanModules of clan-core"

interface.nix

services

Attribute: inventory.services

Services of the inventory.

  • The first <name> is the moduleName. It must be a valid clanModule name.
  • The second <name> is an arbitrary instance name.
Example
#        ClanModule name. See the module documentation for the available modules.
#        ↓          ↓ Instance name, can be anything, some services might use it as a unique identifier.
services.borgbackup."instance_1" = {
  roles.client.machines = ["machineA"];
};

Note

Services MUST be added to machines via roles exclusively. See roles.<rolename>.machines or roles.<rolename>.tags for more information.

Type: attribute set of attribute set of (submodule)

Default:

{ }

interface.nix

services.config

Attribute: inventory.services.<name>.<name>.config

Configuration of the specific clanModule.

Note

Configuration is passed to the nixos configuration scoped to the module.

  clan.<serviceName> = { ... # Config }
Example

For services.borgbackup the config is the passed to the machine with the prefix of clan.borgbackup. This means all config values are mapped to the borgbackup clanModule exclusively (config.clan.borgbackup).

{
  services.borgbackup."instance_1".config = {
    destinations = [ ... ];
    # See the 'borgbackup' module docs for all options
  };
}

Note

The module author is responsible for supporting multiple instance configurations in different roles. See each clanModule's documentation for more information.

Type: attribute set of anything

Default:

{ }

interface.nix

services.enabled

Attribute: inventory.services.<name>.<name>.enabled

Enable or disable the complete service.

If the service is disabled, it will not be added to any machine.

Note

This flag is primarily used to temporarily disable a service. I.e. A 'backup service' without any 'server' might be incomplete and would cause failure if enabled.

Type: boolean

Default:

true

interface.nix

services.extraModules

Attribute: inventory.services.<name>.<name>.extraModules

List of additionally imported .nix expressions.

Supported types:

  • Strings: Interpreted relative to the 'directory' passed to buildClan.
  • Paths: should be relative to the current file.
  • Any: Nix expression must be serializable to JSON.

Note

The import only happens if the machine is part of the service or role.

Other types are passed through to the nixos configuration.

Example

To import the special.nix file

. Clan Directory
β”œβ”€β”€ flake.nix
...
└── modules
    β”œβ”€β”€ special.nix
    └── ...
{
  extraModules = [ "modules/special.nix" ];
}

Type: list of (string or anything)

Default:

[ ]

interface.nix

services.machines

Attribute: inventory.services.<name>.<name>.machines

Attribute set of machines specific config for the service.

Will be merged with other service configs, such as the role config and the global config. For machine specific overrides use mkForce or other higher priority methods.

Example
services.borgbackup."instance_1" = {
  roles.client.machines = ["machineA"];

  machines.machineA.config = {
    # Additional specific config for the machine
    # This is merged with all other config places
  };
};

Type: attribute set of (submodule)

Default:

{ }

interface.nix

services.roles

Attribute: inventory.services.<name>.<name>.roles

This option has no description.

Type: attribute set of (submodule)

Default:

{ }

interface.nix

services.meta.description

Attribute: inventory.services.<name>.<name>.meta.description

Optional freeform description

Type: null or string

Default:

null

interface.nix

services.meta.icon

Attribute: inventory.services.<name>.<name>.meta.icon

Under construction, will be used for the UI

Type: null or string

Default:

null

interface.nix

services.meta.name

Attribute: inventory.services.<name>.<name>.meta.name

Name of the machine or service

Type: string

Default:

"β€Ήnameβ€Ί"

interface.nix

services.machines.config

Attribute: inventory.services.<name>.<name>.machines.<name>.config

Additional configuration of the specific machine.

See how service.<name>.<name>.config works in general for further information.

Type: attribute set of anything

Default:

{ }

interface.nix

services.machines.extraModules

Attribute: inventory.services.<name>.<name>.machines.<name>.extraModules

List of additionally imported .nix expressions.

Supported types:

  • Strings: Interpreted relative to the 'directory' passed to buildClan.
  • Paths: should be relative to the current file.
  • Any: Nix expression must be serializable to JSON.

Note

The import only happens if the machine is part of the service or role.

Other types are passed through to the nixos configuration.

Example

To import the special.nix file

. Clan Directory
β”œβ”€β”€ flake.nix
...
└── modules
    β”œβ”€β”€ special.nix
    └── ...
{
  extraModules = [ "modules/special.nix" ];
}

Type: list of (string or anything)

Default:

[ ]

interface.nix

services.roles.config

Attribute: inventory.services.<name>.<name>.roles.<name>.config

Additional configuration of the specific role.

See how service.<name>.<name>.config works in general for further information.

Type: attribute set of anything

Default:

{ }

interface.nix

services.roles.extraModules

Attribute: inventory.services.<name>.<name>.roles.<name>.extraModules

List of additionally imported .nix expressions.

Supported types:

  • Strings: Interpreted relative to the 'directory' passed to buildClan.
  • Paths: should be relative to the current file.
  • Any: Nix expression must be serializable to JSON.

Note

The import only happens if the machine is part of the service or role.

Other types are passed through to the nixos configuration.

Example

To import the special.nix file

. Clan Directory
β”œβ”€β”€ flake.nix
...
└── modules
    β”œβ”€β”€ special.nix
    └── ...
{
  extraModules = [ "modules/special.nix" ];
}

Type: list of (string or anything)

Default:

[ ]

interface.nix

services.roles.machines

Attribute: inventory.services.<name>.<name>.roles.<name>.machines

List of machines which are part of the role.

The machines are referenced by their attributeName in the inventory.machines attribute set.

Memberships are decaled here to determine which machines are part of the service.

Alternatively, tags can be used to determine the membership, more dynamically.

Type: list of string

Default:

[ ]
Example
[
  "machineA"
]

interface.nix

services.roles.tags

Attribute: inventory.services.<name>.<name>.roles.<name>.tags

List of tags which are used to determine the membership of the role.

The tags are matched against the inventory.machines.<machineName>.tags attribute set. If a machine has at least one tag of the role, it is part of the role.

Type: list of string

Default:

[ ]

interface.nix

tags

Attribute: inventory.tags

Tags of the inventory are used to group machines together.

It is recommended to use machine.tags to define the tags of the machines.

This can be used to define custom tags that are either statically set or dynamically computed.

Static Tags

Static Tag Example
inventory.tags = {
  foo = [ "machineA" "machineB" ];
};

The tag foo will always be added to machineA and machineB.

Dynamic Tags

It is possible to compute tags based on the machines properties or based on other tags.

Danger

This is a powerfull feature and should be used with caution.

It is possible to cause infinite recursion by computing tags based on the machines properties or based on other tags.

Dynamic Tag Example

allButFoo is a computed tag. It will be added to all machines except 'foo'

all is a predefined tag. See the docs of tags.all.

#  inventory.tags ↓       ↓ inventory.machines
inventory.tags = {config, machines...}: {
  #                                                        ↓↓↓ The "all" tag
  allButFoo = builtins.filter (name: name != "foo") config.all;
};

Warning

Do NOT compute tags from machine.tags this will cause infinite recursion.

Type: lazy attribute set of list of string

Default:

{ }

interface.nix

tags.all

Attribute: inventory.tags.all

Predefined Tag

Will be added to all machines

inventory.machines.machineA.tags = [ "all" ];

Type: list of string

Default:

"[ <All Machines> ]"

interface.nix