Compare commits

..

10 commits

Author SHA1 Message Date
7880e7e6a0 WIP 2025-07-01 17:52:37 +02:00
5a3c6ae08f WIP 2025-07-01 15:28:46 +02:00
6ae158bd0f WIP 2025-07-01 15:17:59 +02:00
21aaa26510 WIP 2025-07-01 15:12:26 +02:00
7225eda440 WIP 2025-07-01 15:10:57 +02:00
1d7a18b0a6 WIP 2025-07-01 12:16:29 +02:00
c764c0f7b6
better reflect naming from diagram configuration data flow 2025-06-30 14:20:21 +02:00
34529a7de4
data model: migration 2025-06-23 19:22:47 +02:00
6c2022d064
data model: deployment 2025-06-23 16:35:11 +02:00
f51462afc9
data model: runtime environment
allows declaring options so instantiations may configure required
settings
2025-06-23 16:35:04 +02:00
2 changed files with 96 additions and 76 deletions

View file

@ -16,33 +16,52 @@ in
test-eval = {
expr =
let
example = eval {
runtime-configurations.nixos =
{ ... }:
{
system.stateVersion = "25.05";
example = eval (
{ config, ... }:
{
providers.single-ssh-host =
{ ... }:
{
system.stateVersion = "25.05";
};
resources.bar.runtime-environment.single-ssh-host = {
ssh = {
host = "localhost";
username = "root";
authentication.password = "";
};
};
runtime-environments.bar.nixos = { };
applications.foo = {
module =
applications.foo.module =
{ pkgs, ... }:
{
environment.systemPackages = [
pkgs.hello
];
};
};
};
deployments.baz = {
module = { };
runtime-environment = config.resources.bar.runtime-environment;
};
migrations.boo = {
deployment = config.deployments.baz;
runtime-environment = config.resources.bar.runtime-environment;
};
}
);
in
{
has-runtime-configuration = lib.isAttrs example.runtime-configurations.nixos;
has-runtime-environment = lib.isAttrs example.runtime-environments.bar.nixos.module;
has-provider = lib.isAttrs example.providers.single-ssh-host;
has-resource = lib.isAttrs example.resources.bar.runtime-environment.single-ssh-host.module;
has-application = lib.isAttrs example.applications.foo.module;
has-deployment = lib.isAttrs example.deployments.baz.module;
has-migration = lib.isAttrs example.migrations.boo.deployment;
};
expected = {
has-runtime-configuration = true;
has-runtime-environment = true;
has-provider = true;
has-resource = true;
has-application = true;
has-deployment = true;
has-migration = true;
};
};
}

View file

@ -4,81 +4,82 @@
...
}:
let
inherit (lib)
attrNames
mapAttrs
mkOption
genAttrs
;
inherit (lib) mkOption;
inherit (lib.types)
attrsOf
attrTag
deferredModule
deferredModuleWith
mergeTypes
nullOr
submoduleWith
submodule
str
;
runtime-configuration = mkOption {
description = "The NixOS module of a run-time environment";
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 run-time environment";
type = deferredModule;
default = config.runtime-configurations.${name};
readOnly = true;
};
});
}
)
)
{
nixos = {
description = "A NixOS instance to deploy to.";
type = submodule {
};
};
}
);
application = submoduleWith {
description = "A Fediversity application";
modules = [
{
options = {
module = mkOption {
description = "The NixOS module for that application, for configuring that application";
type = deferredModule;
};
};
}
];
};
in
{
options = {
runtime-configurations = mkOption {
description = "Collection of runtime environments into which applications can be deployed";
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: runtime-configuration));
};
runtime-environments = mkOption {
description = "Collection of runtime environments into which applications can be deployed";
type = attrsOf runtime-environment;
resources = mkOption {
description = "Collection of deployment resources that can be configured by hosting providers and required by applications";
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 {
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 */
};
};
})
);
};
environments = mkOption {
description = "Run-time environments for Fediversity applications to be deployed to";
type = attrsOf (
submodule (environment: {
class = "fediversity-environment";
options = {
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
};
};
})
);
};
};
}