From 1d519dceab91225a170751829f5f3b6f103abc9a Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Tue, 1 Jul 2025 14:20:32 +0200 Subject: [PATCH] move `applications` from `config` to `options` to actually type-check application configurations --- deployment/applications/default.nix | 19 +++++++++++++++ deployment/applications/mastodon/default.nix | 19 +++++++++++++++ deployment/data-model-test.nix | 17 +++++-------- deployment/data-model.nix | 25 +++----------------- 4 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 deployment/applications/default.nix create mode 100644 deployment/applications/mastodon/default.nix diff --git a/deployment/applications/default.nix b/deployment/applications/default.nix new file mode 100644 index 00000000..21d81583 --- /dev/null +++ b/deployment/applications/default.nix @@ -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}; + } + ); +} diff --git a/deployment/applications/mastodon/default.nix b/deployment/applications/mastodon/default.nix new file mode 100644 index 00000000..8c84cf84 --- /dev/null +++ b/deployment/applications/mastodon/default.nix @@ -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"; + }; +} diff --git a/deployment/data-model-test.nix b/deployment/data-model-test.nix index dcaf8a41..778ce702 100644 --- a/deployment/data-model-test.nix +++ b/deployment/data-model-test.nix @@ -34,16 +34,13 @@ in authentication.password = ""; }; }; - applications.foo.module = - { pkgs, ... }: - { - environment.systemPackages = [ - pkgs.hello - ]; - }; deployments.baz = { - module = { }; inherit runtime-environment; + application-configuration = { + mastodon = { + enable = true; + }; + }; }; migrations.boo = { inherit runtime-environment; @@ -55,14 +52,12 @@ in { has-provider = lib.isAttrs example.providers.ssh-host; has-resource = lib.isAttrs example.resources.bar.runtime-environment.ssh-host.module; - has-application = lib.isAttrs example.applications.foo.module; - has-deployment = lib.isAttrs example.deployments.baz.module; + has-deployment = example.deployments.baz.application-configuration.mastodon.enable == true; has-migration = lib.isAttrs example.migrations.boo.deployment; }; expected = { has-provider = true; has-resource = true; - has-application = true; has-deployment = true; has-migration = true; }; diff --git a/deployment/data-model.nix b/deployment/data-model.nix index 502071e1..57c71c3b 100644 --- a/deployment/data-model.nix +++ b/deployment/data-model.nix @@ -4,6 +4,7 @@ ... }: let + applications = ./applications; # how to make this configurable? inherit (lib) attrNames mapAttrs @@ -100,32 +101,16 @@ let 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 { description = "A deployment of a configuration of applications to a run-time environment"; modules = [ { options = { - # the `applications` option consists of configuration for the above applications - module = mkOption { + application-configuration = mkOption { description = '' Configuration to be deployed ''; - type = deferredModule; + type = submodule applications; }; runtime-environment = mkOption { description = "The run-time environment to deploy to"; @@ -163,10 +148,6 @@ in description = "Collection of resources for use in Fediversity applications"; type = attrsOf resource; }; - applications = mkOption { - description = "Collection of (available) Fediversity applications"; - type = attrsOf application; - }; deployments = mkOption { description = "Deployment of a configuration of applications to a run-time environment"; type = attrsOf deployment;