Fediversity/deployment/data-model.nix
2025-07-01 12:16:29 +02:00

123 lines
3.3 KiB
Nix

{
lib,
config,
...
}:
let
inherit (lib)
attrNames
mapAttrs
mkOption
genAttrs
;
inherit (lib.types)
attrsOf
attrTag
deferredModule
mergeTypes
nullOr
submoduleWith
submodule
str
;
resource = submoduleWith {
description = "A deployment resource that can be configured by providers and required by applications";
modules = [
{
options = {
consumer = mkOption {
description = "Description how applications can consume the resource";
type = deferredModule;
};
provider = mkOption {
description = "Description how the hosting provider makes the resource available";
type = deferredModule;
};
};
}
];
};
application = submoduleWith {
description = "A Fediversity application";
modules = [
(
{ config, ... }:
{
options = {
module = mkOption {
description = ''
A module for configuring the application.
'';
type = deferredModule;
};
config-mapping = mkOption {
description = "description of how an application configuration maps to deployment resources";
# TODO: type = (submodule config.module) -> (attrsOf resource)
};
};
}
)
];
};
deployment = submoduleWith {
description = "A deployment of a configuration of applications to a run-time environment";
modules = [
{
options = {
# the `applications` option consists of configuration for the above applications
module = mkOption {
description = ''
Configuration to be deployed
'';
type = deferredModule;
};
runtime-environment = mkOption {
description = "The run-time environment to deploy to";
type = runtime-environment;
};
};
}
];
};
migration = submoduleWith {
description = "Migration of a Fediversity deployment to a Fediversity run-time environment";
modules = [
{
options = {
deployment = mkOption {
description = "Deployment to migrate";
type = deployment;
};
runtime-environment = mkOption {
description = "Run-time environment to migrate the deployment to";
type = runtime-environment;
};
};
}
];
};
in
{
options = {
providers = mkOption {
description = "Collection of providers for run-time environments to deploy applications to";
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: provider));
};
resources = mkOption {
description = "Collection of resources for use in Fediversity applications";
type = attrsOf resource;
};
applications = mkOption {
description = "Collection of (available) Fediversity applications";
type = attrsOf application;
};
deployments = mkOption {
description = "Deployment of a configuration of applications to a run-time environment";
type = attrsOf deployment;
};
migrations = mkOption {
description = "Migrations from Fediversity deployments to Fediversity run-time environments";
type = attrsOf migration;
};
};
}