forked from Fediversity/Fediversity
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.
This commit is contained in:
parent
c764c0f7b6
commit
3ec853a32a
1 changed files with 60 additions and 154 deletions
|
@ -4,176 +4,82 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib) mkOption;
|
||||||
attrNames
|
|
||||||
mapAttrs
|
|
||||||
mkOption
|
|
||||||
genAttrs
|
|
||||||
;
|
|
||||||
inherit (lib.types)
|
inherit (lib.types)
|
||||||
attrsOf
|
attrsOf
|
||||||
attrTag
|
attrTag
|
||||||
deferredModule
|
deferredModuleWith
|
||||||
mergeTypes
|
mergeTypes
|
||||||
nullOr
|
nullOr
|
||||||
submoduleWith
|
submoduleWith
|
||||||
submodule
|
submodule
|
||||||
str
|
str
|
||||||
;
|
;
|
||||||
provider = mkOption {
|
|
||||||
description = "The NixOS module of a provider";
|
|
||||||
type = deferredModule;
|
|
||||||
default = {
|
|
||||||
_class = "nixos";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
runtime-environment = attrTag (
|
|
||||||
mapAttrs
|
|
||||||
(
|
|
||||||
name:
|
|
||||||
option@{ type, ... }:
|
|
||||||
mkOption (
|
|
||||||
option
|
|
||||||
// {
|
|
||||||
type = mergeTypes type (submodule {
|
|
||||||
options.module = mkOption {
|
|
||||||
description = "The NixOS module of the provider";
|
|
||||||
type = deferredModule;
|
|
||||||
default = config.providers.${name};
|
|
||||||
readOnly = true;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
vm = {
|
|
||||||
description = "A VM to deploy to.";
|
|
||||||
type = submodule {
|
|
||||||
options = {
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
single-ssh-host = {
|
|
||||||
description = "A single host to deploy to by SSH.";
|
|
||||||
type = submodule {
|
|
||||||
options = {
|
|
||||||
ssh = mkOption {
|
|
||||||
description = "SSH connection info";
|
|
||||||
type = submodule {
|
|
||||||
options = {
|
|
||||||
host = mkOption {
|
|
||||||
description = "the host to access by SSH";
|
|
||||||
type = str;
|
|
||||||
};
|
|
||||||
username = mkOption {
|
|
||||||
description = "the SSH user to use";
|
|
||||||
type = nullOr str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
authentication = mkOption {
|
|
||||||
description = "authentication method";
|
|
||||||
type = attrsOf (attrTag {
|
|
||||||
private-key = mkOption {
|
|
||||||
description = "path to the user's SSH private key";
|
|
||||||
type = str;
|
|
||||||
example = "/root/.ssh/id_ed25519";
|
|
||||||
};
|
|
||||||
password = mkOption {
|
|
||||||
description = "SSH password";
|
|
||||||
# TODO: mark as sensitive
|
|
||||||
type = str;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
resource = attrTag {
|
|
||||||
runtime-environment = mkOption {
|
|
||||||
description = "A run-time environment one may deploy a NixOS configuration to.";
|
|
||||||
type = runtime-environment;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
application = submoduleWith {
|
|
||||||
description = "A Fediversity application";
|
|
||||||
modules = [
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
module = mkOption {
|
|
||||||
description = ''
|
|
||||||
The NixOS module to configure the application.
|
|
||||||
'';
|
|
||||||
type = deferredModule;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
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
|
in
|
||||||
{
|
{
|
||||||
options = {
|
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 {
|
resources = mkOption {
|
||||||
description = "Collection of resources for use in Fediversity applications";
|
description = "Collection of deployment resources that can be configured by hosting providers and required by applications";
|
||||||
type = attrsOf resource;
|
type = attrsOf (
|
||||||
|
submodule (
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
_class = "fediversity-resource";
|
||||||
|
options = {
|
||||||
|
consumer = mkOption {
|
||||||
|
description = "Configuration of the resource by an application, a description of how the resource is consumed";
|
||||||
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-consumer"; } ]; };
|
||||||
|
};
|
||||||
|
provider = mkOption {
|
||||||
|
description = "Configuration of the resource by the hosting provider, a description of how the resource is made available";
|
||||||
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-provider"; } ]; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
applications = mkOption {
|
||||||
description = "Collection of (available) Fediversity applications";
|
description = "Collection of Fediversity applications";
|
||||||
type = attrsOf application;
|
type = attrsOf (
|
||||||
|
submodule (application: {
|
||||||
|
_class = "fediversity-application";
|
||||||
|
options = {
|
||||||
|
module = mkOption {
|
||||||
|
description = "Operator-facing configuration options for the application";
|
||||||
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||||
|
};
|
||||||
|
config-mapping = mkOption {
|
||||||
|
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||||
|
# TODO: type = (submodule application.config.module) -> (attrsOf (attrTag (lib.mapAttrs' (name: resource: { ${name} = mkOption { type = resource.consumer; }; }) config.resources))) /* something like that */
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
deployments = mkOption {
|
environments = mkOption {
|
||||||
description = "Deployment of a configuration of applications to a run-time environment";
|
description = "Run-time environments for Fediversity applications to be deployed to";
|
||||||
type = attrsOf deployment;
|
type = attrsOf (
|
||||||
};
|
submodule (environment: {
|
||||||
migrations = mkOption {
|
_class = "fediversity-environment";
|
||||||
description = "Migrations from Fediversity deployments to Fediversity run-time environments";
|
options = {
|
||||||
type = attrsOf migration;
|
resources = mkOption {
|
||||||
|
description = "Resources made available by the hosting provider";
|
||||||
|
type = attrsOf (
|
||||||
|
attrTag (
|
||||||
|
lib.mapAttrs' (name: resource: {
|
||||||
|
${name} = mkOption { type = resource.provider; };
|
||||||
|
}) config.resources
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
resource-mapping = mkOption {
|
||||||
|
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
||||||
|
# TODO: type = consumer-resources /* same as the output of application.config-mapping, should be in a `let` */ -> nixops4Deployment
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue