]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Move yourls to pkgs
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 7 May 2019 07:06:29 +0000 (09:06 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 7 May 2019 08:19:52 +0000 (10:19 +0200)
nixops/modules/websites/tools/tools/default.nix
nixops/modules/websites/tools/tools/yourls.nix
pkgs/webapps/default.nix
pkgs/webapps/yourls/default.nix [new file with mode: 0644]
pkgs/webapps/yourls/plugins/ldap/default.nix [new file with mode: 0644]
pkgs/webapps/yourls/plugins/ldap/ldap.json [moved from nixops/modules/websites/tools/tools/yourls-ldap-plugin.json with 100% similarity]
pkgs/webapps/yourls/yourls.json [moved from nixops/modules/websites/tools/tools/yourls.json with 100% similarity]

index 262e5587ec8b4974440da1906f7dbbe540fadba1..746119bae8738c29e5640803b1acd89ed843a6e6 100644 (file)
@@ -18,7 +18,7 @@ let
     };
     wallabag = pkgs.callPackage ./wallabag.nix { env = myconfig.env.tools.wallabag; };
     yourls = pkgs.callPackage ./yourls.nix {
-      inherit (mylibs) fetchedGithub;
+      inherit (pkgs.webapps) yourls yourls-plugins;
       env = myconfig.env.tools.yourls;
     };
     rompr = pkgs.callPackage ./rompr.nix {
index 470fb7bd6e4db2f03380a55445b77c8cbbbfa45f..df1b3a2e822c95116599afa1af242735dc6b65d0 100644 (file)
-{ 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
-    '';
-    keys = [{
-      dest = "webapps/tools-yourls";
-      user = apache.user;
-      group = apache.group;
-      permissions = "0400";
-      text = ''
-        <?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', '${env.mysql.host}' );
-        define( 'YOURLS_DB_PREFIX', 'yourls_' );
-        define( 'YOURLS_SITE', 'https://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}' );
+{ env, yourls, yourls-plugins }:
+rec {
+  activationScript = ''
+    install -m 0755 -o ${apache.user} -g ${apache.group} -d /var/lib/php/sessions/yourls
+  '';
+  keys = [{
+    dest = "webapps/tools-yourls";
+    user = apache.user;
+    group = apache.group;
+    permissions = "0400";
+    text = ''
+      <?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', '${env.mysql.host}' );
+      define( 'YOURLS_DB_PREFIX', 'yourls_' );
+      define( 'YOURLS_SITE', 'https://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_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 /var/secrets/webapps/tools-yourls $out/includes/config.php
-        ${builtins.concatStringsSep "\n" (
-          lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/user/plugins/${name}") plugins
-        )}
-      '';
-    });
-    apache = rec {
-      user = "wwwrun";
-      group = "wwwrun";
-      modules = [ "proxy_fcgi" ];
-      webappName = "tools_yourls";
-      root = "/run/current-system/webapps/${webappName}";
-      vhostConf = ''
-        Alias /url "${root}"
-        <Directory "${root}">
-          <FilesMatch "\.php$">
-            SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
-          </FilesMatch>
+      define( 'LDAPAUTH_USERCACHE_TYPE', 0);
+    '';
+  }];
+  webRoot = (yourls.override { yourls_config = "/var/secrets/webapps/tools-yourls"; }).withPlugins
+    (builtins.attrValues yourls-plugins);
+  apache = rec {
+    user = "wwwrun";
+    group = "wwwrun";
+    modules = [ "proxy_fcgi" ];
+    webappName = "tools_yourls";
+    root = "/run/current-system/webapps/${webappName}";
+    vhostConf = ''
+      Alias /url "${root}"
+      <Directory "${root}">
+        <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 {
-      serviceDeps = [ "mysql.service" "openldap.service" ];
-      basedir = builtins.concatStringsSep ":" (
-        [ webRoot "/var/secrets/webapps/tools-yourls" ]
-        ++ 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
+        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 {
+    serviceDeps = [ "mysql.service" "openldap.service" ];
+    basedir = builtins.concatStringsSep ":" (
+      [ webRoot "/var/secrets/webapps/tools-yourls" ]
+      ++ webRoot.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:/var/lib/php/sessions/yourls"
-        php_admin_value[session.save_path] = "/var/lib/php/sessions/yourls"
-        '';
-    };
+      ; Needed to avoid clashes in browser cookies (same domain)
+      php_value[session.name] = YourlsPHPSESSID
+      php_admin_value[open_basedir] = "${basedir}:/tmp:/var/lib/php/sessions/yourls"
+      php_admin_value[session.save_path] = "/var/lib/php/sessions/yourls"
+      '';
   };
-in 
-  yourls
+}
index 1dde9ca7bd3696c1a42fcd7755c22174079771e1..f9ecd4f6272e894ef12752816e3b1a33e55f2a3b 100644 (file)
@@ -49,4 +49,12 @@ rec {
 
   phpldapadmin = callPackage ./phpldapadmin {};
   rompr = callPackage ./rompr { inherit mylibs; };
+
+  yourls = callPackage ./yourls { inherit mylibs; };
+  yourls-with-plugins = yourls.withPlugins (builtins.attrValues yourls-plugins);
+  yourls-plugins = let
+    names = [ "ldap" ];
+  in
+    lib.attrsets.genAttrs names
+      (name: callPackage (./yourls/plugins + "/${name}") { inherit mylibs; });
 }
diff --git a/pkgs/webapps/yourls/default.nix b/pkgs/webapps/yourls/default.nix
new file mode 100644 (file)
index 0000000..cc880cd
--- /dev/null
@@ -0,0 +1,24 @@
+{ yourls_config ? "/etc/yourls/config.php", mylibs, stdenv }:
+let
+  withPlugins = plugins: package.overrideAttrs(old: {
+    name = "${old.name}-with-plugins";
+    installPhase = old.installPhase +
+      builtins.concatStringsSep "\n" (
+        map (value: "ln -s ${value} $out/user/plugins/${value.pluginName}") plugins
+      );
+    passthru.plugins = plugins;
+    passthru.withPlugins = morePlugins: old.withPlugins (morePlugins ++ plugins);
+  });
+  package = stdenv.mkDerivation (mylibs.fetchedGithub ./yourls.json // rec {
+    installPhase = ''
+      mkdir -p $out
+      cp -a */ *.php $out/
+      cp sample-robots.txt $out/robots.txt
+      ln -sf ${yourls_config} $out/includes/config.php
+    '';
+    passthru = {
+      plugins = [];
+      inherit withPlugins;
+    };
+  });
+in package
diff --git a/pkgs/webapps/yourls/plugins/ldap/default.nix b/pkgs/webapps/yourls/plugins/ldap/default.nix
new file mode 100644 (file)
index 0000000..01dc6fb
--- /dev/null
@@ -0,0 +1,8 @@
+{ stdenv, mylibs }:
+stdenv.mkDerivation (mylibs.fetchedGithub ./ldap.json // rec {
+  installPhase = ''
+    mkdir -p $out
+    cp plugin.php $out
+    '';
+  passthru.pluginName = "ldap";
+})