aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/games/terraforming-mars/default.nix
blob: 0df5363ae42fba9f2470ebb5561c853c3b290c3a (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
{ config, lib, pkgs, ... }:
let
  cfg = config.myServices.websites.games.terraforming-mars;
  terraforming-mars = pkgs.callPackage ./terraforming-mars.nix {};
in
{
  options.myServices.websites.games.terraforming-mars.enable = lib.mkEnableOption "Enable Terraforming mars game";
  config = lib.mkIf cfg.enable {
    systemd.services.terraforming-mars = {
      path = [ pkgs.nodejs pkgs.bashInteractive ];
      description = "Terraforming mars game";
      wantedBy = [ "multi-user.target" ];
      script = ''
        export PORT=/run/terraforming-mars/socket.sock
        export NODE_ENV=production
        mkdir -p /var/lib/terraforming-mars/db
        npm run start
      '';
      postStart = ''
        sleep 5;
        chown :wwwrun /run/terraforming-mars/socket.sock
        chmod g+w /run/terraforming-mars/socket.sock
      '';
      serviceConfig = {
        User = "terraformingmars";
        DynamicUser = true;
        SupplementaryGroups = [ "wwwrun" ];
        Type = "simple";
        WorkingDirectory = terraforming-mars;
        RuntimeDirectory = "terraforming-mars";
        StateDirectory = "terraforming-mars";
      };
    };

    services.websites.env.tools.vhostConfs.games_terraforming-mars = {
      certName = "games";
      certMainHost = "games.immae.eu";
      hosts = [ "terraforming-mars.games.immae.eu" ];
      root = null;
      extraConfig = [
        ''
          ProxyPass        / unix:///run/terraforming-mars/socket.sock|http://terraforming-mars.games.immae.eu/
          ProxyPassReverse / unix:///run/terraforming-mars/socket.sock|http://terraforming-mars.games.immae.eu/
        ''
      ];
    };
  };
}