aboutsummaryrefslogblamecommitdiff
path: root/modules/private/websites/tools/peertube/default.nix
blob: 3345453d1cec5138a1c8f21c59419648fb861e09 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                            
   
                                    
                                                  
                                  
    
                                                



                                                            


                                              


                                                         
                                                                                                  
      
                                                  
 
                     






                                      
                                                       



                                       










                                                
                             











                                                          


                                                

                                                 


                                                     
                                                                             






                                                           
                                                     


           
                                           

                                                     




                                      
                                                       
                              
                         


                                            



                                                                 
                                                                                               

                                                                 
                                                                                               
 

                                                                         


                                                     



           
{ 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
        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'
          from_address: 'peertube@tools.immae.eu'
        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/'
        '';
    }];

    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
      '' ];
    };
  };
}