diff options
Diffstat (limited to 'virtual/modules/websites/tools/tools/wallabag.nix')
-rw-r--r-- | virtual/modules/websites/tools/tools/wallabag.nix | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/virtual/modules/websites/tools/tools/wallabag.nix b/virtual/modules/websites/tools/tools/wallabag.nix new file mode 100644 index 0000000..92787b8 --- /dev/null +++ b/virtual/modules/websites/tools/tools/wallabag.nix | |||
@@ -0,0 +1,160 @@ | |||
1 | { stdenv, fetchurl, writeText, checkEnv, phpPackages, php, which }: | ||
2 | let | ||
3 | wallabag = rec { | ||
4 | varDir = "/var/lib/wallabag"; | ||
5 | parameters = | ||
6 | assert checkEnv "NIXOPS_WALLABAG_SQL_PASSWORD"; | ||
7 | assert checkEnv "NIXOPS_WALLABAG_SECRET"; | ||
8 | assert checkEnv "NIXOPS_WALLABAG_LDAP_PASSWORD"; | ||
9 | writeText "parameters.yml" '' | ||
10 | # This file is auto-generated during the composer install | ||
11 | parameters: | ||
12 | database_driver: pdo_pgsql | ||
13 | database_driver_class: Wallabag\CoreBundle\Doctrine\DBAL\Driver\CustomPostgreSQLDriver | ||
14 | database_host: db-1.immae.eu | ||
15 | database_port: null | ||
16 | database_name: webapps | ||
17 | database_user: wallabag | ||
18 | database_password: ${builtins.getEnv "NIXOPS_WALLABAG_SQL_PASSWORD"} | ||
19 | database_path: null | ||
20 | database_table_prefix: wallabag_ | ||
21 | database_socket: null | ||
22 | database_charset: utf8 | ||
23 | domain_name: https://tools.immae.eu/wallabag | ||
24 | mailer_transport: smtp | ||
25 | mailer_host: mail.immae.eu | ||
26 | mailer_user: null | ||
27 | mailer_password: null | ||
28 | locale: fr | ||
29 | secret: ${builtins.getEnv "NIXOPS_WALLABAG_SECRET"} | ||
30 | twofactor_auth: true | ||
31 | twofactor_sender: wallabag@immae.eu | ||
32 | fosuser_registration: false | ||
33 | fosuser_confirmation: true | ||
34 | from_email: wallabag@immae.eu | ||
35 | rss_limit: 50 | ||
36 | rabbitmq_host: localhost | ||
37 | rabbitmq_port: 5672 | ||
38 | rabbitmq_user: guest | ||
39 | rabbitmq_password: guest | ||
40 | rabbitmq_prefetch_count: 10 | ||
41 | redis_scheme: tcp | ||
42 | redis_host: localhost | ||
43 | redis_port: 6379 | ||
44 | redis_path: null | ||
45 | redis_password: null | ||
46 | sites_credentials: { } | ||
47 | ldap_enabled: true | ||
48 | ldap_host: ldap.immae.eu | ||
49 | ldap_port: 636 | ||
50 | ldap_tls: false | ||
51 | ldap_ssl: true | ||
52 | ldap_bind_requires_dn: true | ||
53 | ldap_base: 'dc=immae,dc=eu' | ||
54 | ldap_manager_dn: 'cn=wallabag,ou=services,dc=immae,dc=eu' | ||
55 | ldap_manager_pw: ${builtins.getEnv "NIXOPS_WALLABAG_LDAP_PASSWORD"} | ||
56 | ldap_filter: '(&(memberOf=cn=users,cn=wallabag,ou=services,dc=immae,dc=eu))' | ||
57 | ldap_admin_filter: '(&(memberOf=cn=admins,cn=wallabag,ou=services,dc=immae,dc=eu)(uid=%s))' | ||
58 | ldap_username_attribute: uid | ||
59 | ldap_email_attribute: mail | ||
60 | ldap_name_attribute: cn | ||
61 | ldap_enabled_attribute: null | ||
62 | ''; | ||
63 | webappDir = stdenv.mkDerivation rec { | ||
64 | # Beware when upgrading, I probably messed up with the migrations table | ||
65 | # (due to a psql bug in wallabag) | ||
66 | version = "2.3.2"; | ||
67 | name = "wallabag-${version}"; | ||
68 | src = fetchurl { | ||
69 | url = "https://static.wallabag.org/releases/wallabag-release-${version}.tar.gz"; | ||
70 | sha256 = "17yczdvgl43j6wa7hksxi2b51afvyd56vdya6hbbv68iiba4jyh4"; | ||
71 | }; | ||
72 | patches = [ ./wallabag_ldap.patch ]; | ||
73 | dontBuild = "true"; | ||
74 | installPhase = '' | ||
75 | cp -a . $out | ||
76 | cd $out | ||
77 | export SYMFONY_ENV=prod | ||
78 | php -d memory_limit=-1 ${phpPackages.composer}/libexec/composer/composer.phar require --update-no-dev -o --prefer-dist fr3d/ldap-bundle | ||
79 | rm -rf web/assets var/cache app/config/parameters.yml data | ||
80 | mv var var_old | ||
81 | ln -sf ${parameters} app/config/parameters.yml | ||
82 | ln -sf ../../../../../${varDir}/var var | ||
83 | ln -sf ../../../../../${varDir}/data data | ||
84 | ln -sf ../../../../../../${varDir}/assets web/assets | ||
85 | ''; | ||
86 | buildInputs = [ php phpPackages.composer ]; | ||
87 | }; | ||
88 | activationScript = '' | ||
89 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | ||
90 | ${varDir}/var ${varDir}/data/db ${varDir}/assets/images | ||
91 | if [ ! -f "${varDir}/currentWebappDir" -o \ | ||
92 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | ||
93 | pushd ${webappDir} > /dev/null | ||
94 | $wrapperDir/sudo -u wwwrun ./bin/console --env=prod doctrine:migrations:migrate --no-interaction | ||
95 | $wrapperDir/sudo -u wwwrun ./bin/console --env=prod cache:clear | ||
96 | popd > /dev/null | ||
97 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | ||
98 | fi | ||
99 | ''; | ||
100 | webRoot = "${webappDir}/web"; | ||
101 | apache = { | ||
102 | user = "wwwrun"; | ||
103 | group = "wwwrun"; | ||
104 | modules = [ "proxy_fcgi" ]; | ||
105 | vhostConf = '' | ||
106 | # FIXME | ||
107 | Alias /assets "${varDir}/assets" | ||
108 | Alias /wallabag "${webRoot}" | ||
109 | <Directory "${webRoot}"> | ||
110 | AllowOverride None | ||
111 | Require all granted | ||
112 | # For OAuth (apps) | ||
113 | CGIPassAuth On | ||
114 | |||
115 | <FilesMatch "\.php$"> | ||
116 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
117 | </FilesMatch> | ||
118 | |||
119 | <IfModule mod_rewrite.c> | ||
120 | Options -MultiViews | ||
121 | RewriteEngine On | ||
122 | RewriteCond %{REQUEST_FILENAME} !-f | ||
123 | RewriteRule ^(.*)$ app.php [QSA,L] | ||
124 | </IfModule> | ||
125 | </Directory> | ||
126 | <Directory "${webRoot}/bundles"> | ||
127 | <IfModule mod_rewrite.c> | ||
128 | RewriteEngine Off | ||
129 | </IfModule> | ||
130 | </Directory> | ||
131 | <Directory "${varDir}/assets"> | ||
132 | AllowOverride None | ||
133 | Require all granted | ||
134 | </Directory> | ||
135 | ''; | ||
136 | }; | ||
137 | phpFpm = rec { | ||
138 | basedir = builtins.concatStringsSep ":" [ webappDir parameters varDir ]; | ||
139 | socket = "/var/run/phpfpm/wallabag.sock"; | ||
140 | pool = '' | ||
141 | listen = ${socket} | ||
142 | user = ${apache.user} | ||
143 | group = ${apache.group} | ||
144 | listen.owner = ${apache.user} | ||
145 | listen.group = ${apache.group} | ||
146 | pm = dynamic | ||
147 | pm.max_children = 60 | ||
148 | pm.start_servers = 2 | ||
149 | pm.min_spare_servers = 1 | ||
150 | pm.max_spare_servers = 10 | ||
151 | |||
152 | ; Needed to avoid clashes in browser cookies (same domain) | ||
153 | php_value[session.name] = WallabagPHPSESSID | ||
154 | php_admin_value[open_basedir] = "${basedir}:/tmp" | ||
155 | php_value[max_execution_time] = 300 | ||
156 | ''; | ||
157 | }; | ||
158 | }; | ||
159 | in | ||
160 | wallabag | ||