aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/tools/peertube/default.nix
blob: 445030c792b343ba3eb7d1c3a987f28ce7e35184 (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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
{ lib, pkgs, config,  ... }:
let
  env = config.myEnv.tools.peertube;
  cfg = config.myServices.websites.tools.peertube;
  pcfg = config.services.peertube;
in {
  options.myServices.websites.tools.peertube = {
    enable = lib.mkEnableOption "enable Peertube's website";
  };

  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.peertube = {
      rootDir = pcfg.dataDir;
    };
    services.peertube = {
      enable = true;
      configFile = "/var/secrets/webapps/tools-peertube";
      package = pkgs.webapps.peertube.override { ldap = true; sendmail = true; light = "fr-FR"; };
    };
    users.users.peertube.extraGroups = [ "keys" ];

    secrets.keys = [{
      dest = "webapps/tools-peertube";
      user = "peertube";
      group = "peertube";
      permissions = "0640";
      text = ''
        listen:
          hostname: 'localhost'
          port: ${toString config.myEnv.ports.peertube}
        webserver:
          https: true
          hostname: 'peertube.immae.eu'
          port: 443
        rates_limit:
          api:
            # 50 attempts in 10 seconds
            window: 10 seconds
            max: 50
          login:
            # 15 attempts in 5 min
            window: 5 minutes
            max: 15
          signup:
            # 2 attempts in 5 min (only succeeded attempts are taken into account)
            window: 5 minutes
            max: 2
          ask_send_email:
            # 3 attempts in 5 min
            window: 5 minutes
            max: 3
        trust_proxy:
          - 'loopback'
        database:
          hostname: '${env.postgresql.socket}'
          port: 5432
          suffix: '_prod'
          username: '${env.postgresql.user}'
          password: '${env.postgresql.password}'
          pool:
            max: 5
        redis:
          socket: '${env.redis.socket}'
          auth: null
          db: ${env.redis.db}
        auth:
          local:
            enabled: true
          ldap:
            enabled: true
            ldap_only: false
            url: ldaps://${env.ldap.host}/${env.ldap.base}
            bind_dn: ${env.ldap.dn}
            bind_password: ${env.ldap.password}
            base: ${env.ldap.base}
            mail_entry: "mail"
            user_filter: "${env.ldap.filter}"
        smtp:
          transport: sendmail
          sendmail: '/run/wrappers/bin/sendmail'
          hostname: null
          port: 465 # If you use StartTLS: 587
          username: null
          password: null
          tls: true # If you use StartTLS: false
          disable_starttls: false
          ca_file: null # Used for self signed certificates
          from_address: 'peertube@tools.immae.eu'
        email:
          body:
            signature: "PeerTube"
          subject:
            prefix: "[PeerTube]"
        storage:
          tmp: '${pcfg.dataDir}/storage/tmp/'
          avatars: '${pcfg.dataDir}/storage/avatars/'
          videos: '${pcfg.dataDir}/storage/videos/'
          streaming_playlists: '${pcfg.dataDir}/storage/streaming-playlists/'
          redundancy: '${pcfg.dataDir}/storage/videos/'
          logs: '${pcfg.dataDir}/storage/logs/'
          previews: '${pcfg.dataDir}/storage/previews/'
          thumbnails: '${pcfg.dataDir}/storage/thumbnails/'
          torrents: '${pcfg.dataDir}/storage/torrents/'
          captions: '${pcfg.dataDir}/storage/captions/'
          cache: '${pcfg.dataDir}/storage/cache/'
          plugins: '${pcfg.dataDir}/storage/plugins/'
        log:
          level: 'info'
          rotation:
            enabled : true # Enabled by default, if disabled make sure that 'storage.logs' is pointing to a folder handled by logrotate
            maxFileSize: 12MB
            maxFiles: 20
          anonymizeIP: false
        search:
          remote_uri:
            users: true
            anonymous: false
        trending:
          videos:
            interval_days: 7
        redundancy:
          videos:
            check_interval: '1 hour' # How often you want to check new videos to cache
            strategies: # Just uncomment strategies you want
        csp:
          enabled: false
          report_only: true # CSP directives are still being tested, so disable the report only mode at your own risk!
          report_uri:
        tracker:
          enabled: true
          private: true
          reject_too_many_announces: false
        history:
          videos:
            max_age: -1
        views:
          videos:
            remote:
              max_age: -1
        plugins:
          index:
            enabled: true
            check_latest_versions_interval: '12 hours'
            url: 'https://packages.joinpeertube.org'
        # Following are saved in local-production.json
        cache:
          previews:
            size: 500 # Max number of previews you want to cache
          captions:
            size: 500 # Max number of video captions/subtitles you want to cache
        admin:
          email: 'peertube@tools.immae.eu'
        contact_form:
          enabled: true
        signup:
          enabled: false
          limit: 10
          requires_email_verification: false
          filters:
            cidr:
              whitelist: []
              blacklist: []
        user:
          video_quota: -1
          video_quota_daily: -1
        transcoding:
          enabled: false
          allow_additional_extensions: true
          allow_audio_files: true
          threads: 1
          resolutions:
            0p: false
            240p: false
            360p: false
            480p: true
            720p: true
            1080p: true
            2160p: false
          webtorrent:
            enabled: true
          hls:
            enabled: false
        import:
          videos:
            http:
              enabled: true
            torrent:
              enabled: false
        auto_blacklist:
          videos:
            of_users:
              enabled: false
        instance:
          name: 'Immae’s PeerTube'
          short_description: 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser with WebTorrent and Angular.'
          description: '''
          terms: '''
          code_of_conduct: '''
          moderation_information: '''
          creation_reason: '''
          administrator: '''
          maintenance_lifetime: '''
          business_model: '''
          hardware_information: '''
          languages:
          categories:
          default_client_route: '/videos/trending'
          is_nsfw: false
          default_nsfw_policy: 'do_not_list'
          customizations:
            javascript: '''
            css: '''
          robots: |
            User-agent: *
            Disallow:
          securitytxt:
            "# If you would like to report a security issue\n# you may report it to:\nContact: https://github.com/Chocobozzz/PeerTube/blob/develop/SECURITY.md\nContact: mailto:"
        services:
          twitter:
            username: '@_immae'
            whitelisted: false
        followers:
          instance:
            enabled: true
            manual_approval: false
        followings:
          instance:
            auto_follow_back:
              enabled: false
            auto_follow_index:
              enabled: false
              index_url: 'https://instances.joinpeertube.org'
        theme:
          default: 'default'
        '';
    }];

    services.websites.env.tools.modules = [
      "headers" "proxy" "proxy_http" "proxy_wstunnel"
    ];
    services.filesWatcher.peertube = {
      restart = true;
      paths = [ pcfg.configFile ];
    };

    services.websites.env.tools.vhostConfs.peertube = {
      certName    = "eldiron";
      addToCerts  = true;
      hosts       = [ "peertube.immae.eu" ];
      root        = null;
      extraConfig = [ ''
          RewriteEngine On

          RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
          RewriteCond %{QUERY_STRING} transport=websocket    [NC]
          RewriteRule /(.*)           ws://localhost:${toString env.listenPort}/$1 [P,NE,QSA,L]

          RewriteCond %{REQUEST_URI}  ^/tracker/socket       [NC]
          RewriteRule /(.*)           ws://localhost:${toString env.listenPort}/$1 [P,NE,QSA,L]

          ProxyPass /        http://localhost:${toString env.listenPort}/
          ProxyPassReverse / http://localhost:${toString env.listenPort}/

          ProxyPreserveHost On
          RequestHeader set X-Real-IP %{REMOTE_ADDR}s
      '' ];
    };
  };
}