WIP: start writing an evaluation test

turns out we also need a collection of configurations, obviously
next: figure out where to wire everything up to obtain a deployment
This commit is contained in:
Valentin Gagarin 2025-07-01 23:59:16 +02:00
parent 5c97e35970
commit 7a667c7517
2 changed files with 29 additions and 41 deletions

View file

@ -17,52 +17,29 @@ in
test-eval = { test-eval = {
expr = expr =
let let
example = eval ( fediversity = eval (
{ config, ... }: { config, ... }:
{ {
providers.single-ssh-host = resources.nixos = {
{ ... }:
{
system.stateVersion = "25.05";
}; };
resources.bar.runtime-environment.single-ssh-host = { applications.hello = {
ssh = {
host = "localhost";
username = "root";
authentication.password = "";
}; };
environments.single-nixos-vm = {
}; };
applications.foo.module = configurations.example = {
{ pkgs, ... }: enable = true;
{ applications.hello.enable = true;
environment.systemPackages = [
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-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,16 +5,13 @@
... ...
}: }:
let let
inherit (lib) mkOption; inherit (lib) mkOption types;
inherit (lib.types) inherit (lib.types)
attrsOf attrsOf
attrTag attrTag
deferredModuleWith deferredModuleWith
mergeTypes
nullOr
submoduleWith submoduleWith
submodule submodule
str
; ;
functionType = import ./interface.nix; functionType = import ./interface.nix;
@ -70,7 +67,7 @@ in
}; };
# TODO: somewhere we still need to # TODO: somewhere we still need to
# - apply = { implementation = config-mapping; input = <application configuration value from operator>; } # - apply = { implementation = config-mapping; input = <application configuration value from operator>; }
# - apply.output # - apply.output (applications required by resources)
function = mkOption { 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;
@ -103,8 +100,10 @@ in
resource-mapping = mkOption { resource-mapping = 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.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 { 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;
@ -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;
};
});
};
}; };
} }