forked from Fediversity/Fediversity
WIP: add data model test using selfhostblocks
status: properly test that this works
This commit is contained in:
parent
9d903f3ef7
commit
59f56c9436
3 changed files with 199 additions and 0 deletions
|
@ -21,6 +21,12 @@ jobs:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix'
|
- run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix'
|
||||||
|
|
||||||
|
check-shb:
|
||||||
|
runs-on: native
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: nix-shell --run 'nix-unit ./deployment/shb-test.nix'
|
||||||
|
|
||||||
check-mastodon:
|
check-mastodon:
|
||||||
runs-on: native
|
runs-on: native
|
||||||
steps:
|
steps:
|
||||||
|
|
177
deployment/shb-test.nix
Normal file
177
deployment/shb-test.nix
Normal file
|
@ -0,0 +1,177 @@
|
||||||
|
let
|
||||||
|
sources = import ../npins;
|
||||||
|
inherit (import ../default.nix { }) pkgs inputs;
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
eval =
|
||||||
|
module:
|
||||||
|
(lib.evalModules {
|
||||||
|
specialArgs = {
|
||||||
|
inherit inputs;
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
module
|
||||||
|
./data-model.nix
|
||||||
|
];
|
||||||
|
}).config;
|
||||||
|
nixops4Deployment = inputs.nixops4.modules.nixops4Deployment.default;
|
||||||
|
contracts = pkgs.callPackage "${sources.selfhostblocks}/modules/contracts" { };
|
||||||
|
inherit (inputs.nixops4.lib) mkDeployment;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
_class = "nix-unit";
|
||||||
|
|
||||||
|
test-eval = {
|
||||||
|
expr =
|
||||||
|
let
|
||||||
|
fediversity = eval (
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
resources.backup = {
|
||||||
|
description = "handle SelfHostBlocks backup requests";
|
||||||
|
request =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
_class = "fediversity-resource-request";
|
||||||
|
options = {
|
||||||
|
req = mkOption {
|
||||||
|
type = contracts.backup.contract.request;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
policy =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
_class = "fediversity-resource-policy";
|
||||||
|
options = {
|
||||||
|
block = mkOption {
|
||||||
|
description = ''
|
||||||
|
the environment's SHB implementation handling back-up requests,
|
||||||
|
using any of: https://shb.skarabox.com/contracts-backup.html#contract-backup-providers.
|
||||||
|
takes the form of a function from a request to NixOS configuration handling the back-up request.
|
||||||
|
'';
|
||||||
|
type = types.functionTo types.raw;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
resource-type = types.raw; # TODO: splice out the user type from NixOS
|
||||||
|
apply =
|
||||||
|
requests:
|
||||||
|
lib.mkMerge (
|
||||||
|
lib.mapAttrsToList (name: request: config.block { inherit name request; }) requests.resources
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
applications.bar =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
description = "application to test SHB backups";
|
||||||
|
module =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
enable = lib.mkEnableOption "shb test";
|
||||||
|
backup = mkOption {
|
||||||
|
default = { };
|
||||||
|
type = lib.types.submodule {
|
||||||
|
options = contracts.backup.mkRequester {
|
||||||
|
sourceDirectories = [
|
||||||
|
"/var/lock" # some small dir
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
implementation = cfg: {
|
||||||
|
input = cfg;
|
||||||
|
output = lib.optionalAttrs cfg.enable {
|
||||||
|
resources.hello.req = {
|
||||||
|
inherit (cfg) backup;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
environments.single-nixos-vm =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
resources.operator-environment.backup.block =
|
||||||
|
{ name, request }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
"${sources.selfhostblocks}/modules/blocks/restic.nix"
|
||||||
|
];
|
||||||
|
shb.restic.instances.${name} = {
|
||||||
|
inherit request;
|
||||||
|
settings = {
|
||||||
|
enable = true;
|
||||||
|
repository.path = "/srv/backup/restic/fediversity-test/${name}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
implementation = requests: {
|
||||||
|
input = requests;
|
||||||
|
output =
|
||||||
|
{ providers, ... }:
|
||||||
|
{
|
||||||
|
providers = {
|
||||||
|
inherit (inputs.nixops4.modules.nixops4Provider) local;
|
||||||
|
};
|
||||||
|
resources.the-machine = {
|
||||||
|
type = providers.local.exec;
|
||||||
|
imports = [
|
||||||
|
inputs.nixops4-nixos.modules.nixops4Resource.nixos
|
||||||
|
];
|
||||||
|
nixos.module = { ... }: config.resources.baz.backup.apply requests;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
options = {
|
||||||
|
example-configuration = mkOption {
|
||||||
|
type = config.configuration;
|
||||||
|
readOnly = true;
|
||||||
|
default = {
|
||||||
|
enable = true;
|
||||||
|
applications = {
|
||||||
|
bar = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
example-deployment = mkOption {
|
||||||
|
type = types.submodule nixops4Deployment;
|
||||||
|
readOnly = true;
|
||||||
|
default = config.environments.single-nixos-vm.deployment config.example-configuration;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
result = mkDeployment {
|
||||||
|
modules = [
|
||||||
|
(fediversity.environments.single-nixos-vm.deployment fediversity.example-configuration)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
deployment = {
|
||||||
|
inherit (result) _type;
|
||||||
|
deploymentFunction = lib.isFunction result.deploymentFunction;
|
||||||
|
getProviders = lib.isFunction result.getProviders;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
expected = {
|
||||||
|
deployment = {
|
||||||
|
_type = "nixops4Deployment";
|
||||||
|
deploymentFunction = true;
|
||||||
|
getProviders = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -150,6 +150,22 @@
|
||||||
"revision": "f33a4d26226c05d501b9d4d3e5e60a3a59991921",
|
"revision": "f33a4d26226c05d501b9d4d3e5e60a3a59991921",
|
||||||
"url": "https://github.com/nixos/nixpkgs/archive/f33a4d26226c05d501b9d4d3e5e60a3a59991921.tar.gz",
|
"url": "https://github.com/nixos/nixpkgs/archive/f33a4d26226c05d501b9d4d3e5e60a3a59991921.tar.gz",
|
||||||
"hash": "1b6dm1sn0bdpcsmxna0zzspjaixa2dald08005fry5jrbjvwafdj"
|
"hash": "1b6dm1sn0bdpcsmxna0zzspjaixa2dald08005fry5jrbjvwafdj"
|
||||||
|
},
|
||||||
|
"selfhostblocks": {
|
||||||
|
"type": "GitRelease",
|
||||||
|
"repository": {
|
||||||
|
"type": "GitHub",
|
||||||
|
"owner": "ibizaman",
|
||||||
|
"repo": "selfhostblocks"
|
||||||
|
},
|
||||||
|
"pre_releases": false,
|
||||||
|
"version_upper_bound": null,
|
||||||
|
"release_prefix": null,
|
||||||
|
"submodules": false,
|
||||||
|
"version": "v0.4.0",
|
||||||
|
"revision": "00fc98da3528ab270e987feb0f0579da89efd6f0",
|
||||||
|
"url": "https://api.github.com/repos/ibizaman/selfhostblocks/tarball/v0.4.0",
|
||||||
|
"hash": "1jp2qsib3xmlcbzz4d11xj5lbyn6a6zyp5n1ag5w3fabrichzvv7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": 5
|
"version": 5
|
||||||
|
|
Loading…
Add table
Reference in a new issue