From 2907788315a73d3292140b4d59b5d95796565625 Mon Sep 17 00:00:00 2001 From: Johan Larsson <13087841+jolars@users.noreply.github.com> Date: Thu, 6 Nov 2025 17:44:08 +0100 Subject: [PATCH] tomat: init service (#8138) --- .../misc/news/2025/11/2025-11-06_12-50-53.nix | 9 +++ modules/services/tomat.nix | 74 +++++++++++++++++++ tests/modules/services/tomat/default.nix | 5 ++ .../services/tomat/expected-config.toml | 3 + tests/modules/services/tomat/expected.service | 11 +++ tests/modules/services/tomat/tomat.nix | 25 +++++++ 6 files changed, 127 insertions(+) create mode 100644 modules/misc/news/2025/11/2025-11-06_12-50-53.nix create mode 100644 modules/services/tomat.nix create mode 100644 tests/modules/services/tomat/default.nix create mode 100644 tests/modules/services/tomat/expected-config.toml create mode 100644 tests/modules/services/tomat/expected.service create mode 100644 tests/modules/services/tomat/tomat.nix diff --git a/modules/misc/news/2025/11/2025-11-06_12-50-53.nix b/modules/misc/news/2025/11/2025-11-06_12-50-53.nix new file mode 100644 index 000000000..6ed52dee1 --- /dev/null +++ b/modules/misc/news/2025/11/2025-11-06_12-50-53.nix @@ -0,0 +1,9 @@ +{ + time = "2025-11-06T11:50:53+00:00"; + condition = true; + message = '' + A new module is available: 'services.tomat'. + + tomat is a Pomodoro timer for status bars and the command line. It is easily configurable and support both desktop and sound notifications. + ''; +} diff --git a/modules/services/tomat.nix b/modules/services/tomat.nix new file mode 100644 index 000000000..95189cca1 --- /dev/null +++ b/modules/services/tomat.nix @@ -0,0 +1,74 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.tomat; + tomlFormat = pkgs.formats.toml { }; +in +{ + meta.maintainers = with lib.maintainers; [ jolars ]; + + options.services.tomat = { + enable = lib.mkEnableOption "Tomat Pomodoro server"; + + package = lib.mkPackageOption pkgs "tomat" { }; + + settings = lib.mkOption { + type = lib.types.submodule { freeformType = tomlFormat.type; }; + + default = { }; + + example = { + timer = { + work = 25; + break = 5; + auto_advance = false; + }; + + sound = { + enabled = true; + }; + + notification = { + enabled = true; + }; + }; + + description = '' + Tomat configuration. + See for supported values. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile = { + "tomat/config.toml" = lib.mkIf (cfg.settings != { }) { + source = tomlFormat.generate "tomat-config.toml" cfg.settings; + }; + }; + + systemd.user.services.tomat = { + Unit = { + Description = "Tomat Pomodoro server"; + After = [ "graphical.target" ]; + }; + + Service = { + ExecStart = "${lib.getExe cfg.package} daemon run"; + Restart = "always"; + RestartSec = 5; + }; + + Install = { + WantedBy = [ "default.target" ]; + }; + }; + }; +} diff --git a/tests/modules/services/tomat/default.nix b/tests/modules/services/tomat/default.nix new file mode 100644 index 000000000..589fc5291 --- /dev/null +++ b/tests/modules/services/tomat/default.nix @@ -0,0 +1,5 @@ +{ lib, pkgs, ... }: + +lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + tomat-service = ./tomat.nix; +} diff --git a/tests/modules/services/tomat/expected-config.toml b/tests/modules/services/tomat/expected-config.toml new file mode 100644 index 000000000..8bf29ac8e --- /dev/null +++ b/tests/modules/services/tomat/expected-config.toml @@ -0,0 +1,3 @@ +[timer] +break = 10 +work = 60 diff --git a/tests/modules/services/tomat/expected.service b/tests/modules/services/tomat/expected.service new file mode 100644 index 000000000..dce396a2d --- /dev/null +++ b/tests/modules/services/tomat/expected.service @@ -0,0 +1,11 @@ +[Install] +WantedBy=default.target + +[Service] +ExecStart=@tomat@/bin/tomat daemon run +Restart=always +RestartSec=5 + +[Unit] +After=graphical.target +Description=Tomat Pomodoro server diff --git a/tests/modules/services/tomat/tomat.nix b/tests/modules/services/tomat/tomat.nix new file mode 100644 index 000000000..c0c6ade88 --- /dev/null +++ b/tests/modules/services/tomat/tomat.nix @@ -0,0 +1,25 @@ +{ + services.tomat = { + enable = true; + + settings = { + timer = { + break = 10; + work = 60; + }; + }; + }; + + nmt.script = + let + serviceFile = "home-files/.config/systemd/user/tomat.service"; + configFile = "home-files/.config/tomat/config.toml"; + in + '' + assertFileExists "${serviceFile}" + assertFileExists "${configFile}" + + assertFileContent "${serviceFile}" ${./expected.service} + assertFileContent "${configFile}" ${./expected-config.toml} + ''; +}