summary refs log tree commit diff
path: root/nixos/modules/services/misc/leaps.nix
blob: ef89d3e64d0c31b12704c10b278c8cb490c2478b (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
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.leaps;
  stateDir = "/var/lib/leaps/";
in
{
  options = {
    services.leaps = {
      enable = mkEnableOption "leaps";
      port = mkOption {
        type = types.int;
        default = 8080;
        description = "A port where leaps listens for incoming http requests";
      };
      address = mkOption {
        default = "";
        type = types.str;
        example = "127.0.0.1";
        description = "Hostname or IP-address to listen to. By default it will listen on all interfaces.";
      };
      path = mkOption {
        default = "/";
        type = types.path;
        description = "Subdirectory used for reverse proxy setups";
      };
    };
  };

  config = mkIf cfg.enable {
    users = {
      users.leaps = {
        uid             = config.ids.uids.leaps;
        description     = "Leaps server user";
        group           = "leaps";
        home            = stateDir;
        createHome      = true;
      };

      groups.leaps = {
        gid = config.ids.gids.leaps;
      };
    };

    systemd.services.leaps = {
      description   = "leaps service";
      wantedBy      = [ "multi-user.target" ];
      after         = [ "network.target" ];

      serviceConfig = {
        User = "leaps";
        Group = "leaps";
        Restart = "on-failure";
        WorkingDirectory = stateDir;
        PrivateTmp = true;
        ExecStart = "${pkgs.leaps}/bin/leaps -path ${toString cfg.path} -address ${cfg.address}:${toString cfg.port}";
      };
    };
  };
}