move applications from config to options to actually type-check application configurations

This commit is contained in:
Kiara Grouwstra 2025-07-01 14:20:32 +02:00
parent dbd3e90238
commit 1d519dceab
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
4 changed files with 47 additions and 33 deletions

View file

@ -0,0 +1,19 @@
{
lib,
...
}:
let
applications = [
"mastodon"
];
in
{
options = lib.genAttrs applications (
k:
# TODO: how to type entries here to conform to some common structure?
lib.mkOption {
description = "configuration options for ${k}";
type = lib.types.submodule ./${k};
}
);
}

View file

@ -0,0 +1,19 @@
{
config,
lib,
...
}:
{
options =
{
fediversity.domain = lib.mkOption {
type = lib.types.str;
default = "fediversity.tld";
};
}
// import ../../../services/fediversity/sharedOptions.nix {
inherit config lib;
serviceName = "mastodon";
serviceDocName = "Mastodon";
};
}

View file

@ -34,16 +34,13 @@ in
authentication.password = ""; authentication.password = "";
}; };
}; };
applications.foo.module =
{ pkgs, ... }:
{
environment.systemPackages = [
pkgs.hello
];
};
deployments.baz = { deployments.baz = {
module = { };
inherit runtime-environment; inherit runtime-environment;
application-configuration = {
mastodon = {
enable = true;
};
};
}; };
migrations.boo = { migrations.boo = {
inherit runtime-environment; inherit runtime-environment;
@ -55,14 +52,12 @@ in
{ {
has-provider = lib.isAttrs example.providers.ssh-host; has-provider = lib.isAttrs example.providers.ssh-host;
has-resource = lib.isAttrs example.resources.bar.runtime-environment.ssh-host.module; has-resource = lib.isAttrs example.resources.bar.runtime-environment.ssh-host.module;
has-application = lib.isAttrs example.applications.foo.module; has-deployment = example.deployments.baz.application-configuration.mastodon.enable == true;
has-deployment = lib.isAttrs example.deployments.baz.module;
has-migration = lib.isAttrs example.migrations.boo.deployment; has-migration = lib.isAttrs example.migrations.boo.deployment;
}; };
expected = { expected = {
has-provider = true; has-provider = true;
has-resource = true; has-resource = true;
has-application = true;
has-deployment = true; has-deployment = true;
has-migration = true; has-migration = true;
}; };

View file

@ -4,6 +4,7 @@
... ...
}: }:
let let
applications = ./applications; # how to make this configurable?
inherit (lib) inherit (lib)
attrNames attrNames
mapAttrs mapAttrs
@ -100,32 +101,16 @@ let
type = runtime-environment; type = runtime-environment;
}; };
}; };
application = submoduleWith {
description = "A Fediversity application";
modules = [
{
options = {
module = mkOption {
description = ''
The NixOS module to configure the application.
'';
type = deferredModule;
};
};
}
];
};
deployment = submoduleWith { deployment = submoduleWith {
description = "A deployment of a configuration of applications to a run-time environment"; description = "A deployment of a configuration of applications to a run-time environment";
modules = [ modules = [
{ {
options = { options = {
# the `applications` option consists of configuration for the above applications application-configuration = mkOption {
module = mkOption {
description = '' description = ''
Configuration to be deployed Configuration to be deployed
''; '';
type = deferredModule; type = submodule applications;
}; };
runtime-environment = mkOption { runtime-environment = mkOption {
description = "The run-time environment to deploy to"; description = "The run-time environment to deploy to";
@ -163,10 +148,6 @@ in
description = "Collection of resources for use in Fediversity applications"; description = "Collection of resources for use in Fediversity applications";
type = attrsOf resource; type = attrsOf resource;
}; };
applications = mkOption {
description = "Collection of (available) Fediversity applications";
type = attrsOf application;
};
deployments = mkOption { deployments = mkOption {
description = "Deployment of a configuration of applications to a run-time environment"; description = "Deployment of a configuration of applications to a run-time environment";
type = attrsOf deployment; type = attrsOf deployment;