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;
in
{
_class = "nix-unit";
test-eval = {
expr =
let
example = eval {
runtime-environments.bar.nixos = {
module =
{ ... }:
{
system.stateVersion = "25.05";
};
};
runtime-configurations.nixos =
{ ... }:
{
system.stateVersion = "25.05";
};
runtime-environments.bar.nixos = { };
applications.foo = {
module =
{ pkgs, ... }:
@ -34,11 +35,13 @@ 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;
};
expected = {
has-runtime = true;
has-runtime-configuration = true;
has-runtime-environment = true;
has-application = true;
};
};

View file

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