]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/tools/tools/yourls.nix
Fix the SSL state for databases connections
[perso/Immae/Config/Nix.git] / nixops / modules / websites / tools / tools / yourls.nix
CommitLineData
133ebaee
IB
1{ lib, env, writeText, stdenv, fetchedGithub }:
2let
3 yourls = let
4 plugins = {
5 ldap = stdenv.mkDerivation (fetchedGithub ./yourls-ldap-plugin.json // rec {
6 installPhase = ''
7 mkdir -p $out
8 cp plugin.php $out/
9 '';
10 });
11 };
12 in rec {
13 activationScript = ''
14 install -m 0755 -o ${apache.user} -g ${apache.group} -d /var/lib/php/sessions/yourls
15 '';
16 config = writeText "config.php" ''
17 <?php
18 define( 'YOURLS_DB_USER', '${env.mysql.user}' );
19 define( 'YOURLS_DB_PASS', '${env.mysql.password}' );
20 define( 'YOURLS_DB_NAME', '${env.mysql.database}' );
7ebcaad5 21 define( 'YOURLS_DB_HOST', '${env.mysql.host}' );
133ebaee 22 define( 'YOURLS_DB_PREFIX', 'yourls_' );
7ebcaad5 23 define( 'YOURLS_SITE', 'https://tools.immae.eu/url' );
133ebaee
IB
24 define( 'YOURLS_HOURS_OFFSET', 0 );
25 define( 'YOURLS_LANG', ''' );
26 define( 'YOURLS_UNIQUE_URLS', true );
27 define( 'YOURLS_PRIVATE', true );
28 define( 'YOURLS_COOKIEKEY', '${env.cookieKey}' );
29 $yourls_user_passwords = array();
30 define( 'YOURLS_DEBUG', false );
31 define( 'YOURLS_URL_CONVERT', 36 );
32 $yourls_reserved_URL = array();
33 define( 'LDAPAUTH_HOST', 'ldaps://ldap.immae.eu' );
34 define( 'LDAPAUTH_PORT', '636' );
35 define( 'LDAPAUTH_BASE', 'dc=immae,dc=eu' );
36 define( 'LDAPAUTH_SEARCH_USER', 'cn=yourls,ou=services,dc=immae,dc=eu' );
37 define( 'LDAPAUTH_SEARCH_PASS', '${env.ldap.password}' );
38
39 define( 'LDAPAUTH_GROUP_ATTR', 'memberof' );
40 define( 'LDAPAUTH_GROUP_REQ', 'cn=admin,cn=yourls,ou=services,dc=immae,dc=eu');
41
42 define( 'LDAPAUTH_USERCACHE_TYPE', 0);
43 '';
44 webRoot = stdenv.mkDerivation (fetchedGithub ./yourls.json // rec {
45 installPhase = ''
46 mkdir -p $out
47 cp -a */ *.php $out/
48 cp sample-robots.txt $out/robots.txt
49 ln -sf ${config} $out/includes/config.php
50 ${builtins.concatStringsSep "\n" (
51 lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/user/plugins/${name}") plugins
52 )}
53 '';
54 });
55 apache = {
56 user = "wwwrun";
57 group = "wwwrun";
58 modules = [ "proxy_fcgi" ];
59 vhostConf = ''
60 Alias /url "${webRoot}"
61 <Directory "${webRoot}">
62 <FilesMatch "\.php$">
63 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
64 </FilesMatch>
65
66 AllowOverride None
67 Require all granted
68 <IfModule mod_rewrite.c>
69 RewriteEngine On
70 RewriteBase /url/
71 RewriteCond %{REQUEST_FILENAME} !-f
72 RewriteCond %{REQUEST_FILENAME} !-d
73 RewriteRule ^.*$ /url/yourls-loader.php [L]
74 </IfModule>
75 DirectoryIndex index.php
76 </Directory>
77 '';
78 };
79 phpFpm = rec {
80 basedir = builtins.concatStringsSep ":" (
81 [ webRoot config ]
82 ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
83 socket = "/var/run/phpfpm/yourls.sock";
84 pool = ''
85 listen = ${socket}
86 user = ${apache.user}
87 group = ${apache.group}
88 listen.owner = ${apache.user}
89 listen.group = ${apache.group}
90 pm = ondemand
91 pm.max_children = 60
92 pm.process_idle_timeout = 60
93
94 ; Needed to avoid clashes in browser cookies (same domain)
95 php_value[session.name] = YourlsPHPSESSID
96 php_admin_value[open_basedir] = "${basedir}:/tmp"
97 php_admin_value[session.save_path] = "/var/lib/php/sessions/yourls"
98 '';
99 };
100 };
101in
102 yourls