@@ -0,0 +1,80 @@
1+{ config, lib, pkgs, ... }:
2+
3+let
4+ inherit (lib) mkEnableOption mkIf mkOption types literalExpression;
5+
6+ cfg = config.services.timetagger;
7+in {
8+
9+ options = {
10+ services.timetagger = {
11+ enable = mkOption {
12+ type = types.bool;
13+ default = false;
14+ description = ''
15+ Tag your time, get the insight
16+
17+ <note><para>
18+ This app does not do authentication.
19+ You must setup authentication yourself or run it in an environment where
20+ only allowed users have access.
21+ </para></note>
22+ '';
23+ };
24+
25+ bindAddr = mkOption {
26+ description = "Address to bind to.";
27+ type = types.str;
28+ default = "127.0.0.1";
29+ };
30+
31+ port = mkOption {
32+ description = "Port to bind to.";
33+ type = types.port;
34+ default = 8080;
35+ };
36+
37+ package = mkOption {
38+ description = ''
39+ Use own package for starting timetagger web application.
40+
41+ The ${literalExpression ''pkgs.timetagger''} package only provides a
42+ "run.py" script for the actual package
43+ ${literalExpression ''pkgs.python3Packages.timetagger''}.
44+
45+ If you want to provide a "run.py" script for starting timetagger
46+ yourself, you can do so with this option.
47+ If you do so, the 'bindAddr' and 'port' options are ignored.
48+ '';
49+
50+ default = pkgs.timetagger.override { addr = cfg.bindAddr; port = cfg.port; };
51+ defaultText = literalExpression ''
52+ pkgs.timetagger.override {
53+ addr = ${cfg.bindAddr};
54+ port = ${cfg.port};
55+ };
56+ '';
57+ type = types.package;
58+ };
59+ };
60+ };
61+
62+ config = mkIf cfg.enable {
63+ systemd.services.timetagger = {
64+ description = "Timetagger service";
65+ wantedBy = [ "multi-user.target" ];
66+
67+ serviceConfig = {
68+ User = "timetagger";
69+ Group = "timetagger";
70+ StateDirectory = "timetagger";
71+
72+ ExecStart = "${cfg.package}/bin/timetagger";
73+
74+ Restart = "on-failure";
75+ RestartSec = 1;
76+ };
77+ };
78+ };
79+}
80+