fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Clément DOUINcomodoro: add modulee0034971

master
1.7 KiB70 linesraw
1{ config, lib, pkgs, ... }:
2
3let
4  cfg = config.services.comodoro;
5
6  args = with cfg; {
7    inherit preset;
8    protocols = if lib.isList protocols then
9      lib.concatStringsSep " " protocols
10    else
11      protocols;
12  };
13
14in {
15  meta.maintainers = with lib.hm.maintainers; [ soywod ];
16
17  options.services.comodoro = {
18    enable = lib.mkEnableOption "Comodoro server";
19
20    package = lib.mkPackageOption pkgs "comodoro" { };
21
22    environment = lib.mkOption {
23      type = with lib.types; attrsOf str;
24      default = { };
25      example = lib.literalExpression ''
26        {
27          "PASSWORD_STORE_DIR" = "~/.password-store";
28        }
29      '';
30      description = ''
31        Extra environment variables to be exported in the service.
32      '';
33    };
34
35    preset = lib.mkOption {
36      type = lib.types.nonEmptyStr;
37      description = ''
38        Use configuration from the given preset as defined in the configuration file.
39      '';
40    };
41
42    protocols = lib.mkOption {
43      type = with lib.types; nonEmptyListOf nonEmptyStr;
44      description = ''
45        Define protocols the server should use to accept requests.
46      '';
47    };
48  };
49
50  config = lib.mkIf cfg.enable {
51    home.packages = [ cfg.package ];
52
53    systemd.user.services.comodoro = {
54      Unit = {
55        Description = "Comodoro server";
56        After = [ "network.target" ];
57      };
58      Install = { WantedBy = [ "default.target" ]; };
59      Service = {
60        ExecStart = with args;
61          "${cfg.package}/bin/comodoro server start ${preset} ${protocols}";
62        ExecSearchPath = "/bin";
63        Restart = "always";
64        RestartSec = 10;
65        Environment =
66          lib.mapAttrsToList (key: val: "${key}=${val}") cfg.environment;
67      };
68    };
69  };
70}