]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - nixops/modules/websites/tools/tools/ttrss.nix
Move ttrss to pkgs
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / tools / ttrss.nix
index 95cca9d68f819eb20860874e0f102304abf2081d..05c8cab04452831878754e25e9594892105b4c8b 100644 (file)
@@ -1,58 +1,27 @@
-{ lib, php, env, writeText, stdenv, fetchedGit, fetchedGithub }:
-let
-  ttrss = let
-    plugins = {
-      auth_ldap = stdenv.mkDerivation (fetchedGithub ./ttrss-auth-ldap.json // rec {
-        installPhase = ''
-          mkdir $out
-          cp plugins/auth_ldap/init.php $out
-        '';
-      });
-      af_feedmod = stdenv.mkDerivation (fetchedGithub ./ttrss-af_feedmod.json // rec {
-        patches = [ ./ttrss-af-feedmod_type_replace.patch ];
-        installPhase = ''
-          mkdir $out
-          cp init.php $out
-        '';
-      });
-      feediron = stdenv.mkDerivation (fetchedGithub ./ttrss-feediron.json // rec {
-        patches = [ ./ttrss-feediron_json_reformat.patch ];
-        installPhase = ''
-          mkdir $out
-          cp -a . $out
-        '';
-      });
-      ff_instagram = stdenv.mkDerivation (fetchedGithub ./ttrss-ff_instagram.json // rec {
-        installPhase = ''
-          mkdir $out
-          cp -a . $out
-        '';
-      });
-      tumblr_gdpr_ua = stdenv.mkDerivation (fetchedGithub ./ttrss-tumblr_gdpr_ua.json // rec {
-        installPhase = ''
-          mkdir $out
-          cp -a . $out
-        '';
-      });
-    };
-  in rec {
-    varDir = "/var/lib/ttrss";
-    activationScript = {
-      deps = [ "wrappers" ];
-      text = ''
-        install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
-          ${varDir}/lock ${varDir}/cache ${varDir}/feed-icons
-        install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}/cache/export/ \
-          ${varDir}/cache/feeds/ \
-          ${varDir}/cache/images/ \
-          ${varDir}/cache/js/ \
-          ${varDir}/cache/simplepie/ \
-          ${varDir}/cache/upload/
-        touch ${varDir}/feed-icons/index.html
-        install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
-      '';
-    };
-    config = writeText "config.php" ''
+{ php, env, ttrss, ttrss-plugins }:
+rec {
+  varDir = "/var/lib/ttrss";
+  activationScript = {
+    deps = [ "wrappers" ];
+    text = ''
+      install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
+        ${varDir}/lock ${varDir}/cache ${varDir}/feed-icons
+      install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}/cache/export/ \
+        ${varDir}/cache/feeds/ \
+        ${varDir}/cache/images/ \
+        ${varDir}/cache/js/ \
+        ${varDir}/cache/simplepie/ \
+        ${varDir}/cache/upload/
+      touch ${varDir}/feed-icons/index.html
+      install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
+    '';
+  };
+  keys = [{
+    dest = "webapps/tools-ttrss";
+    user = apache.user;
+    group = apache.group;
+    permissions = "0400";
+    text = ''
       <?php
 
         define('PHP_EXECUTABLE', '${php}/bin/php');
@@ -94,16 +63,11 @@ let
         define('SPHINX_INDEX', 'ttrss, delta');
 
         define('ENABLE_REGISTRATION', false);
-        define('REG_NOTIFY_ADDRESS', 'outils@immae.eu');
+        define('REG_NOTIFY_ADDRESS', 'ttrss@tools.immae.eu');
         define('REG_MAX_USERS', 10);
 
-        define('SMTP_SERVER', 'mail.immae.eu:25');
-        define('SMTP_LOGIN', ''');
-        define('SMTP_PASSWORD', ''');
-        define('SMTP_SECURE', 'tls');
-
         define('SMTP_FROM_NAME', 'Tiny Tiny RSS');
-        define('SMTP_FROM_ADDRESS', 'outils@immae.eu');
+        define('SMTP_FROM_ADDRESS', 'ttrss@tools.immae.eu');
         define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');
 
         define('LDAP_AUTH_SERVER_URI', 'ldap://ldap.immae.eu:389/');
@@ -120,58 +84,48 @@ let
         define('LDAP_AUTH_LOG_ATTEMPTS', FALSE);
         define('LDAP_AUTH_DEBUG', FALSE);
       '';
-    webRoot = stdenv.mkDerivation (fetchedGit ./tt-rss.json // rec {
-      buildPhase = ''
-        rm -rf lock feed-icons cache
-        ln -sf ../../../../../${varDir}/{lock,feed-icons,cache} .
+  }];
+  webRoot = (ttrss.override { ttrss_config = "/var/secrets/webapps/tools-ttrss"; }).withPlugins (builtins.attrValues ttrss-plugins);
+  apache = rec {
+    user = "wwwrun";
+    group = "wwwrun";
+    modules = [ "proxy_fcgi" ];
+    webappName = "tools_ttrss";
+    root = "/run/current-system/webapps/${webappName}";
+    vhostConf = ''
+      Alias /ttrss "${root}"
+      <Directory "${root}">
+        DirectoryIndex index.php
+        <FilesMatch "\.php$">
+          SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
+        </FilesMatch>
+
+        AllowOverride All
+        Options FollowSymlinks
+        Require all granted
+      </Directory>
       '';
-      installPhase = ''
-        cp -a . $out
-        ln -s ${config} $out/config.php
-        ${builtins.concatStringsSep "\n" (
-          lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/plugins/${name}") plugins
-        )}
+  };
+  phpFpm = rec {
+    serviceDeps = [ "postgresql.service" "openldap.service" ];
+    basedir = builtins.concatStringsSep ":" (
+      [ webRoot "/var/secrets/webapps/tools-ttrss" varDir ]
+      ++ webRoot.plugins);
+    socket = "/var/run/phpfpm/ttrss.sock";
+    pool = ''
+      listen = ${socket}
+      user = ${apache.user}
+      group = ${apache.group}
+      listen.owner = ${apache.user}
+      listen.group = ${apache.group}
+      pm = ondemand
+      pm.max_children = 60
+      pm.process_idle_timeout = 60
+
+      ; Needed to avoid clashes in browser cookies (same domain)
+      php_value[session.name] = TtrssPHPSESSID
+      php_admin_value[open_basedir] = "${basedir}:/tmp"
+      php_admin_value[session.save_path] = "${varDir}/phpSessions"
       '';
-    });
-    apache = {
-      user = "wwwrun";
-      group = "wwwrun";
-      modules = [ "proxy_fcgi" ];
-      vhostConf = ''
-        Alias /ttrss "${webRoot}"
-        <Directory "${webRoot}">
-          DirectoryIndex index.php
-          <FilesMatch "\.php$">
-            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
-          </FilesMatch>
-
-          AllowOverride All
-          Options FollowSymlinks
-          Require all granted
-        </Directory>
-        '';
-    };
-    phpFpm = rec {
-      basedir = builtins.concatStringsSep ":" (
-        [ webRoot config varDir ]
-        ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
-      socket = "/var/run/phpfpm/ttrss.sock";
-      pool = ''
-        listen = ${socket}
-        user = ${apache.user}
-        group = ${apache.group}
-        listen.owner = ${apache.user}
-        listen.group = ${apache.group}
-        pm = ondemand
-        pm.max_children = 60
-        pm.process_idle_timeout = 60
-
-        ; Needed to avoid clashes in browser cookies (same domain)
-        php_value[session.name] = TtrssPHPSESSID
-        php_admin_value[open_basedir] = "${basedir}:/tmp"
-        php_admin_value[session.save_path] = "${varDir}/phpSessions"
-        '';
-    };
   };
-in 
-  ttrss
+}