aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-11 12:53:22 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-11 12:53:22 +0200
commit240f724440b08be08bb3202e259d7336d793e385 (patch)
treef648f3605f92877be64b69555146cfe66c9d3398
parentzones/vhack.eu: add nextcloud subdomain (diff)
downloadnixos-server-240f724440b08be08bb3202e259d7336d793e385.zip
{modules,test}/taskchampion-sync: Init
-rw-r--r--modules/by-name/ta/taskchampion-sync/module.nix18
-rw-r--r--tests/by-name/ta/taskchampion-sync/test.nix96
2 files changed, 114 insertions, 0 deletions
diff --git a/modules/by-name/ta/taskchampion-sync/module.nix b/modules/by-name/ta/taskchampion-sync/module.nix
new file mode 100644
index 0000000..84721fe
--- /dev/null
+++ b/modules/by-name/ta/taskchampion-sync/module.nix
@@ -0,0 +1,18 @@
+{
+ config,
+ lib,
+ ...
+}: let
+ cfg = config.vhack.taskchampion-sync;
+in {
+ options.vhack.taskchampion-sync = {
+ enable = lib.mkEnableOption "taskchampion-sync";
+ };
+
+ config = lib.mkIf cfg.enable {
+ services.taskchampion-sync-server = {
+ enable = true;
+ openFirewall = true;
+ };
+ };
+}
diff --git a/tests/by-name/ta/taskchampion-sync/test.nix b/tests/by-name/ta/taskchampion-sync/test.nix
new file mode 100644
index 0000000..4dd273b
--- /dev/null
+++ b/tests/by-name/ta/taskchampion-sync/test.nix
@@ -0,0 +1,96 @@
+{
+ nixos-lib,
+ pkgsUnstable,
+ nixpkgs-unstable,
+ vhackPackages,
+ pkgs,
+ extraModules,
+ nixLib,
+ ...
+}:
+nixos-lib.runTest {
+ hostPkgs = pkgs;
+ name = "taskchampion-sync";
+
+ node = {
+ specialArgs = {inherit pkgsUnstable vhackPackages nixpkgs-unstable nixLib;};
+
+ # Use the nixpkgs as constructed by the `nixpkgs.*` options
+ pkgs = null;
+ };
+
+ nodes = {
+ server = {config, ...}: {
+ imports =
+ extraModules
+ ++ [
+ ../../../../modules
+ ];
+
+ vhack = {
+ taskchampion-sync.enable = true;
+ };
+ };
+
+ task_client1 = {config, ...}: {
+ environment.systemPackages = [
+ pkgs.taskwarrior3
+ ];
+ };
+ task_client2 = {config, ...}: {
+ environment.systemPackages = [
+ pkgs.taskwarrior3
+ ];
+ };
+ };
+
+ testScript = {nodes, ...}: let
+ cfg = nodes.server.services.taskchampion-sync-server;
+ port = builtins.toString cfg.port;
+
+ # Generated with uuidgen
+ uuid = "bf01376e-04a4-435a-9263-608567531af3";
+ password = "nixos-test";
+
+ mkSyncConfig = path:
+ pkgs.writeShellScript "setup-config-file" ''
+ set -xe
+
+ mkdir --parents "$(dirname "${path}")"
+ echo 'sync.server.origin=http://server:${port}' >> "${path}"
+ echo 'sync.server.client_id=${uuid}' >> "${path}"
+ echo 'sync.encryption_secret=${password}' >> "${path}"
+ '';
+ in
+ /*
+ python
+ */
+ ''
+ start_all()
+
+ server.wait_for_unit("taskchampion-sync-server.service")
+ server.wait_for_open_port(${port})
+
+ with subtest("Setup task syncing"):
+ for task in [task_client1, task_client2]:
+ # See man task-sync(5)
+ task.succeed("mkdir ~/.task")
+ task.succeed("${mkSyncConfig "$HOME/.taskrc"}")
+
+ with subtest("Can create tasks"):
+ task_client1.succeed("task add 'First task -- task_client1'")
+ task_client2.succeed("task add 'First task -- task_client2'")
+
+ with subtest("Can sync tasks"):
+ for task in [task_client1, task_client2]:
+ task.succeed("task sync")
+ task_client1.succeed("task sync")
+
+ with subtest("Have correct tasks"):
+ count1 = task_client1.succeed("task count")
+ count2 = task_client2.succeed("task count")
+
+ assert int(count1) == 2, f"We don't have exactly 2 tasks, but {count1}"
+ assert count1 == count2, f"The clients don't have the same amount of tasks, client1: {count1}, client2: {count2}"
+ '';
+}