revert submodule wrapper to align with module functions already doing types #2

Closed
kiara wants to merge 37 commits from kiara/Fediversity:fix-submodule-type into main
2 changed files with 29 additions and 41 deletions
Showing only changes of commit 7a667c7517 - Show all commits

View file

@ -17,52 +17,29 @@ in
test-eval = {
expr =
let
example = eval (
fediversity = eval (
{ config, ... }:
{
providers.single-ssh-host =
{ ... }:
{
system.stateVersion = "25.05";
};
resources.bar.runtime-environment.single-ssh-host = {
ssh = {
host = "localhost";
username = "root";
authentication.password = "";
};
resources.nixos = {
};
applications.foo.module =
{ pkgs, ... }:
{
environment.systemPackages = [
pkgs.hello
];
};
deployments.baz = {
module = { };
runtime-environment = config.resources.bar.runtime-environment;
applications.hello = {
};
migrations.boo = {
deployment = config.deployments.baz;
runtime-environment = config.resources.bar.runtime-environment;
environments.single-nixos-vm = {
};
configurations.example = {
enable = true;
applications.hello.enable = true;
};
}
);
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 = {
has-provider = true;
has-resource = true;
has-application = true;
has-deployment = true;
has-migration = true;
};
};
}

View file

@ -5,16 +5,13 @@
...
}:
let
inherit (lib) mkOption;
inherit (lib) mkOption types;
inherit (lib.types)
attrsOf
attrTag
deferredModuleWith
mergeTypes
nullOr
submoduleWith
submodule
str
;
functionType = import ./interface.nix;
@ -70,7 +67,7 @@ in
};
# TODO: somewhere we still need to
# - apply = { implementation = config-mapping; input = <application configuration value from operator>; }
# - apply.output
# - apply.output (applications required by resources)
function = mkOption {
description = "Function type for the mapping from application configuration to required resources";
type = submodule functionType;
@ -103,8 +100,10 @@ in
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
};
# TODO: somewhere we still need to
# - 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";
type = submodule functionType;
@ -118,5 +117,17 @@ in
})
);
};
configurations = mkOption {
description = "Application configurations set by operators";
type = attrsOf (submodule {
options = {
enable = mkOption {
description = "Whether to enable the configuration";
type = types.bool;
};
applications = mapAttrs (name: application: submodule application.module) config.applications;
};
});
};
};
}