]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/tools/tools/wallabag.nix
Fix passthru’s in pkgs
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / tools / wallabag.nix
CommitLineData
a3d281ea 1{ stdenv, fetchurl, writeText, env, composerEnv, phpPackages, php, which }:
aebd817b
IB
2let
3 wallabag = rec {
4 varDir = "/var/lib/wallabag";
8db8e666
IB
5 keys = [{
6 dest = "webapps/tools-wallabag";
a840a21c
IB
7 user = apache.user;
8 group = apache.group;
85f5ed68 9 permissions = "0400";
a840a21c
IB
10 text = ''
11 # This file is auto-generated during the composer install
12 parameters:
13 database_driver: pdo_pgsql
14 database_driver_class: Wallabag\CoreBundle\Doctrine\DBAL\Driver\CustomPostgreSQLDriver
15 database_host: ${env.postgresql.socket}
16 database_port: ${env.postgresql.port}
17 database_name: ${env.postgresql.database}
18 database_user: ${env.postgresql.user}
19 database_password: ${env.postgresql.password}
20 database_path: null
21 database_table_prefix: wallabag_
22 database_socket: null
23 database_charset: utf8
24 domain_name: https://tools.immae.eu/wallabag
25 mailer_transport: sendmail
26 mailer_host: 127.0.0.1
27 mailer_user: null
28 mailer_password: null
29 locale: fr
30 secret: ${env.secret}
31 twofactor_auth: true
32 twofactor_sender: wallabag@tools.immae.eu
33 fosuser_registration: false
34 fosuser_confirmation: true
35 from_email: wallabag@tools.immae.eu
36 rss_limit: 50
37 rabbitmq_host: localhost
38 rabbitmq_port: 5672
39 rabbitmq_user: guest
40 rabbitmq_password: guest
41 rabbitmq_prefetch_count: 10
42 redis_scheme: unix
43 redis_host: null
44 redis_port: null
45 redis_path: ${env.redis.socket}
46 redis_password: null
47 sites_credentials: { }
48 ldap_enabled: true
49 ldap_host: ldap.immae.eu
50 ldap_port: 636
51 ldap_tls: false
52 ldap_ssl: true
53 ldap_bind_requires_dn: true
54 ldap_base: 'dc=immae,dc=eu'
55 ldap_manager_dn: 'cn=wallabag,ou=services,dc=immae,dc=eu'
56 ldap_manager_pw: ${env.ldap.password}
57 ldap_filter: '(&(memberOf=cn=users,cn=wallabag,ou=services,dc=immae,dc=eu))'
58 ldap_admin_filter: '(&(memberOf=cn=admins,cn=wallabag,ou=services,dc=immae,dc=eu)(uid=%s))'
59 ldap_username_attribute: uid
60 ldap_email_attribute: mail
61 ldap_name_attribute: cn
62 ldap_enabled_attribute: null
63 services:
64 swiftmailer.mailer.default.transport:
65 class: Swift_SendmailTransport
66 arguments: ['/run/wrappers/bin/sendmail -bs']
67 '';
8db8e666 68 }];
a3d281ea
IB
69 webappDir = composerEnv.buildPackage rec {
70 packages = {
71 "fr3d/ldap-bundle" = {
72 targetDir = "";
73 src = composerEnv.buildZipPackage {
74 name = "fr3d-ldap-bundle-5a8927c11af45fa06331b97221c6da1a4a237475";
75 src = fetchurl {
76 url = https://api.github.com/repos/Maks3w/FR3DLdapBundle/zipball/5a8927c11af45fa06331b97221c6da1a4a237475;
77 sha256 = "168zkd82j200wd6h0a3lq81g5s2pifg889rv27q2g429nppsbfxc";
78 };
79 };
80 };
81 "zendframework/zend-ldap" = {
82 targetDir = "";
83 src = composerEnv.buildZipPackage {
84 name = "zendframework-zend-ldap-b63c7884a08d3a6bda60ebcf7d6238cf8ad89f49";
85 src = fetchurl {
86 url = https://api.github.com/repos/zendframework/zend-ldap/zipball/b63c7884a08d3a6bda60ebcf7d6238cf8ad89f49;
87 sha256 = "0mn4yqnb5prqhrbbybmw1i2rx7xf4s4wagbdq9qi55fa0vk3jgw9";
88 };
89 };
90 };
91 };
92 noDev = true;
93 doRemoveVendor = false;
aebd817b
IB
94 # Beware when upgrading, I probably messed up with the migrations table
95 # (due to a psql bug in wallabag)
03525bd4 96 version = "2.3.6";
aebd817b
IB
97 name = "wallabag-${version}";
98 src = fetchurl {
99 url = "https://static.wallabag.org/releases/wallabag-release-${version}.tar.gz";
03525bd4 100 sha256 = "0m0dy3r94ks5pfxyb9vbgrsm0vrwdl3jd5wqwg4f5vd107lq90q1";
aebd817b 101 };
a3d281ea
IB
102 unpackPhase = ''
103 unpackFile "$src"
104 sourceRoot=${version}
105 src=$PWD/${version}
106 '';
aebd817b 107 patches = [ ./wallabag_ldap.patch ];
a3d281ea
IB
108 preInstall = ''
109 export SYMFONY_ENV="prod"
110 '';
111 postInstall = ''
112 rm -rf web/assets var/{cache,logs,sessions} app/config/parameters.yml data
8db8e666 113 ln -sf /var/secrets/webapps/tools-wallabag app/config/parameters.yml
3c8d7f87
IB
114 ln -sf ${varDir}/var/{cache,logs,sessions} var
115 ln -sf ${varDir}/data data
116 ln -sf ${varDir}/assets web/assets
aebd817b 117 '';
aebd817b
IB
118 };
119 activationScript = ''
120 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
121 ${varDir}/var ${varDir}/data/db ${varDir}/assets/images
aebd817b
IB
122 '';
123 webRoot = "${webappDir}/web";
73ed4b90
IB
124 # Domain migration: Table wallabag_entry contains whole
125 # https://tools.immae.eu/wallabag domain name in preview_picture
a95ab089 126 apache = rec {
aebd817b
IB
127 user = "wwwrun";
128 group = "wwwrun";
129 modules = [ "proxy_fcgi" ];
a95ab089
IB
130 webappName = "tools_wallabag";
131 root = "/run/current-system/webapps/${webappName}";
aebd817b 132 vhostConf = ''
a95ab089
IB
133 Alias /wallabag "${root}"
134 <Directory "${root}">
aebd817b
IB
135 AllowOverride None
136 Require all granted
137 # For OAuth (apps)
138 CGIPassAuth On
139
140 <FilesMatch "\.php$">
141 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
142 </FilesMatch>
143
144 <IfModule mod_rewrite.c>
145 Options -MultiViews
146 RewriteEngine On
147 RewriteCond %{REQUEST_FILENAME} !-f
148 RewriteRule ^(.*)$ app.php [QSA,L]
149 </IfModule>
150 </Directory>
a95ab089 151 <Directory "${root}/bundles">
aebd817b
IB
152 <IfModule mod_rewrite.c>
153 RewriteEngine Off
154 </IfModule>
155 </Directory>
156 <Directory "${varDir}/assets">
157 AllowOverride None
158 Require all granted
159 </Directory>
160 '';
161 };
162 phpFpm = rec {
8eded9ec
IB
163 preStart = ''
164 if [ ! -f "${varDir}/currentWebappDir" -o \
165 ! -f "${varDir}/currentKey" -o \
166 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \
167 || ! sha512sum -c --status ${varDir}/currentKey; then
168 pushd ${webappDir} > /dev/null
169 /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod cache:clear
170 rm -rf /var/lib/wallabag/var/cache/pro_
171 /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=prod doctrine:migrations:migrate --no-interaction
172 popd > /dev/null
173 echo -n "${webappDir}" > ${varDir}/currentWebappDir
8db8e666 174 sha512sum /var/secrets/webapps/tools-wallabag > ${varDir}/currentKey
8eded9ec
IB
175 fi
176 '';
8db8e666
IB
177 serviceDeps = [ "postgresql.service" "openldap.service" ];
178 basedir = builtins.concatStringsSep ":" [ webappDir "/var/secrets/webapps/tools-wallabag" varDir ];
aebd817b
IB
179 socket = "/var/run/phpfpm/wallabag.sock";
180 pool = ''
181 listen = ${socket}
182 user = ${apache.user}
183 group = ${apache.group}
184 listen.owner = ${apache.user}
185 listen.group = ${apache.group}
186 pm = dynamic
187 pm.max_children = 60
188 pm.start_servers = 2
189 pm.min_spare_servers = 1
190 pm.max_spare_servers = 10
191
192 ; Needed to avoid clashes in browser cookies (same domain)
193 php_value[session.name] = WallabagPHPSESSID
591ebd87 194 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:${basedir}:/tmp"
aebd817b
IB
195 php_value[max_execution_time] = 300
196 '';
197 };
198 };
199in
200 wallabag