forked from fediversity/fediversity
Compare commits
No commits in common. "7880e7e6a0ade09937d5e930de6f3b41add73f26" and "fefcd93bc177b2b7f324645bbc37f37ee4d8a306" have entirely different histories.
7880e7e6a0
...
fefcd93bc1
2 changed files with 76 additions and 96 deletions
|
@ -16,52 +16,33 @@ in
|
||||||
test-eval = {
|
test-eval = {
|
||||||
expr =
|
expr =
|
||||||
let
|
let
|
||||||
example = eval (
|
example = eval {
|
||||||
{ config, ... }:
|
runtime-configurations.nixos =
|
||||||
{
|
|
||||||
providers.single-ssh-host =
|
|
||||||
{ ... }:
|
{ ... }:
|
||||||
{
|
{
|
||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
};
|
};
|
||||||
resources.bar.runtime-environment.single-ssh-host = {
|
runtime-environments.bar.nixos = { };
|
||||||
ssh = {
|
applications.foo = {
|
||||||
host = "localhost";
|
module =
|
||||||
username = "root";
|
|
||||||
authentication.password = "";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
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-provider = lib.isAttrs example.providers.single-ssh-host;
|
has-runtime-configuration = lib.isAttrs example.runtime-configurations.nixos;
|
||||||
has-resource = lib.isAttrs example.resources.bar.runtime-environment.single-ssh-host.module;
|
has-runtime-environment = lib.isAttrs example.runtime-environments.bar.nixos.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-provider = true;
|
has-runtime-configuration = true;
|
||||||
has-resource = true;
|
has-runtime-environment = true;
|
||||||
has-application = true;
|
has-application = true;
|
||||||
has-deployment = true;
|
|
||||||
has-migration = true;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,82 +4,81 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption;
|
inherit (lib)
|
||||||
|
attrNames
|
||||||
|
mapAttrs
|
||||||
|
mkOption
|
||||||
|
genAttrs
|
||||||
|
;
|
||||||
inherit (lib.types)
|
inherit (lib.types)
|
||||||
attrsOf
|
attrsOf
|
||||||
attrTag
|
attrTag
|
||||||
deferredModuleWith
|
deferredModule
|
||||||
mergeTypes
|
mergeTypes
|
||||||
nullOr
|
|
||||||
submoduleWith
|
submoduleWith
|
||||||
submodule
|
submodule
|
||||||
str
|
|
||||||
;
|
;
|
||||||
in
|
runtime-configuration = mkOption {
|
||||||
{
|
description = "The NixOS module of a run-time environment";
|
||||||
options = {
|
type = deferredModule;
|
||||||
resources = mkOption {
|
default = {
|
||||||
description = "Collection of deployment resources that can be configured by hosting providers and required by applications";
|
_class = "nixos";
|
||||||
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";
|
runtime-environment = attrTag (
|
||||||
type = deferredModuleWith { staticModules = [ { class = "fediversity-resource-provider"; } ]; };
|
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;
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
applications = mkOption {
|
||||||
description = "Collection of Fediversity applications";
|
description = "Collection of Fediversity applications";
|
||||||
type = attrsOf (
|
type = attrsOf application;
|
||||||
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