Compare commits

..

No commits in common. "f8d1be9f6e5b16d98284b098635ce887a942b34e" and "5c97e3597009c3b80bb8db5fa332b12545700d74" have entirely different histories.

4 changed files with 104 additions and 124 deletions

View file

@ -1,7 +1,6 @@
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 {
@ -13,53 +12,57 @@ let
./data-model.nix ./data-model.nix
]; ];
}).config; }).config;
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
in in
{ {
test-eval = { test-eval = {
expr = expr =
let let
fediversity = eval ( example = eval (
{ config, ... }: { config, ... }:
{ {
config = { providers.single-ssh-host =
resources.nixos = { { ... }:
# TODO: consumer = ? {
# TODO: provider = ? system.stateVersion = "25.05";
}; };
applications.hello = { resources.bar.runtime-environment.single-ssh-host = {
description = ''Command-line tool that will print "Hello, world!" on the terminal''; ssh = {
# TODO: module = ? host = "localhost";
# TODO: config=mapping = ? username = "root";
}; authentication.password = "";
environments.single-nixos-vm = {
# TODO: resources = ?
# TODO: resource-mapping = ?
}; };
}; };
options = { applications.foo.module =
example-configuration = mkOption { { pkgs, ... }:
type = config.configuration; {
readOnly = true; environment.systemPackages = [
default = { pkgs.hello
enable = true; ];
applications.hello.enable = true;
}; };
deployments.baz = {
module = { };
runtime-environment = config.resources.bar.runtime-environment;
}; };
example-deployment = mkOption { migrations.boo = {
type = nixops4Deployment; deployment = config.deployments.baz;
readOnly = true; runtime-environment = config.resources.bar.runtime-environment;
default = config.environments.single-nixos-vm.deployment config.example-configuration;
};
}; };
} }
); );
in in
{ {
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 = expected = {
{ has-provider = true;
has-resource = true;
has-application = true;
has-deployment = true;
has-migration = true;
}; };
}; };
} }

View file

@ -5,18 +5,19 @@
... ...
}: }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption;
inherit (lib.types) inherit (lib.types)
attrsOf attrsOf
attrTag attrTag
deferredModuleWith deferredModuleWith
mergeTypes
nullOr
submoduleWith submoduleWith
submodule submodule
optionType str
functionTo
; ;
functionType = import ./function.nix; functionType = import ./interface.nix;
application-resources = { application-resources = {
options.resources = mkOption { options.resources = mkOption {
type = attrsOf ( type = attrsOf (
@ -41,11 +42,11 @@ in
_class = "fediversity-resource"; _class = "fediversity-resource";
options = { options = {
consumer = mkOption { consumer = mkOption {
description = "Options for declaring resource requirements by an application, a description of how the resource is consumed"; description = "Configuration of the resource 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 = "Options for configuring the resource for the hosting provider, a description of how the resource is made available"; 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"; } ]; }; type = deferredModuleWith { staticModules = [ { _class = "fediversity-resource-provider"; } ]; };
}; };
}; };
@ -59,25 +60,18 @@ 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"; } ]; };
}; };
implementation = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.config-mapping.function-type;
};
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;
};
config-mapping = mkOption { config-mapping = mkOption {
description = "Mapping of application configuration to deployment resources, a description of what an application needs to run";
type = application.config.function.implementation;
};
# TODO: somewhere we still need to
# - apply = { implementation = config-mapping; input = <application configuration value from operator>; }
# - apply.output
function = 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;
@ -106,59 +100,23 @@ in
) )
); );
}; };
implementation = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed";
type = environment.config.resource-mapping.function-type;
};
resource-mapping = mkOption { resource-mapping = mkOption {
description = "Mapping of resources required by applications to available resources; the result can be deployed";
type = environment.config.function.implementation;
# TODO: type = consumer-resources /* same as the output of application.config-mapping, should be in a `let` */ -> nixops4Deployment
};
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 = nixops4Deployment; output-type = submodule 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;
};
}; };
}) })
); );
}; };
configuration = mkOption {
description = "Configuration type declaring options to be set by operators";
type = optionType;
readOnly = true;
default = submodule (configuration: {
options = {
enable = mkOption {
description = "Whether to enable the configuration";
type = types.bool;
default = false;
};
applications = lib.mapAttrs (
name: application:
mkOption {
description = application.description;
type = submodule application.module;
default = { };
}
) config.applications;
};
});
};
}; };
} }

View file

@ -1,30 +0,0 @@
/**
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;
};
};
})
);
};
};
}

49
deployment/interface.nix Normal file
View file

@ -0,0 +1,49 @@
/**
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;
};
};
});
};
};
}