summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/networking/nebula-lighthouse-service.nix
blob: cd9371cba2ae051340f6ac96d4054b08cb3fc2c6 (plain)
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
{
  config,
  pkgs,
  lib,
  ...
}:

let
  inherit (lib) types;

  cfg = config.services.nebula-lighthouse-service;
  settingsFormat = pkgs.formats.yaml { };
in
{

  options.services.nebula-lighthouse-service = {
    enable = lib.mkEnableOption "nebula-lighthouse-service";
    user = lib.mkOption {
      type = types.str;
      default = "nebula-lighthouse";
      description = ''
        The user and group to run nebula-lighthouse-service as.
      '';
      example = "nebula-lighthouse";
    };
    settings = lib.mkOption {
      type = settingsFormat.type;
      default = { };
      description = ''
        Configuration for nebula-lighthouse-service.
      '';
      example = {
        max-port = 65535;
        min-port = 49152;
        "webserver.ip" = "127.0.0.1";
        "webserver.port" = 8080;
      };
    };
  };

  config = lib.mkIf cfg.enable {
    services.nebula-lighthouse-service.settings = {
      min-port = lib.mkDefault 49152;
      max-port = lib.mkDefault 65535;
      "webserver.port" = lib.mkDefault 8080;
      "webserver.ip" = lib.mkDefault "127.0.0.1";
    };
    environment.etc."nebula-lighthouse-service/config.yaml".source =
      settingsFormat.generate "nebula-lighthouse-service-config.yaml" cfg.settings;
    systemd.services.nebula-lighthouse-service = {
      description = "Run nebula-lighthouse-service";
      wants = [ "basic.target" ];
      after = [
        "basic.target"
        "network.target"
      ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "exec";
        Restart = "always";
        ExecStart = "${pkgs.nebula-lighthouse-service}/bin/nebula-lighthouse-service";
        StateDirectory = "nebula-lighthouse-service";
        User = cfg.user;
        Group = cfg.user;
      };
    };
    users.users.${cfg.user} = {
      group = cfg.user;
      description = "nebula-lighthouse-service user";
      isSystemUser = true;
    };
    users.groups.${cfg.user} = { };
  };
  meta.maintainers = with lib.maintainers; [
    bloominstrong
  ];
}