1{ config, pkgs, lib, ... }:
2
3with lib;
4
5let
6 cfg = config.services.leaps;
7 stateDir = "/var/lib/leaps/";
8in
9{
10 options = {
11 services.leaps = {
12 enable = mkEnableOption (lib.mdDoc "leaps");
13 port = mkOption {
14 type = types.port;
15 default = 8080;
16 description = lib.mdDoc "A port where leaps listens for incoming http requests";
17 };
18 address = mkOption {
19 default = "";
20 type = types.str;
21 example = "127.0.0.1";
22 description = lib.mdDoc "Hostname or IP-address to listen to. By default it will listen on all interfaces.";
23 };
24 path = mkOption {
25 default = "/";
26 type = types.path;
27 description = lib.mdDoc "Subdirectory used for reverse proxy setups";
28 };
29 };
30 };
31
32 config = mkIf cfg.enable {
33 users = {
34 users.leaps = {
35 uid = config.ids.uids.leaps;
36 description = "Leaps server user";
37 group = "leaps";
38 home = stateDir;
39 createHome = true;
40 };
41
42 groups.leaps = {
43 gid = config.ids.gids.leaps;
44 };
45 };
46
47 systemd.services.leaps = {
48 description = "leaps service";
49 wantedBy = [ "multi-user.target" ];
50 after = [ "network.target" ];
51
52 serviceConfig = {
53 User = "leaps";
54 Group = "leaps";
55 Restart = "on-failure";
56 WorkingDirectory = stateDir;
57 PrivateTmp = true;
58 ExecStart = "${pkgs.leaps}/bin/leaps -path ${toString cfg.path} -address ${cfg.address}:${toString cfg.port}";
59 };
60 };
61 };
62}