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 = {
|
test-eval = {
|
||||||
expr =
|
expr =
|
||||||
let
|
let
|
||||||
example = eval {
|
example = eval (
|
||||||
runtime-configurations.nixos =
|
{ config, ... }:
|
||||||
{ ... }:
|
{
|
||||||
{
|
providers.single-ssh-host =
|
||||||
system.stateVersion = "25.05";
|
{ ... }:
|
||||||
|
{
|
||||||
|
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, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.hello
|
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
|
in
|
||||||
{
|
{
|
||||||
has-runtime-configuration = lib.isAttrs example.runtime-configurations.nixos;
|
has-provider = lib.isAttrs example.providers.single-ssh-host;
|
||||||
has-runtime-environment = lib.isAttrs example.runtime-environments.bar.nixos.module;
|
has-resource = lib.isAttrs example.resources.bar.runtime-environment.single-ssh-host.module;
|
||||||
has-application = lib.isAttrs example.applications.foo.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 = {
|
expected = {
|
||||||
has-runtime-configuration = true;
|
has-provider = true;
|
||||||
has-runtime-environment = true;
|
has-resource = true;
|
||||||
has-application = true;
|
has-application = true;
|
||||||
|
has-deployment = true;
|
||||||
|
has-migration = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,81 +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
|
||||||
submoduleWith
|
submoduleWith
|
||||||
submodule
|
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
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
runtime-configurations = mkOption {
|
resources = mkOption {
|
||||||
description = "Collection of runtime environments into which applications can be deployed";
|
description = "Collection of deployment resources that can be configured by hosting providers and required by applications";
|
||||||
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: runtime-configuration));
|
type = attrsOf (
|
||||||
};
|
submodule (
|
||||||
runtime-environments = mkOption {
|
{ config, ... }:
|
||||||
description = "Collection of runtime environments into which applications can be deployed";
|
{
|
||||||
type = attrsOf runtime-environment;
|
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 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 */
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
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