forked from fediversity/fediversity
Compare commits
10 commits
fefcd93bc1
...
7880e7e6a0
Author | SHA1 | Date | |
---|---|---|---|
7880e7e6a0 | |||
5a3c6ae08f | |||
6ae158bd0f | |||
21aaa26510 | |||
7225eda440 | |||
1d7a18b0a6 | |||
c764c0f7b6 | |||
34529a7de4 | |||
6c2022d064 | |||
f51462afc9 |
2 changed files with 96 additions and 76 deletions
|
@ -16,33 +16,52 @@ in
|
|||
test-eval = {
|
||||
expr =
|
||||
let
|
||||
example = eval {
|
||||
runtime-configurations.nixos =
|
||||
example = eval (
|
||||
{ config, ... }:
|
||||
{
|
||||
providers.single-ssh-host =
|
||||
{ ... }:
|
||||
{
|
||||
system.stateVersion = "25.05";
|
||||
};
|
||||
runtime-environments.bar.nixos = { };
|
||||
applications.foo = {
|
||||
module =
|
||||
resources.bar.runtime-environment.single-ssh-host = {
|
||||
ssh = {
|
||||
host = "localhost";
|
||||
username = "root";
|
||||
authentication.password = "";
|
||||
};
|
||||
};
|
||||
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;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
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"; } ]; };
|
||||
};
|
||||
runtime-environments = mkOption {
|
||||
description = "Collection of runtime environments into which applications can be deployed";
|
||||
type = attrsOf runtime-environment;
|
||||
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
|
||||
};
|
||||
};
|
||||
})
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue