aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/games/codenames/default.nix
blob: 25eb62de6f13072e2abc7be58692aebdf7a0ad82 (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
{ config, lib, pkgs, ... }:
let
  greenapid = pkgs.callPackage ./greenapid.nix {};
  frontend = pkgs.callPackage ./frontend.nix { nodeEnv = pkgs.callPackage pkgs.mylibs.nodeEnv {}; };
  wordlists = pkgs.runCommand "wordlists" {} ''
    mkdir -p $out
    cp -r ${./wordlists} $out/wordlists
  '';
  cfg = config.myServices.websites.games.codenames;
in
{
  options.myServices.websites.games.codenames.enable = lib.mkEnableOption "Enable Codenames game";
  config = lib.mkIf cfg.enable {
    systemd.services.codenames_api = {
      description = "Api for codenames game";
      wantedBy = [ "multi-user.target" ];
      script = "${greenapid}/bin/greenapid";
      postStart = ''
        sleep 5;
        chown :wwwrun /run/codenamesgreen/socket.sock
        chmod g+w /run/codenamesgreen/socket.sock
      '';
      serviceConfig = {
        User = "codenames";
        DynamicUser = true;
        SupplementaryGroups = [ "wwwrun" ];
        Type = "simple";
        RuntimeDirectory = "codenamesgreen";
        WorkingDirectory = builtins.toString wordlists;
      };
    };

    services.websites.env.tools.vhostConfs.games_codenames = {
      certName = "games";
      certMainHost = "games.immae.eu";
      hosts = [ "codenames.games.immae.eu" ];
      root = frontend;
      extraConfig = [
        ''
        ProxyPass        /api/ unix:///run/codenamesgreen/socket.sock|http://codenames.games.immae.eu/
        ProxyPassReverse /api/ unix:///run/codenamesgreen/socket.sock|http://codenames.games.immae.eu/

        <Directory ${frontend}>
          FallbackResource index.html
        </Directory>
        ''
      ];
    };
  };
}