summary refs log tree commit diff
path: root/hosts/vps/services/cytube.nix
blob: deb0058daade02d5754714c044d38a45b829e92c (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
{
  pkgs,
  config,
  lib,
  system,
  ...
}: {
  config = let
    dir = "/var/lib/cytube";
    yamlConfig =
      pkgs.writeText "config.yaml"
      (lib.generators.toYAML {} {
        mysql = {
          server = "localhost";
          port = 3306;
          database = "cytube";
          user = "cytube";
          password = "";
          pool-size = 10;
        };
        listen = [
          {
            ip = "";
            port = 8080;
            http = true;
          }
          {
            ip = "";
            port = 8081;
            io = true;
            url = "https://tube.tzlil.net";
          }
        ];
        http = {
          default-port = 8080;
          root-domain = "tube.tzlil.net";
          alt-domains = [];
          minify = false;
          max-age = "7d";
          gzip = true;
          gzip-threshold = 1024;
          cookie-secret = "tube.tzlil.net";
          index = {
            max-entries = 50;
          };
          trust-proxies = ["loopback"];
        };
        https = {
          enabled = false;
        };
        html-template = {
          title = "TZLINC";
          description = "lol";
        };
        io = {
          domain = "https://tube.tzlil.net";
          default-port = 8081;
        };
        youtube-v3-key = "";
        max-channels-per-user = 1;
        max-accounts-per-ip = 5;
        ffmpeg = {
          enabled = true;
          ffprobe-exec = "ffprobe";
        };
        service-socket = {
          enabled = false;
        };
      });
  in {
    services.mysql = {
      enable = true;
      package = pkgs.mariadb;
      ensureDatabases = ["cytube"];
      ensureUsers = [
        {
          name = "cytube";
          ensurePermissions = {
            "cytube.*" = "ALL PRIVILEGES";
          };
        }
      ];

      settings = {
        mysqld = {
          bind-address = "127.0.0.1";
          port = "3306";
        };
      };
    };

    virtualisation.oci-containers.containers.cytube = {
      ports = [
        "8080:8080"
        "8081:8081"
      ];
      image = "cytube";

      imageFile = pkgs.dockerTools.buildImage {
        name = "cytube";
        tag = "latest";
        fromImage = pkgs.dockerTools.pullImage {
          imageName = "kittysh/cytube";
          imageDigest = "sha256:77e6051c0fe4ce486375f53d80a5cb9a18e289db9cc8ba28e142287b53730455";
          sha256 = "072gyx9s4nnq2i8h5b3n3vrcl5h7wigq9fzbf6y11n945km1ds2r";
          finalImageName = "kittysh/cytube";
          finalImageTag = "latest";
        };

        copyToRoot = pkgs.buildEnv {
          name = "image-root";
          paths = [pkgs.ffmpeg];
          pathsToLink = ["/bin"];
        };
        config.Cmd = ["node" "index.js"];
      };

      workdir = "/home/syncuser/sync";
      extraOptions = ["--mount=type=bind,source=${yamlConfig},target=/home/syncuser/sync/config.yaml" "--network=host"];
    };

    environment.persistence."/nix/persist".directories = [
      {
        directory = "${config.services.mysql.dataDir}";
        user = "${config.services.mysql.user}";
        group = "${config.services.mysql.group}";
      }
    ];

    services.caddy = {
      virtualHosts."tube.tzlil.net".extraConfig = ''
        bind 0.0.0.0
        handle /socket.io/* {
          reverse_proxy :8081
        }
        reverse_proxy :8080
      '';
    };
  };
}