comodoro: add module

This commit is contained in:
Clément DOUIN 2023-04-14 23:41:51 +02:00 committed by Robert Helgesson
parent 194086df82
commit e0034971f9
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
11 changed files with 193 additions and 0 deletions

View File

@ -1101,6 +1101,16 @@ in
A new module is available: 'programs.git-credential-oauth'.
'';
}
{
time = "2023-06-14T21:41:22+00:00";
message = ''
Two new modules are available:
- 'programs.comodoro' and
- 'services.comodoro'
'';
}
];
};
}

View File

@ -68,6 +68,7 @@ let
./programs/btop.nix
./programs/chromium.nix
./programs/command-not-found/command-not-found.nix
./programs/comodoro.nix
./programs/dircolors.nix
./programs/direnv.nix
./programs/discocss.nix
@ -234,6 +235,7 @@ let
./services/cbatticon.nix
./services/clipman.nix
./services/clipmenu.nix
./services/comodoro.nix
./services/copyq.nix
./services/devilspie2.nix
./services/dropbox.nix

View File

@ -0,0 +1,31 @@
{ config, lib, pkgs, ... }:
let
cfg = config.programs.comodoro;
tomlFormat = pkgs.formats.toml { };
in {
meta.maintainers = with lib.hm.maintainers; [ soywod ];
options.programs.comodoro = {
enable = lib.mkEnableOption "Comodoro, a CLI to manage your time";
package = lib.mkPackageOption pkgs "comodoro" { };
settings = lib.mkOption {
type = lib.types.submodule { freeformType = tomlFormat.type; };
default = { };
description = ''
Comodoro configuration.
See <link xlink:href="https://pimalaya.org/comodoro/cli/configuration/"/> for supported values.
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."comodoro/config.toml".source =
tomlFormat.generate "comodoro-config.toml" cfg.settings;
};
}

View File

@ -0,0 +1,70 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.comodoro;
args = with cfg; {
inherit preset;
protocols = if lib.isList protocols then
lib.concatStringsSep " " protocols
else
protocols;
};
in {
meta.maintainers = with lib.hm.maintainers; [ soywod ];
options.services.comodoro = {
enable = lib.mkEnableOption "Comodoro server";
package = lib.mkPackageOption pkgs "comodoro" { };
environment = lib.mkOption {
type = with lib.types; attrsOf str;
default = { };
example = lib.literalExpression ''
{
"PASSWORD_STORE_DIR" = "~/.password-store";
}
'';
description = ''
Extra environment variables to be exported in the service.
'';
};
preset = lib.mkOption {
type = lib.types.nonEmptyStr;
description = ''
Use configuration from the given preset as defined in the configuration file.
'';
};
protocols = lib.mkOption {
type = with lib.types; nonEmptyListOf nonEmptyStr;
description = ''
Define protocols the server should use to accept requests.
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
systemd.user.services.comodoro = {
Unit = {
Description = "Comodoro server";
After = [ "network.target" ];
};
Install = { WantedBy = [ "default.target" ]; };
Service = {
ExecStart = with args;
"${cfg.package}/bin/comodoro server start ${preset} ${protocols}";
ExecSearchPath = "/bin";
Restart = "always";
RestartSec = 10;
Environment =
lib.mapAttrsToList (key: val: "${key}=${val}") cfg.environment;
};
};
};
}

View File

@ -66,6 +66,7 @@ import nmt {
./modules/programs/broot
./modules/programs/browserpass
./modules/programs/btop
./modules/programs/comodoro
./modules/programs/dircolors
./modules/programs/direnv
./modules/programs/emacs
@ -186,6 +187,7 @@ import nmt {
./modules/services/borgmatic
./modules/services/cachix-agent
./modules/services/clipman
./modules/services/comodoro
./modules/services/devilspie2
./modules/services/dropbox
./modules/services/emacs

View File

@ -0,0 +1,35 @@
{ ... }:
{
programs.comodoro = {
enable = true;
settings = {
test-preset = {
cycles = [
{
name = "Work";
duration = 1500;
}
{
name = "Rest";
duration = 500;
}
];
tcp-host = "localhost";
tcp-port = 8080;
on-server-start = "echo server started";
on-timer-stop = "echo timer stopped";
on-work-begin = "echo work cycle began";
};
};
};
test.stubs.comodoro = { };
nmt.script = ''
assertFileExists home-files/.config/comodoro/config.toml
assertFileContent home-files/.config/comodoro/config.toml ${./expected.toml}
'';
}

View File

@ -0,0 +1 @@
{ comodoro-program = ./comodoro.nix; }

View File

@ -0,0 +1,13 @@
[test-preset]
on-server-start = "echo server started"
on-timer-stop = "echo timer stopped"
on-work-begin = "echo work cycle began"
tcp-host = "localhost"
tcp-port = 8080
[[test-preset.cycles]]
duration = 1500
name = "Work"
[[test-preset.cycles]]
duration = 500
name = "Rest"

View File

@ -0,0 +1,16 @@
{ ... }:
{
services.comodoro = {
enable = true;
preset = "preset";
protocols = [ "tcp" ];
};
test.stubs.comodoro = { };
nmt.script = ''
serviceFile=$(normalizeStorePaths home-files/.config/systemd/user/comodoro.service)
assertFileContent "$serviceFile" ${./expected.service}
'';
}

View File

@ -0,0 +1 @@
{ comodoro-service = ./comodoro.nix; }

View File

@ -0,0 +1,12 @@
[Install]
WantedBy=default.target
[Service]
ExecSearchPath=/bin
ExecStart=@comodoro@/bin/comodoro server start preset tcp
Restart=always
RestartSec=10
[Unit]
After=network.target
Description=Comodoro server