forked from Fediversity/Fediversity
revert submodule
wrapper to align with module functions already doing types #2
4 changed files with 114 additions and 82 deletions
|
@ -1,6 +1,7 @@
|
||||||
let
|
let
|
||||||
inherit (import ../default.nix { }) pkgs inputs;
|
inherit (import ../default.nix { }) pkgs inputs;
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
|
inherit (lib) mkOption types;
|
||||||
eval =
|
eval =
|
||||||
module:
|
module:
|
||||||
(lib.evalModules {
|
(lib.evalModules {
|
||||||
|
@ -12,6 +13,7 @@ let
|
||||||
./data-model.nix
|
./data-model.nix
|
||||||
];
|
];
|
||||||
}).config;
|
}).config;
|
||||||
|
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
test-eval = {
|
test-eval = {
|
||||||
|
@ -20,18 +22,35 @@ in
|
||||||
fediversity = eval (
|
fediversity = eval (
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
resources.nixos = {
|
config = {
|
||||||
|
resources.nixos = {
|
||||||
|
# TODO: consumer = ?
|
||||||
|
# TODO: provider = ?
|
||||||
|
};
|
||||||
|
applications.hello = {
|
||||||
|
description = ''Command-line tool that will print "Hello, world!" on the terminal'';
|
||||||
|
# TODO: module = ?
|
||||||
|
# TODO: config=mapping = ?
|
||||||
|
};
|
||||||
|
environments.single-nixos-vm = {
|
||||||
|
# TODO: resources = ?
|
||||||
|
# TODO: resource-mapping = ?
|
||||||
|
};
|
||||||
};
|
};
|
||||||
applications.hello = {
|
options = {
|
||||||
|
example-configuration = mkOption {
|
||||||
};
|
type = config.configuration;
|
||||||
environments.single-nixos-vm = {
|
readOnly = true;
|
||||||
|
default = {
|
||||||
};
|
enable = true;
|
||||||
configurations.example = {
|
applications.hello.enable = true;
|
||||||
enable = true;
|
};
|
||||||
applications.hello.enable = true;
|
};
|
||||||
|
example-deployment = mkOption {
|
||||||
|
type = nixops4Deployment;
|
||||||
|
readOnly = true;
|
||||||
|
default = config.environments.single-nixos-vm.deployment config.example-configuration;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -39,7 +58,8 @@ in
|
||||||
{
|
{
|
||||||
|
|
||||||
};
|
};
|
||||||
expected = {
|
expected =
|
||||||
};
|
{
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,11 @@ let
|
||||||
deferredModuleWith
|
deferredModuleWith
|
||||||
submoduleWith
|
submoduleWith
|
||||||
submodule
|
submodule
|
||||||
|
optionType
|
||||||
|
functionTo
|
||||||
;
|
;
|
||||||
|
|
||||||
functionType = import ./interface.nix;
|
functionType = import ./function.nix;
|
||||||
application-resources = {
|
application-resources = {
|
||||||
options.resources = mkOption {
|
options.resources = mkOption {
|
||||||
type = attrsOf (
|
type = attrsOf (
|
||||||
|
@ -39,11 +41,11 @@ in
|
||||||
_class = "fediversity-resource";
|
_class = "fediversity-resource";
|
||||||
options = {
|
options = {
|
||||||
consumer = mkOption {
|
consumer = mkOption {
|
||||||
description = "Configuration of the resource by an application, a description of how the resource is consumed";
|
description = "Options for declaring resource requirements by an application, a description of how the resource is consumed";
|
||||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-consumer"; } ]; };
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-consumer"; } ]; };
|
||||||
};
|
};
|
||||||
provider = mkOption {
|
provider = mkOption {
|
||||||
description = "Configuration of the resource by the hosting provider, a description of how the resource is made available";
|
description = "Options for configuring the resource for the hosting provider, a description of how the resource is made available";
|
||||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-provider"; } ]; };
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-provider"; } ]; };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -57,18 +59,25 @@ in
|
||||||
submodule (application: {
|
submodule (application: {
|
||||||
_class = "fediversity-application";
|
_class = "fediversity-application";
|
||||||
options = {
|
options = {
|
||||||
|
description = mkOption {
|
||||||
|
description = "Description to be shown in the application overview";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
module = mkOption {
|
module = mkOption {
|
||||||
description = "Operator-facing configuration options for the application";
|
description = "Operator-facing configuration options for the application";
|
||||||
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
type = deferredModuleWith { staticModules = [ { _class = "fediversity-application-config"; } ]; };
|
||||||
};
|
};
|
||||||
config-mapping = mkOption {
|
implementation = mkOption {
|
||||||
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
|
||||||
type = application.config.function.implementation;
|
type = application.config.config-mapping.function-type;
|
||||||
};
|
};
|
||||||
# TODO: somewhere we still need to
|
resources = mkOption {
|
||||||
# - apply = { implementation = config-mapping; input = <application configuration value from operator>; }
|
description = "Compute resources required by an application";
|
||||||
# - apply.output (applications required by resources)
|
type = functionTo application.config.config-mapping.output-type;
|
||||||
function = mkOption {
|
readOnly = true;
|
||||||
|
default = input: (application.config.implementation input).output;
|
||||||
|
};
|
||||||
|
config-mapping = mkOption {
|
||||||
description = "Function type for the mapping from application configuration to required resources";
|
description = "Function type for the mapping from application configuration to required resources";
|
||||||
type = submodule functionType;
|
type = submodule functionType;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
@ -97,35 +106,57 @@ in
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
resource-mapping = mkOption {
|
implementation = mkOption {
|
||||||
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
description = "Mapping of resources required by applications to available resources; the result can be deployed";
|
||||||
type = environment.config.function.implementation;
|
type = environment.config.resource-mapping.function-type;
|
||||||
};
|
};
|
||||||
# TODO: somewhere we still need to
|
resource-mapping = mkOption {
|
||||||
# - apply = { implementation = resource-mapping; input = <resource requirements of configured applications>; }
|
|
||||||
# - apply.output (deployment)
|
|
||||||
function = mkOption {
|
|
||||||
description = "Function type for the mapping from resources to a (NixOps4) deployment";
|
description = "Function type for the mapping from resources to a (NixOps4) deployment";
|
||||||
type = submodule functionType;
|
type = submodule functionType;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = {
|
default = {
|
||||||
input-type = application-resources;
|
input-type = application-resources;
|
||||||
output-type = submodule nixops4Deployment;
|
output-type = nixops4Deployment;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
deployment = mkOption {
|
||||||
|
description = "Generate a deployment from a configuration";
|
||||||
|
type = functionTo environment.config.resource-mapping.output-type;
|
||||||
|
readOnly = true;
|
||||||
|
default =
|
||||||
|
cfg:
|
||||||
|
# TODO: check cfg.enable.true
|
||||||
|
let
|
||||||
|
required-resources = lib.mapAttrs (
|
||||||
|
name: application-settings: config.applications.${name}.resources application-settings
|
||||||
|
) cfg.applications;
|
||||||
|
in
|
||||||
|
(environment.config.implementation required-resources).output;
|
||||||
|
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
configurations = mkOption {
|
configuration = mkOption {
|
||||||
description = "Application configurations set by operators";
|
description = "Configuration type declaring options to be set by operators";
|
||||||
type = attrsOf (submodule {
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = submodule (configuration: {
|
||||||
options = {
|
options = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
description = "Whether to enable the configuration";
|
description = "Whether to enable the configuration";
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
};
|
};
|
||||||
applications = mapAttrs (name: application: submodule application.module) config.applications;
|
applications = lib.mapAttrs (
|
||||||
|
name: application:
|
||||||
|
mkOption {
|
||||||
|
description = application.description;
|
||||||
|
type = submodule application.module;
|
||||||
|
default = { };
|
||||||
|
}
|
||||||
|
) config.applications;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
30
deployment/function.nix
Normal file
30
deployment/function.nix
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/**
|
||||||
|
Modular function type
|
||||||
|
*/
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
input-type = mkOption {
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
output-type = mkOption {
|
||||||
|
type = deferredModule;
|
||||||
|
};
|
||||||
|
function-type = mkOption {
|
||||||
|
type = optionType;
|
||||||
|
readOnly = true;
|
||||||
|
default = functionTo (
|
||||||
|
submodule (function: {
|
||||||
|
options = {
|
||||||
|
input = mkOption {
|
||||||
|
type = submodule config.input-type;
|
||||||
|
};
|
||||||
|
output = mkOption {
|
||||||
|
type = submodule config.output-type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,49 +0,0 @@
|
||||||
/**
|
|
||||||
Modular function type
|
|
||||||
*/
|
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
options = {
|
|
||||||
input-type = mkOption {
|
|
||||||
type = deferredModule;
|
|
||||||
};
|
|
||||||
output-type = mkOption {
|
|
||||||
type = deferredModule;
|
|
||||||
};
|
|
||||||
implementation = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
readOnly = true;
|
|
||||||
default = implementationTo (
|
|
||||||
submodule (implementation: {
|
|
||||||
options = {
|
|
||||||
input = mkOption {
|
|
||||||
type = submodule config.input-type;
|
|
||||||
};
|
|
||||||
output = mkOption {
|
|
||||||
type = submodule config.output-type;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
apply = mkOption {
|
|
||||||
type = optionType;
|
|
||||||
readOnly = true;
|
|
||||||
default = submodule (apply: {
|
|
||||||
options = {
|
|
||||||
implementation = mkOption {
|
|
||||||
type = config.implementation;
|
|
||||||
};
|
|
||||||
input = mkOption {
|
|
||||||
type = submodule config.input-type;
|
|
||||||
};
|
|
||||||
output = mkOption {
|
|
||||||
type = submodule config.output-type;
|
|
||||||
readOnly = true;
|
|
||||||
default = (apply.config.implementation apply.config.input).output;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue