data model: add run-time configuration

This commit is contained in:
Kiara Grouwstra 2025-06-23 09:06:52 +02:00
parent 486b316885
commit 8b2ee21dbe
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 62 additions and 34 deletions

View file

@ -11,17 +11,18 @@ let
}).config; }).config;
in in
{ {
_class = "nix-unit";
test-eval = { test-eval = {
expr = expr =
let let
example = eval { example = eval {
runtime-environments.bar.nixos = { runtime-configurations.nixos =
module = { ... }:
{ ... }: {
{ system.stateVersion = "25.05";
system.stateVersion = "25.05"; };
}; runtime-environments.bar.nixos = { };
};
applications.foo = { applications.foo = {
module = module =
{ pkgs, ... }: { pkgs, ... }:
@ -34,11 +35,13 @@ in
}; };
in in
{ {
has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module; has-runtime-configuration = lib.isAttrs example.runtime-configurations.nixos;
has-runtime-environment = lib.isAttrs example.runtime-environments.bar.nixos.module;
has-application = lib.isAttrs example.applications.foo.module; has-application = lib.isAttrs example.applications.foo.module;
}; };
expected = { expected = {
has-runtime = true; has-runtime-configuration = true;
has-runtime-environment = true;
has-application = true; has-application = true;
}; };
}; };

View file

@ -1,43 +1,68 @@
{ {
lib, lib,
config,
... ...
}: }:
let let
inherit (lib) types mkOption; inherit (lib) attrNames mkOption genAttrs;
in inherit (lib.types)
with types; attrsOf
{ attrTag
options = { deferredModule
runtime-environments = mkOption { submoduleWith
description = "Collection of runtime environments into which applications can be deployed"; ;
type = attrsOf (attrTag { runtime-configuration = mkOption {
nixos = mkOption { description = "The NixOS module of a run-time environment";
description = "A single NixOS machine"; type = deferredModule;
type = submodule { default = {
options = { _class = "nixos";
module = mkOption {
description = "The NixOS module describing the base configuration for that machine";
type = deferredModule;
};
};
};
};
});
}; };
applications = mkOption { };
description = "Collection of Fediversity applications"; runtime-environment = attrTag {
type = attrsOf (submoduleWith { nixos = mkOption {
type = submoduleWith {
modules = [ modules = [
{ {
options = { options = {
module = mkOption { module = mkOption {
description = "The NixOS module for that application, for configuring that application"; description = "The NixOS module of the run-time environment";
type = deferredModule; type = deferredModule;
default = config.runtime-configurations.nixos;
readOnly = true;
}; };
}; };
} }
]; ];
}); };
};
};
application = submoduleWith {
description = "A Fediversity application";
modules = [
{
options = {
module = mkOption {
description = "The NixOS module for that application, for configuring that application";
type = deferredModule;
};
};
}
];
};
in
{
options = {
runtime-configurations = mkOption {
description = "Collection of runtime environments into which applications can be deployed";
type = attrTag (genAttrs (attrNames runtime-environment.nestedTypes) (_: runtime-configuration));
};
runtime-environments = mkOption {
description = "Collection of runtime environments into which applications can be deployed";
type = attrsOf runtime-environment;
};
applications = mkOption {
description = "Collection of Fediversity applications";
type = attrsOf application;
}; };
}; };
} }