add data model entity: application (#387)

part of #103.

Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Reviewed-on: Fediversity/Fediversity#387
Co-authored-by: Kiara Grouwstra <kiara@procolix.eu>
Co-committed-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-06-17 17:11:52 +02:00 committed by Valentin Gagarin
parent 4801433ae0
commit 939f9d961d
6 changed files with 118 additions and 3 deletions

View file

@ -15,6 +15,12 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: nix-build -A tests - 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: check-peertube:
runs-on: native runs-on: native
steps: steps:

View file

@ -154,6 +154,3 @@ details as to what they are for. As an overview:
- [`services/`](./services) contains our effort to make Fediverse applications - [`services/`](./services) contains our effort to make Fediverse applications
work seemlessly together in our specific setting. work seemlessly together in our specific setting.
- [`website/`](./website) contains the framework and the content of [the
Fediversity website](https://fediversity.eu/)

View file

@ -41,6 +41,23 @@ in
shell = pkgs.mkShellNoCC { shell = pkgs.mkShellNoCC {
inherit (pre-commit-check) shellHook; inherit (pre-commit-check) shellHook;
buildInputs = pre-commit-check.enabledPackages; 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 = { tests = {

View file

@ -3,6 +3,13 @@
This directory contains work to generate a full Fediversity deployment from a minimal configuration. 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. 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 ## Checks
There are three levels of deployment checks: `basic`, `cli`, `panel`. There are three levels of deployment checks: `basic`, `cli`, `panel`.

View file

@ -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;
};
};
}

43
deployment/data-model.nix Normal file
View file

@ -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;
};
};
}
];
});
};
};
}