diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 18925ab8..203eca03 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -15,6 +15,12 @@ jobs: - uses: actions/checkout@v4 - run: nix-build -A tests + check-data-model: + runs-on: native + steps: + - uses: actions/checkout@v4 + - run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix' + check-peertube: runs-on: native steps: diff --git a/README.md b/README.md index 3b19751c..d0a94395 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,3 @@ details as to what they are for. As an overview: - [`services/`](./services) contains our effort to make Fediverse applications work seemlessly together in our specific setting. - -- [`website/`](./website) contains the framework and the content of [the - Fediversity website](https://fediversity.eu/) diff --git a/default.nix b/default.nix index 4c71ec49..7c536a03 100644 --- a/default.nix +++ b/default.nix @@ -41,6 +41,23 @@ in shell = pkgs.mkShellNoCC { inherit (pre-commit-check) shellHook; buildInputs = pre-commit-check.enabledPackages; + packages = + let + test-loop = pkgs.writeShellApplication { + name = "test-loop"; + runtimeInputs = [ + pkgs.watchexec + pkgs.nix-unit + ]; + text = '' + watchexec -w ${builtins.toString ./.} -- nix-unit ${builtins.toString ./deployment/data-model-test.nix} "$@" + ''; + }; + in + [ + pkgs.nix-unit + test-loop + ]; }; tests = { diff --git a/deployment/README.md b/deployment/README.md index f3e24276..784273dd 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -3,6 +3,13 @@ This directory contains work to generate a full Fediversity deployment from a minimal configuration. This is different from [`../services/`](../services) that focuses on one machine, providing a polished and unified interface to different Fediverse services. +## Data model + +The core piece of the project is the [Fediversity data model](./data-model.nix), which describes all entities and their interactions. + +What can be done with it is exemplified in the [evaluation tests](./data-model-test.nix). +Run `test-loop` in the development environment when hacking on the data model or adding tests. + ## Checks There are three levels of deployment checks: `basic`, `cli`, `panel`. diff --git a/deployment/data-model-test.nix b/deployment/data-model-test.nix new file mode 100644 index 00000000..17c85f77 --- /dev/null +++ b/deployment/data-model-test.nix @@ -0,0 +1,45 @@ +let + inherit (import ../default.nix { }) pkgs; + inherit (pkgs) lib; + eval = + module: + (lib.evalModules { + modules = [ + module + ./data-model.nix + ]; + }).config; +in +{ + test-eval = { + expr = + let + example = eval { + runtime-environments.bar.nixos = { + module = + { ... }: + { + system.stateVersion = "25.05"; + }; + }; + applications.foo = { + module = + { pkgs, ... }: + { + environment.systemPackages = [ + pkgs.hello + ]; + }; + }; + }; + in + { + has-runtime = lib.isAttrs example.runtime-environments.bar.nixos.module; + has-application = lib.isAttrs example.applications.foo.module; + }; + expected = { + has-runtime = true; + has-application = true; + }; + }; +} diff --git a/deployment/data-model.nix b/deployment/data-model.nix new file mode 100644 index 00000000..af867d55 --- /dev/null +++ b/deployment/data-model.nix @@ -0,0 +1,43 @@ +{ + lib, + ... +}: +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; + }; + }; + }; + }; + }); + }; + applications = mkOption { + description = "Collection of Fediversity applications"; + type = attrsOf (submoduleWith { + modules = [ + { + options = { + module = mkOption { + description = "The NixOS module for that application, for configuring that application"; + type = deferredModule; + }; + }; + } + ]; + }); + }; + }; +}