summary refs log tree commit diff
path: root/nix/modules/default/cs/uapi.nix
blob: 2df0535ff1c1a6348eb199218322c775776734ef (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
self:
{
  config,
  lib,
  pkgs,
  spacebar,
  ...
}:

let
  secrets = import ../secrets.nix { inherit lib config; };
  cfg = config.services.spacebarchat-server;
  jsonFormat = pkgs.formats.json { };
in
{
  imports = [
    ./shared-config.nix
  ];
  options.services.spacebarchat-server.uApi = lib.mkOption {
    default = { };
    description = "Configuration for C# API overlay.";
    type = lib.types.submodule {
      options = {
        enable = lib.mkEnableOption "Enable C# API overlay.";
        listenPort = lib.mkOption {
          type = lib.types.port;
          default = 3012;
          description = "Port for the gateway offload daemon to listen on.";
        };
        extraConfiguration = lib.mkOption {
          type = jsonFormat.type;
          default = { };
          description = "Extra appsettings.json configuration for the C# API overlay.";
        };
      };
    };
  };

  config = lib.mkIf cfg.uApi.enable (
    let
      makeServerTsService = import ../makeServerTsService.nix { inherit cfg lib secrets; };
    in
    {
      assertions = [
        (import ./assert-has-connection-string.nix "uAPI" cfg)
      ];

      systemd.services.spacebar-uapi = makeServerTsService {
        description = "Spacebar Server - C# API overlay";
        # after = [ "spacebar-api.service" ];
        environment = builtins.mapAttrs (_: val: builtins.toString val) (
          {
            # things we set by default...
            EVENT_TRANSMISSION = "unix";
            EVENT_SOCKET_PATH = "/run/spacebar/";
          }
          // cfg.extraEnvironment
          // {
            # things we force...
            # CONFIG_PATH = configFile;
            CONFIG_READONLY = 1;
            ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.uApi.listenPort}";
            STORAGE_LOCATION = cfg.cdnPath;
            APPSETTINGS_PATH = jsonFormat.generate "appsettings.spacebar-uapi.json" (lib.recursiveUpdate cfg.cs.defaultAppsettings cfg.uApi.extraConfiguration);
          }
        );
        serviceConfig = {
          ExecStart = "${self.packages.${pkgs.stdenv.hostPlatform.system}.Spacebar-UApi}/bin/Spacebar.UApi";
        };
      };
    }
  );
}