]>
Commit | Line | Data |
---|---|---|
133ebaee IB |
1 | { lib, env, writeText, stdenv, fetchedGithub }: |
2 | let | |
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 | }); | |
a95ab089 | 55 | apache = rec { |
133ebaee IB |
56 | user = "wwwrun"; |
57 | group = "wwwrun"; | |
58 | modules = [ "proxy_fcgi" ]; | |
a95ab089 IB |
59 | webappName = "tools_yourls"; |
60 | root = "/run/current-system/webapps/${webappName}"; | |
133ebaee | 61 | vhostConf = '' |
a95ab089 IB |
62 | Alias /url "${root}" |
63 | <Directory "${root}"> | |
133ebaee IB |
64 | <FilesMatch "\.php$"> |
65 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
66 | </FilesMatch> | |
67 | ||
68 | AllowOverride None | |
69 | Require all granted | |
70 | <IfModule mod_rewrite.c> | |
71 | RewriteEngine On | |
72 | RewriteBase /url/ | |
73 | RewriteCond %{REQUEST_FILENAME} !-f | |
74 | RewriteCond %{REQUEST_FILENAME} !-d | |
75 | RewriteRule ^.*$ /url/yourls-loader.php [L] | |
76 | </IfModule> | |
77 | DirectoryIndex index.php | |
78 | </Directory> | |
79 | ''; | |
80 | }; | |
81 | phpFpm = rec { | |
82 | basedir = builtins.concatStringsSep ":" ( | |
83 | [ webRoot config ] | |
84 | ++ lib.attrsets.mapAttrsToList (name: value: value) plugins); | |
85 | socket = "/var/run/phpfpm/yourls.sock"; | |
86 | pool = '' | |
87 | listen = ${socket} | |
88 | user = ${apache.user} | |
89 | group = ${apache.group} | |
90 | listen.owner = ${apache.user} | |
91 | listen.group = ${apache.group} | |
92 | pm = ondemand | |
93 | pm.max_children = 60 | |
94 | pm.process_idle_timeout = 60 | |
95 | ||
96 | ; Needed to avoid clashes in browser cookies (same domain) | |
97 | php_value[session.name] = YourlsPHPSESSID | |
98 | php_admin_value[open_basedir] = "${basedir}:/tmp" | |
99 | php_admin_value[session.save_path] = "/var/lib/php/sessions/yourls" | |
100 | ''; | |
101 | }; | |
102 | }; | |
103 | in | |
104 | yourls |