aboutsummaryrefslogtreecommitdiff
path: root/systems/eldiron/websites/tools/wallabag.nix
blob: 0a5750d67fe0008b6f6d46231d7d17394e2d9abf (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
{ env, wallabag, mylibs, config }:
rec {
  varDir = "/var/lib/wallabag";
  keys."webapps/tools-wallabag" = {
    user = apache.user;
    group = apache.group;
    permissions = "0400";
    text = ''
      # This file is auto-generated during the composer install
      parameters:
          database_driver: pdo_pgsql
          database_driver_class: Wallabag\CoreBundle\Doctrine\DBAL\Driver\CustomPostgreSQLDriver
          database_host: ${env.postgresql.socket}
          database_port: ${env.postgresql.port}
          database_name: ${env.postgresql.database}
          database_user: ${env.postgresql.user}
          database_password: ${env.postgresql.password}
          database_path: null
          database_table_prefix: wallabag_
          database_socket: null
          database_charset: utf8
          domain_name: https://tools.immae.eu/wallabag
          mailer_transport: sendmail
          mailer_host: 127.0.0.1
          mailer_user: null
          mailer_password: null
          locale: fr
          secret: ${env.secret}
          twofactor_auth: true
          twofactor_sender: wallabag@tools.immae.eu
          fosuser_registration: false
          fosuser_confirmation: true
          from_email: wallabag@tools.immae.eu
          rss_limit: 50
          rabbitmq_host: localhost
          rabbitmq_port: 5672
          rabbitmq_user: guest
          rabbitmq_password: guest
          rabbitmq_prefetch_count: 10
          redis_scheme: unix
          redis_host: null
          redis_port: null
          redis_path: ${env.redis.socket}
          redis_password: null
          sites_credentials: {  }
          ldap_enabled: true
          ldap_host: ${env.ldap.host}
          ldap_port: 636
          ldap_tls: false
          ldap_ssl: true
          ldap_bind_requires_dn: true
          ldap_base: '${env.ldap.base}'
          ldap_manager_dn: '${env.ldap.dn}'
          ldap_manager_pw: ${env.ldap.password}
          ldap_filter: '${env.ldap.filter}'
          ldap_admin_filter: '${env.ldap.admin_filter}'
          ldap_username_attribute: uid
          ldap_email_attribute: mail
          ldap_name_attribute: cn
          ldap_enabled_attribute: null
      services:
          swiftmailer.mailer.default.transport:
              class:     Swift_SendmailTransport
              arguments: ['/run/wrappers/bin/sendmail -bs']
      '';
  };
  chatonsProperties = {
    file.datetime = "2022-08-21T22:50:00";
    service = {
      name = "Wallabag";
      description = "wallabag is a self hostable application for saving web pages: Save and classify articles. Read them later. Freely.";
      website = "https://tools.immae.eu/wallabag/";
      logo = "https://tools.immae.eu/wallabag/wallassets/themes/_global/img/appicon/apple-touch-icon-120.png";
      status.level = "OK";
      status.description = "OK";
      registration."" = ["MEMBER" "CLIENT"];
      registration.load = "OPEN";
      install.type = "PACKAGE";
    };
    software = {
      name = "Wallabag";
      website = "https://wallabag.org/en";
      license.url = "https://github.com/wallabag/wallabag/blob/master/COPYING.md";
      license.name = "MIT License";
      version = webappDir.version;
      source.url = "https://github.com/wallabag/wallabag";
      modules = "ldap-patch";
    };
  };
  webappDir = wallabag.override { ldap = true; wallabag_config = config.secrets.fullPaths."webapps/tools-wallabag"; };
  activationScript = ''
    install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
      ${varDir}/var ${varDir}/data/db ${varDir}/assets/images
    '';
  webRoot = "${webappDir}/web";
  # Domain migration: Table wallabag_entry contains whole
  # https://tools.immae.eu/wallabag domain name in preview_picture
  apache = rec {
    user = "wwwrun";
    group = "wwwrun";
    modules = [ "proxy_fcgi" ];
    root = webRoot;
    vhostConf = socket: ''
      Alias /wallabag "${root}"
      <Directory "${root}">
        AllowOverride None
        Require all granted
        # For OAuth (apps)
        CGIPassAuth On

        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${socket}|fcgi://localhost"
        </FilesMatch>

        <IfModule mod_rewrite.c>
          Options -MultiViews
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^(.*)$ app.php [QSA,L]
        </IfModule>
      </Directory>
      <Directory "${root}/bundles">
        <IfModule mod_rewrite.c>
          RewriteEngine Off
        </IfModule>
      </Directory>
      <Directory "${varDir}/assets">
        AllowOverride None
        Require all granted
      </Directory>
      '';
  };
  phpFpm = rec {
    preStart = ''
      if [ ! -f "${varDir}/currentWebappDir" -o \
          ! -f "${varDir}/currentKey" -o \
          "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \
          || ! sha512sum -c --status ${varDir}/currentKey; then
        pushd ${webappDir} > /dev/null
        /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod cache:clear
        rm -rf /var/lib/wallabag/var/cache/pro_
        /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod doctrine:migrations:migrate --no-interaction
        popd > /dev/null
        echo -n "${webappDir}" > ${varDir}/currentWebappDir
        sha512sum ${config.secrets.fullPaths."webapps/tools-wallabag"} > ${varDir}/currentKey
      fi
    '';
    serviceDeps = [ "postgresql.service" "openldap.service" ];
    basedir = builtins.concatStringsSep ":" [ webappDir config.secrets.fullPaths."webapps/tools-wallabag" varDir ];
    pool = {
      "listen.owner" = apache.user;
      "listen.group" = apache.group;
      "pm" = "dynamic";
      "pm.max_children" = "60";
      "pm.start_servers" = "2";
      "pm.min_spare_servers" = "1";
      "pm.max_spare_servers" = "10";

      # Needed to avoid clashes in browser cookies (same domain)
      "php_value[session.name]" = "WallabagPHPSESSID";
      "php_admin_value[session.save_handler]" = "redis";
      "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Tools:Wallabag:'";
      "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${basedir}:/tmp";
      "php_value[max_execution_time]" = "300";
    };
  };
  monitoringPlugins = [ "http" ];
  monitoringObjects.service = [
    {
      service_description = "wallabag website is running on tools.immae.eu";
      host_name = config.hostEnv.fqdn;
      use = "external-web-service";
      check_command = ["check_https" "tools.immae.eu" "/wallabag/" "<title>Bienvenue sur wallabag"];

      servicegroups = "webstatus-webapps";
      _webstatus_name = "Wallabag";
      _webstatus_url = "https://tools.immae.eu/wallabag/";
    }
  ];
}