diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 08:37:18 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 08:37:18 +0100 |
commit | 133ebaee701a52a74fc6897498f44f006ea3c3d8 (patch) | |
tree | 595f1519dd87d72ee6ee993a7d5fa6366b152115 /virtual/modules/websites/tools/tools/yourls.nix | |
parent | 17146204f5a8d67e2dcc86b1fe2b7cc3593ed6bf (diff) | |
download | Nix-133ebaee701a52a74fc6897498f44f006ea3c3d8.tar.gz Nix-133ebaee701a52a74fc6897498f44f006ea3c3d8.tar.zst Nix-133ebaee701a52a74fc6897498f44f006ea3c3d8.zip |
Add yourls
Fixes https://git.immae.eu/mantisbt/view.php?id=68
Diffstat (limited to 'virtual/modules/websites/tools/tools/yourls.nix')
-rw-r--r-- | virtual/modules/websites/tools/tools/yourls.nix | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/virtual/modules/websites/tools/tools/yourls.nix b/virtual/modules/websites/tools/tools/yourls.nix new file mode 100644 index 0000000..b97dac9 --- /dev/null +++ b/virtual/modules/websites/tools/tools/yourls.nix | |||
@@ -0,0 +1,102 @@ | |||
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}' ); | ||
21 | define( 'YOURLS_DB_HOST', 'db-1.immae.eu' ); | ||
22 | define( 'YOURLS_DB_PREFIX', 'yourls_' ); | ||
23 | define( 'YOURLS_SITE', 'http://tools.immae.eu/url' ); | ||
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 | }; | ||
101 | in | ||
102 | yourls | ||