forked from fediversity/fediversity
Compare commits
No commits in common. "e69bb3bccb7fc3d39341b435431d26e0798e717f" and "9c219341b11df75c09b3455c4839de1bf66267e5" have entirely different histories.
e69bb3bccb
...
9c219341b1
3 changed files with 88 additions and 25 deletions
|
|
@ -99,12 +99,13 @@ in
|
||||||
{
|
{
|
||||||
options.enable = lib.mkEnableOption "Hello in the shell";
|
options.enable = lib.mkEnableOption "Hello in the shell";
|
||||||
};
|
};
|
||||||
implementation =
|
implementation = cfg: {
|
||||||
cfg:
|
input = cfg;
|
||||||
lib.optionalAttrs cfg.enable {
|
output = lib.optionalAttrs cfg.enable {
|
||||||
resources.hello.login-shell.packages.hello = pkgs.hello;
|
resources.hello.login-shell.packages.hello = pkgs.hello;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
environments.single-nixos-vm =
|
environments.single-nixos-vm =
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
|
|
@ -151,7 +152,7 @@ in
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
resources = fediversity.applications.hello.implementation fediversity.example-configuration.applications.hello;
|
resources = fediversity.applications.hello.resources fediversity.example-configuration.applications.hello;
|
||||||
hello-shell = resources.resources.hello.login-shell;
|
hello-shell = resources.resources.hello.login-shell;
|
||||||
environment = fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell;
|
environment = fediversity.environments.single-nixos-vm.resources.operator-environment.login-shell;
|
||||||
result = mkDeployment {
|
result = mkDeployment {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ let
|
||||||
functionTo
|
functionTo
|
||||||
;
|
;
|
||||||
|
|
||||||
|
functionType = import ./function.nix;
|
||||||
application-resources = submodule {
|
application-resources = submodule {
|
||||||
options.resources = mkOption {
|
options.resources = mkOption {
|
||||||
# TODO: maybe transpose, and group the resources by type instead
|
# TODO: maybe transpose, and group the resources by type instead
|
||||||
|
|
@ -84,7 +85,8 @@ in
|
||||||
};
|
};
|
||||||
applications = mkOption {
|
applications = mkOption {
|
||||||
description = "Collection of Fediversity applications";
|
description = "Collection of Fediversity applications";
|
||||||
type = attrsOf (submodule {
|
type = attrsOf (
|
||||||
|
submodule (application: {
|
||||||
_class = "fediversity-application";
|
_class = "fediversity-application";
|
||||||
options = {
|
options = {
|
||||||
description = mkOption {
|
description = mkOption {
|
||||||
|
|
@ -96,12 +98,28 @@ in
|
||||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||||
};
|
};
|
||||||
implementation = mkOption {
|
implementation = mkOption {
|
||||||
description = "Mapping of application configuration to deployment resources required by an application";
|
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||||
# input: submodule application.config.module
|
type = application.config.config-mapping.function-type;
|
||||||
type = functionTo application-resources;
|
};
|
||||||
|
resources = mkOption {
|
||||||
|
description = "Compute resources required by an application";
|
||||||
|
type = functionTo application.config.config-mapping.output-type;
|
||||||
|
readOnly = true;
|
||||||
|
default = input: (application.config.implementation input).output;
|
||||||
|
};
|
||||||
|
# TODO(@fricklerhandwerk): this needs a better name, it's just the type
|
||||||
|
config-mapping = mkOption {
|
||||||
|
description = "Function type for the mapping from application configuration to required resources";
|
||||||
|
type = submodule functionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
input-type = submodule application.config.module;
|
||||||
|
output-type = application-resources;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
environments = mkOption {
|
environments = mkOption {
|
||||||
description = "Run-time environments for Fediversity applications to be deployed to";
|
description = "Run-time environments for Fediversity applications to be deployed to";
|
||||||
|
|
@ -123,16 +141,24 @@ in
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
implementation = mkOption {
|
implementation = mkOption {
|
||||||
description = "Mapping from resources required by applications to available resources to a deployment";
|
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
||||||
# input: application-resources
|
type = environment.config.resource-mapping.function-type;
|
||||||
type = functionTo nixops4Deployment;
|
};
|
||||||
|
resource-mapping = mkOption {
|
||||||
|
description = "Function type for the mapping from resources to a (NixOps4) deployment";
|
||||||
|
type = submodule functionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
input-type = application-resources;
|
||||||
|
output-type = nixops4Deployment;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
# TODO(@fricklerhandwerk): maybe this should be a separate thing such as `fediversity-setup`,
|
# TODO(@fricklerhandwerk): maybe this should be a separate thing such as `fediversity-setup`,
|
||||||
# which makes explicit which applications and environments are available.
|
# which makes explicit which applications and environments are available.
|
||||||
# then the deployments can simply be the result of the function application baked into this module.
|
# then the deployments can simply be the result of the function application baked into this module.
|
||||||
deployment = mkOption {
|
deployment = mkOption {
|
||||||
description = "Generate a deployment from a configuration, by applying an environment's resource policies to the applications' resource mappings";
|
description = "Generate a deployment from a configuration, by applying an environment's resource policies to the applications' resource mappings";
|
||||||
type = functionTo nixops4Deployment;
|
type = functionTo (environment.config.resource-mapping.output-type);
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
cfg:
|
cfg:
|
||||||
|
|
|
||||||
36
deployment/function.nix
Normal file
36
deployment/function.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
Modular function type
|
||||||
|
*/
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (types)
|
||||||
|
submodule
|
||||||
|
functionTo
|
||||||
|
optionType
|
||||||
|
;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
input-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
};
|
||||||
|
output-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
};
|
||||||
|
function-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo (submodule {
|
||||||
|
options = {
|
||||||
|
input = mkOption {
|
||||||
|
type = config.input-type;
|
||||||
|
};
|
||||||
|
output = mkOption {
|
||||||
|
type = config.output-type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue