Fediversity/deployment/data-model.nix
Kiara Grouwstra 2e97b4b647
data model: add run-time configuration
have run-time environments use their corresponding run-time configurations

grant run-time environments their own modules with their own description

data model: runtime environment

allows declaring options so instantiations may configure required
settings

data model: deployment

data model: migration

better reflect naming from diagram configuration data flow

WIP: implement data model as in diagram

this doesn't update the tests yet because we don't have all the data
types in place anyway yet, and I still need to come up with testable examples.

WIP: add missing types

WIP: start writing an evaluation test

turns out we also need a collection of configurations, obviously
next: figure out where to wire everything up to obtain a deployment

WIP: implement mappings

WIP: (broken) implement test

WIP: illustrate an entire NixOS configuration as a resource

fix typos, lint, format

test for configuration passes, test for deployment wip

use `mapAttrs` right

`mapAttrs'` takes two args rather than a set, whereas if only the val
changes `mapAttrs (_: v: ...)` should do

rm deployment/resources
2025-07-06 11:09:04 +02:00

87 lines
2.7 KiB
Nix

{
lib,
config,
...
}:
let
inherit (lib) mkOption types;
inherit (lib.types)
attrsOf
attrTag
deferredModuleWith
submodule
optionType
functionTo
;
functionType = import ./function.nix;
application-resources = {
options.resources = mkOption {
# TODO: maybe transpose, and group the resources by type instead
type = attrsOf (
attrTag (lib.mapAttrs (_name: resource: mkOption { type = resource.request; }) config.resources)
);
};
};
in
{
options = {
applications = mkOption {
description = "Collection of Fediversity applications";
type = attrsOf (
submodule (application: {
_class = "fediversity-application";
options = {
description = mkOption {
description = "Description to be shown in the application overview";
type = types.str;
};
module = mkOption {
description = "Operator-facing configuration options for the application";
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
};
implementation = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.config-mapping.function-type;
};
resources = mkOption {
description = "Compute resources required by an application";
type = functionTo application.config.config-mapping.output-type;
readOnly = true;
default = input: (application.config.implementation input).output;
};
config-mapping = mkOption {
description = "Function type for the mapping from application configuration to required resources";
type = submodule functionType;
readOnly = true;
default = {
input-type = application.config.module;
output-type = application-resources;
};
};
};
})
);
};
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submodule {
options = {
enable = lib.mkEnableOption {
description = "your Fediversity configuration";
};
applications = lib.mapAttrs (
_name: application:
mkOption {
description = application.description;
type = submodule application.module;
default = { };
}
) config.applications;
};
};
};
};
}