about summary refs log tree commit diff
path: root/nixos/modules/services/misc/workout-tracker.nix
blob: 13555504be30294b5909eb7a2942f32d5e6295d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
  config,
  lib,
  pkgs,
  ...
}:

let
  inherit (lib) types;
  cfg = config.services.workout-tracker;
  stateDir = "workout-tracker";
in

{
  options = {
    services.workout-tracker = {
      enable = lib.mkEnableOption "workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities";

      package = lib.mkPackageOption pkgs "workout-tracker" { };

      address = lib.mkOption {
        type = types.str;
        default = "127.0.0.1";
        description = "Web interface address.";
      };

      port = lib.mkOption {
        type = types.port;
        default = 8080;
        description = "Web interface port.";
      };

      environmentFile = lib.mkOption {
        type = types.nullOr types.path;
        default = null;
        example = "/run/keys/workout-tracker.env";
        description = ''
          An environment file as defined in {manpage}`systemd.exec(5)`.

          Secrets like `WT_JWT_ENCRYPTION_KEY` may be passed to the service without adding them
          to the world-readable Nix store.
        '';
      };

      settings = lib.mkOption {
        type = types.attrsOf types.str;

        default = { };
        description = ''
          Extra config options.
        '';
        example = {
          WT_LOGGING = "true";
          WT_DEBUG = "false";
          WT_DATABASE_DRIVER = "sqlite";
          WT_DSN = "./database.db";
        };
      };
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.workout-tracker = {
      description = "A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities";
      wantedBy = [ "multi-user.target" ];
      environment = {
        WT_BIND = "${cfg.address}:${toString cfg.port}";
        WT_DATABASE_DRIVER = "sqlite";
        WT_DSN = "./database.db";
      } // cfg.settings;
      serviceConfig = {
        ExecStart = lib.getExe cfg.package;
        DynamicUser = true;
        StateDirectory = stateDir;
        WorkingDirectory = "%S/${stateDir}";
        Restart = "always";
        EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
      };
    };
  };

  meta.maintainers = with lib.maintainers; [ bhankas ];
}