From 71b5201527b4af23e2ac2a511fe3c757c911d662 Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Tue, 17 Jun 2025 12:12:16 +0200 Subject: [PATCH] add data model entity: application --- .forgejo/workflows/ci.yaml | 2 +- default.nix | 2 +- deployment/application.nix | 42 +++++++++++++++++++++++++++++++++++ test.nix | 45 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 deployment/application.nix create mode 100644 test.nix diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index f7f0a438..60d30977 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: runs-on: native steps: - uses: actions/checkout@v4 - - run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix' + - run: nix-shell --run 'nix-unit ./test.nix' check-peertube: runs-on: native diff --git a/default.nix b/default.nix index 7c536a03..09da3710 100644 --- a/default.nix +++ b/default.nix @@ -50,7 +50,7 @@ in pkgs.nix-unit ]; text = '' - watchexec -w ${builtins.toString ./.} -- nix-unit ${builtins.toString ./deployment/data-model-test.nix} "$@" + watchexec -w ${builtins.toString ./.} -- nix-unit ${builtins.toString ./test.nix} "$@" ''; }; in diff --git a/deployment/application.nix b/deployment/application.nix new file mode 100644 index 00000000..12326907 --- /dev/null +++ b/deployment/application.nix @@ -0,0 +1,42 @@ +{ + lib, + ... +}: +let + inherit (lib) types mkOption; +in +with types; +{ + options = { + runtime-environments = mkOption { + type = attrsOf (attrTag { + nixos = mkOption { + type = submodule { + options = { + module = mkOption { + description = "The NixOS module of the run-time environment"; + type = deferredModule; + }; + }; + }; + }; + }); + }; + applications = mkOption { + description = "Collection of NixOS modules, each implementing a Fediversity application"; + type = attrsOf (submoduleWith { + description = "A Fediversity application"; + modules = [ + { + options = { + module = mkOption { + description = "The NixOS module to compose into an operator's configuration"; + type = deferredModule; + }; + }; + } + ]; + }); + }; + }; +} diff --git a/test.nix b/test.nix new file mode 100644 index 00000000..b84ac16c --- /dev/null +++ b/test.nix @@ -0,0 +1,45 @@ +let + inherit (import ./default.nix { }) pkgs; + inherit (pkgs) lib; + eval = + module: + (lib.evalModules { + modules = [ + module + ./deployment/application.nix + ]; + }).config; +in +{ + test-foo = { + expr = + let + example = eval { + runtime-environments.bar.nixos = { + module = + { ... }: + { + system.stateVersion = "25.05"; + }; + }; + applications.foo = { + module = + { pkgs, ... }: + { + environment.systemPackages = [ + pkgs.hello + ]; + }; + }; + }; + in + { + has-runtime = example.runtime-environments.bar.nixos ? module; + has-application = example.applications.foo ? module; + }; + expected = { + has-runtime = true; + has-application = true; + }; + }; +}