]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add yourls
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 25 Jan 2019 07:37:18 +0000 (08:37 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 25 Jan 2019 07:37:18 +0000 (08:37 +0100)
Fixes https://git.immae.eu/mantisbt/view.php?id=68

virtual/modules/websites/tools/tools/default.nix
virtual/modules/websites/tools/tools/yourls-ldap-plugin.json [new file with mode: 0644]
virtual/modules/websites/tools/tools/yourls.json [new file with mode: 0644]
virtual/modules/websites/tools/tools/yourls.nix [new file with mode: 0644]

index 294959c72455c50138426845d58d3a434817dd99..7fb4974bd7687a006ca5fe85876e1c4dc07c3575 100644 (file)
@@ -8,6 +8,10 @@ let
     };
     roundcubemail = pkgs.callPackage ./roundcubemail.nix { env = myconfig.env.tools.roundcubemail; };
     wallabag = pkgs.callPackage ./wallabag.nix { env = myconfig.env.tools.wallabag; };
+    yourls = pkgs.callPackage ./yourls.nix {
+      inherit (mylibs) fetchedGithub;
+      env = myconfig.env.tools.yourls;
+    };
 
     cfg = config.services.myWebsites.tools.tools;
 in {
@@ -23,7 +27,8 @@ in {
       ++ ympd.apache.modules
       ++ ttrss.apache.modules
       ++ roundcubemail.apache.modules
-      ++ wallabag.apache.modules;
+      ++ wallabag.apache.modules
+      ++ yourls.apache.modules;
 
     services.ympd = ympd.config // { enable = false; };
 
@@ -37,6 +42,7 @@ in {
         ttrss.apache.vhostConf
         roundcubemail.apache.vhostConf
         wallabag.apache.vhostConf
+        yourls.apache.vhostConf
       ];
     };
 
@@ -45,12 +51,14 @@ in {
       ttrss = ttrss.phpFpm.pool;
       roundcubemail = roundcubemail.phpFpm.pool;
       wallabag = wallabag.phpFpm.pool;
+      yourls = yourls.phpFpm.pool;
     };
 
     system.activationScripts = {
       ttrss = ttrss.activationScript;
       roundcubemail = roundcubemail.activationScript;
       wallabag = wallabag.activationScript;
+      yourls = yourls.activationScript;
     };
 
     systemd.services.tt-rss = {
diff --git a/virtual/modules/websites/tools/tools/yourls-ldap-plugin.json b/virtual/modules/websites/tools/tools/yourls-ldap-plugin.json
new file mode 100644 (file)
index 0000000..9411e4a
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "tag": "2a3cb03-master",
+  "meta": {
+    "name": "yourls-ldap-plugin",
+    "url": "https://github.com/k3a/yourls-ldap-plugin",
+    "branch": "master"
+  },
+  "github": {
+    "owner": "k3a",
+    "repo": "yourls-ldap-plugin",
+    "rev": "2a3cb0334b8a6b81b284a7196e614bbd2b2b1615",
+    "sha256": "0cchbnli77d295lzf7kjmn4dcxj2bmdqa9qc3f8l8qgmp4n5n0gh",
+    "fetchSubmodules": true
+  }
+}
diff --git a/virtual/modules/websites/tools/tools/yourls.json b/virtual/modules/websites/tools/tools/yourls.json
new file mode 100644 (file)
index 0000000..0a79b18
--- /dev/null
@@ -0,0 +1,15 @@
+{
+  "tag": "1.7.3",
+  "meta": {
+    "name": "yourls",
+    "url": "https://github.com/YOURLS/YOURLS",
+    "branch": "refs/tags/1.7.3"
+  },
+  "github": {
+    "owner": "YOURLS",
+    "repo": "YOURLS",
+    "rev": "077018822d3594229daa8343310d0b40804b9ddc",
+    "sha256": "1av6h619rwqn0yn0kjn2s2h3gmrhmxaaa9hd5ns4ralxgg731imd",
+    "fetchSubmodules": true
+  }
+}
diff --git a/virtual/modules/websites/tools/tools/yourls.nix b/virtual/modules/websites/tools/tools/yourls.nix
new file mode 100644 (file)
index 0000000..b97dac9
--- /dev/null
@@ -0,0 +1,102 @@
+{ lib, env, writeText, stdenv, fetchedGithub }:
+let
+  yourls = let
+    plugins = {
+      ldap = stdenv.mkDerivation (fetchedGithub ./yourls-ldap-plugin.json // rec {
+        installPhase = ''
+          mkdir -p $out
+          cp plugin.php $out/
+          '';
+      });
+    };
+  in rec {
+    activationScript = ''
+      install -m 0755 -o ${apache.user} -g ${apache.group} -d /var/lib/php/sessions/yourls
+    '';
+    config = writeText "config.php" ''
+        <?php
+        define( 'YOURLS_DB_USER', '${env.mysql.user}' );
+        define( 'YOURLS_DB_PASS', '${env.mysql.password}' );
+        define( 'YOURLS_DB_NAME', '${env.mysql.database}' );
+        define( 'YOURLS_DB_HOST', 'db-1.immae.eu' );
+        define( 'YOURLS_DB_PREFIX', 'yourls_' );
+        define( 'YOURLS_SITE', 'http://tools.immae.eu/url' );
+        define( 'YOURLS_HOURS_OFFSET', 0 ); 
+        define( 'YOURLS_LANG', ''' ); 
+        define( 'YOURLS_UNIQUE_URLS', true );
+        define( 'YOURLS_PRIVATE', true );
+        define( 'YOURLS_COOKIEKEY', '${env.cookieKey}' );
+        $yourls_user_passwords = array();
+        define( 'YOURLS_DEBUG', false );
+        define( 'YOURLS_URL_CONVERT', 36 );
+        $yourls_reserved_URL = array();
+        define( 'LDAPAUTH_HOST', 'ldaps://ldap.immae.eu' );
+        define( 'LDAPAUTH_PORT', '636' );
+        define( 'LDAPAUTH_BASE', 'dc=immae,dc=eu' );
+        define( 'LDAPAUTH_SEARCH_USER', 'cn=yourls,ou=services,dc=immae,dc=eu' );
+        define( 'LDAPAUTH_SEARCH_PASS', '${env.ldap.password}' );
+
+        define( 'LDAPAUTH_GROUP_ATTR', 'memberof' );
+        define( 'LDAPAUTH_GROUP_REQ', 'cn=admin,cn=yourls,ou=services,dc=immae,dc=eu');
+
+        define( 'LDAPAUTH_USERCACHE_TYPE', 0);
+      '';
+    webRoot = stdenv.mkDerivation (fetchedGithub ./yourls.json // rec {
+      installPhase = ''
+        mkdir -p $out
+        cp -a */ *.php $out/
+        cp sample-robots.txt $out/robots.txt
+        ln -sf ${config} $out/includes/config.php
+        ${builtins.concatStringsSep "\n" (
+          lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/user/plugins/${name}") plugins
+        )}
+      '';
+    });
+    apache = {
+      user = "wwwrun";
+      group = "wwwrun";
+      modules = [ "proxy_fcgi" ];
+      vhostConf = ''
+        Alias /url "${webRoot}"
+        <Directory "${webRoot}">
+          <FilesMatch "\.php$">
+            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
+          </FilesMatch>
+
+          AllowOverride None
+          Require all granted
+          <IfModule mod_rewrite.c>
+            RewriteEngine On
+            RewriteBase /url/
+            RewriteCond %{REQUEST_FILENAME} !-f
+            RewriteCond %{REQUEST_FILENAME} !-d
+            RewriteRule ^.*$ /url/yourls-loader.php [L]
+          </IfModule>
+          DirectoryIndex index.php
+        </Directory>
+        '';
+    };
+    phpFpm = rec {
+      basedir = builtins.concatStringsSep ":" (
+        [ webRoot config ]
+        ++ lib.attrsets.mapAttrsToList (name: value: value) plugins);
+      socket = "/var/run/phpfpm/yourls.sock";
+      pool = ''
+        listen = ${socket}
+        user = ${apache.user}
+        group = ${apache.group}
+        listen.owner = ${apache.user}
+        listen.group = ${apache.group}
+        pm = ondemand
+        pm.max_children = 60
+        pm.process_idle_timeout = 60
+
+        ; Needed to avoid clashes in browser cookies (same domain)
+        php_value[session.name] = YourlsPHPSESSID
+        php_admin_value[open_basedir] = "${basedir}:/tmp"
+        php_admin_value[session.save_path] = "/var/lib/php/sessions/yourls"
+        '';
+    };
+  };
+in 
+  yourls