From 452c23140ea93ce301e7fafdc37d28009bd6f613 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 4 May 2019 00:27:59 +0200 Subject: [PATCH] Move dav packages to pkgs --- nixops/modules/websites/tools/dav/davical.nix | 272 ++++++++---------- nixops/modules/websites/tools/dav/default.nix | 21 +- .../modules/websites/tools/dav/infcloud.nix | 40 --- pkgs/default.nix | 4 +- pkgs/webapps/awl/default.nix | 16 ++ ...79ebf9250e5f339675319902458c40ed1755.patch | 0 pkgs/webapps/davical/default.nix | 20 ++ pkgs/webapps/default.nix | 7 + pkgs/webapps/infcloud/default.nix | 18 ++ .../webapps/infcloud}/infcloud_config.js | 0 10 files changed, 198 insertions(+), 200 deletions(-) delete mode 100644 nixops/modules/websites/tools/dav/infcloud.nix create mode 100644 pkgs/webapps/awl/default.nix rename {nixops/modules/websites/tools/dav => pkgs/webapps/davical}/davical_19eb79ebf9250e5f339675319902458c40ed1755.patch (100%) create mode 100644 pkgs/webapps/davical/default.nix create mode 100644 pkgs/webapps/default.nix create mode 100644 pkgs/webapps/infcloud/default.nix rename {nixops/modules/websites/tools/dav => pkgs/webapps/infcloud}/infcloud_config.js (100%) diff --git a/nixops/modules/websites/tools/dav/davical.nix b/nixops/modules/websites/tools/dav/davical.nix index 1e3893f..6b37f11 100644 --- a/nixops/modules/websites/tools/dav/davical.nix +++ b/nixops/modules/websites/tools/dav/davical.nix @@ -1,169 +1,133 @@ -{ stdenv, fetchurl, gettext, writeText, env }: -let - awl = stdenv.mkDerivation rec { - version = "0.59"; - name = "awl-${version}"; - src = fetchurl { - url = "https://www.davical.org/downloads/awl_${version}.orig.tar.xz"; - sha256 = "01b7km7ga3ggbpp8axkc55nizgk5c35fl2z93iydb3hwbxmsvnjp"; - }; - unpackCmd = '' - tar --one-top-level -xf $curSrc - ''; - installPhase = '' - mkdir -p $out - cp -ra dba docs inc scripts tests $out - ''; - }; - davical = rec { - keys = [{ - dest = "webapps/dav-davical"; - user = apache.user; - group = apache.group; - permissions = "0400"; - text = '' - pg_connect[] = "dbname=${env.postgresql.database} user=${env.postgresql.user} host=${env.postgresql.socket} password=${env.postgresql.password}"; +{ stdenv, fetchurl, gettext, writeText, env, awl, davical }: +rec { + keys = [{ + dest = "webapps/dav-davical"; + user = apache.user; + group = apache.group; + permissions = "0400"; + text = '' + pg_connect[] = "dbname=${env.postgresql.database} user=${env.postgresql.user} host=${env.postgresql.socket} password=${env.postgresql.password}"; - $c->readonly_webdav_collections = false; + $c->readonly_webdav_collections = false; - $c->admin_email ='davical@tools.immae.eu'; + $c->admin_email ='davical@tools.immae.eu'; - $c->restrict_setup_to_admin = true; + $c->restrict_setup_to_admin = true; - $c->collections_always_exist = false; + $c->collections_always_exist = false; - $c->external_refresh = 60; + $c->external_refresh = 60; - $c->enable_scheduling = true; + $c->enable_scheduling = true; - $c->iMIP = (object) array("send_email" => true); + $c->iMIP = (object) array("send_email" => true); - $c->authenticate_hook['optional'] = false; - $c->authenticate_hook['call'] = 'LDAP_check'; - $c->authenticate_hook['config'] = array( - 'host' => 'ldap.immae.eu', - 'port' => '389', - 'startTLS' => 'yes', - 'bindDN'=> 'cn=davical,ou=services,dc=immae,dc=eu', - 'passDN'=> '${env.ldap.password}', - 'protocolVersion' => '3', - 'baseDNUsers'=> array('ou=users,dc=immae,dc=eu', 'ou=group_users,dc=immae,dc=eu'), - 'filterUsers' => 'memberOf=cn=users,cn=davical,ou=services,dc=immae,dc=eu', - 'baseDNGroups' => 'ou=groups,dc=immae,dc=eu', - 'filterGroups' => 'memberOf=cn=groups,cn=davical,ou=services,dc=immae,dc=eu', - 'mapping_field' => array( - "username" => "uid", - "fullname" => "cn", - "email" => "mail", - "modified" => "modifyTimestamp", - ), - 'format_updated'=> array('Y' => array(0,4),'m' => array(4,2),'d'=> array(6,2),'H' => array(8,2),'M'=>array(10,2),'S' => array(12,2)), - /** used to set default value for all users, will be overcharged by ldap if defined also in mapping_field **/ - // 'default_value' => array("date_format_type" => "E","locale" => "fr_FR"), - 'group_mapping_field' => array( - "username" => "cn", - "updated" => "modifyTimestamp", - "fullname" => "givenName", - "displayname" => "givenName", - "members" => "memberUid", - "email" => "mail", - ), - ); + $c->authenticate_hook['optional'] = false; + $c->authenticate_hook['call'] = 'LDAP_check'; + $c->authenticate_hook['config'] = array( + 'host' => 'ldap.immae.eu', + 'port' => '389', + 'startTLS' => 'yes', + 'bindDN'=> 'cn=davical,ou=services,dc=immae,dc=eu', + 'passDN'=> '${env.ldap.password}', + 'protocolVersion' => '3', + 'baseDNUsers'=> array('ou=users,dc=immae,dc=eu', 'ou=group_users,dc=immae,dc=eu'), + 'filterUsers' => 'memberOf=cn=users,cn=davical,ou=services,dc=immae,dc=eu', + 'baseDNGroups' => 'ou=groups,dc=immae,dc=eu', + 'filterGroups' => 'memberOf=cn=groups,cn=davical,ou=services,dc=immae,dc=eu', + 'mapping_field' => array( + "username" => "uid", + "fullname" => "cn", + "email" => "mail", + "modified" => "modifyTimestamp", + ), + 'format_updated'=> array('Y' => array(0,4),'m' => array(4,2),'d'=> array(6,2),'H' => array(8,2),'M'=>array(10,2),'S' => array(12,2)), + /** used to set default value for all users, will be overcharged by ldap if defined also in mapping_field **/ + // 'default_value' => array("date_format_type" => "E","locale" => "fr_FR"), + 'group_mapping_field' => array( + "username" => "cn", + "updated" => "modifyTimestamp", + "fullname" => "givenName", + "displayname" => "givenName", + "members" => "memberUid", + "email" => "mail", + ), + ); - $c->do_not_sync_from_ldap = array('admin' => true); - include('drivers_ldap.php'); - ''; - }]; - webapp = stdenv.mkDerivation rec { - version = "1.1.7"; - name = "davical-${version}"; - src = fetchurl { - url = "https://www.davical.org/downloads/davical_${version}.orig.tar.xz"; - sha256 = "1ar5m2dxr92b204wkdi8z33ir9vz2jbh5k1p74icpv9ywifvjjp9"; - }; - unpackCmd = '' - tar --one-top-level -xf $curSrc - ''; - makeFlags = "all"; - patches = [ ./davical_19eb79ebf9250e5f339675319902458c40ed1755.patch ]; - installPhase = '' - mkdir -p $out - cp -ra config dba docs htdocs inc locale po scripts testing zonedb $out - ln -s /var/secrets/webapps/dav-davical $out/config/config.php - ''; - buildInputs = [ gettext ]; - }; - webRoot = "${webapp}/htdocs"; - apache = rec { - user = "wwwrun"; - group = "wwwrun"; - modules = [ "proxy_fcgi" ]; - webappName = "tools_davical"; - root = "/run/current-system/webapps/${webappName}"; - vhostConf = '' - Alias /davical "${root}" - Alias /caldav.php "${root}/caldav.php" - - DirectoryIndex index.php index.html - AcceptPathInfo On - AllowOverride None - Require all granted + $c->do_not_sync_from_ldap = array('admin' => true); + include('drivers_ldap.php'); + ''; + }]; + webapp = davical.override { config = "/var/secrets/webapps/dav-davical"; }; + webRoot = "${webapp}/htdocs"; + apache = rec { + user = "wwwrun"; + group = "wwwrun"; + modules = [ "proxy_fcgi" ]; + webappName = "tools_davical"; + root = "/run/current-system/webapps/${webappName}"; + vhostConf = '' + Alias /davical "${root}" + Alias /caldav.php "${root}/caldav.php" + + DirectoryIndex index.php index.html + AcceptPathInfo On + AllowOverride None + Require all granted - - CGIPassAuth on - SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" - + + CGIPassAuth on + SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" + - RewriteEngine On - - Header unset Access-Control-Allow-Origin - Header unset Access-Control-Allow-Methods - Header unset Access-Control-Allow-Headers - Header unset Access-Control-Allow-Credentials - Header unset Access-Control-Expose-Headers + RewriteEngine On + + Header unset Access-Control-Allow-Origin + Header unset Access-Control-Allow-Methods + Header unset Access-Control-Allow-Headers + Header unset Access-Control-Allow-Credentials + Header unset Access-Control-Expose-Headers - Header always set Access-Control-Allow-Origin "*" - Header always set Access-Control-Allow-Methods "GET,POST,OPTIONS,PROPFIND,PROPPATCH,REPORT,PUT,MOVE,DELETE,LOCK,UNLOCK" - Header always set Access-Control-Allow-Headers "User-Agent,Authorization,Content-type,Depth,If-match,If-None-Match,Lock-Token,Timeout,Destination,Overwrite,Prefer,X-client,X-Requested-With" - Header always set Access-Control-Allow-Credentials false - Header always set Access-Control-Expose-Headers "Etag,Preference-Applied" + Header always set Access-Control-Allow-Origin "*" + Header always set Access-Control-Allow-Methods "GET,POST,OPTIONS,PROPFIND,PROPPATCH,REPORT,PUT,MOVE,DELETE,LOCK,UNLOCK" + Header always set Access-Control-Allow-Headers "User-Agent,Authorization,Content-type,Depth,If-match,If-None-Match,Lock-Token,Timeout,Destination,Overwrite,Prefer,X-client,X-Requested-With" + Header always set Access-Control-Allow-Credentials false + Header always set Access-Control-Expose-Headers "Etag,Preference-Applied" - RewriteCond %{HTTP:Access-Control-Request-Method} !^$ - RewriteCond %{REQUEST_METHOD} OPTIONS - RewriteRule ^(.*)$ $1 [R=200,L] - - - ''; - }; - phpFpm = rec { - serviceDeps = [ "postgresql.service" "openldap.service" ]; - basedir = builtins.concatStringsSep ":" [ webapp "/var/secrets/webapps/dav-davical" awl ]; - socket = "/var/run/phpfpm/davical.sock"; - pool = '' - listen = ${socket} - user = ${apache.user} - group = ${apache.group} - listen.owner = ${apache.user} - listen.group = ${apache.group} - pm = dynamic - pm.max_children = 60 - pm.start_servers = 2 - pm.min_spare_servers = 1 - pm.max_spare_servers = 10 + RewriteCond %{HTTP:Access-Control-Request-Method} !^$ + RewriteCond %{REQUEST_METHOD} OPTIONS + RewriteRule ^(.*)$ $1 [R=200,L] + + + ''; + }; + phpFpm = rec { + serviceDeps = [ "postgresql.service" "openldap.service" ]; + basedir = builtins.concatStringsSep ":" [ webapp "/var/secrets/webapps/dav-davical" awl ]; + socket = "/var/run/phpfpm/davical.sock"; + pool = '' + listen = ${socket} + user = ${apache.user} + group = ${apache.group} + listen.owner = ${apache.user} + listen.group = ${apache.group} + pm = dynamic + pm.max_children = 60 + pm.start_servers = 2 + pm.min_spare_servers = 1 + pm.max_spare_servers = 10 - ; Needed to avoid clashes in browser cookies (same domain) - php_value[session.name] = DavicalPHPSESSID - php_admin_value[open_basedir] = "${basedir}:/tmp:/var/lib/php/sessions/davical" - php_admin_value[include_path] = "${awl}/inc:${webapp}/inc" - php_admin_value[session.save_path] = "/var/lib/php/sessions/davical" - php_flag[magic_quotes_gpc] = Off - php_flag[register_globals] = Off - php_admin_value[error_reporting] = "E_ALL & ~E_NOTICE" - php_admin_value[default_charset] = "utf-8" - php_flag[magic_quotes_runtime] = Off - ''; - }; + ; Needed to avoid clashes in browser cookies (same domain) + php_value[session.name] = DavicalPHPSESSID + php_admin_value[open_basedir] = "${basedir}:/tmp:/var/lib/php/sessions/davical" + php_admin_value[include_path] = "${awl}/inc:${webapp}/inc" + php_admin_value[session.save_path] = "/var/lib/php/sessions/davical" + php_flag[magic_quotes_gpc] = Off + php_flag[register_globals] = Off + php_admin_value[error_reporting] = "E_ALL & ~E_NOTICE" + php_admin_value[default_charset] = "utf-8" + php_flag[magic_quotes_runtime] = Off + ''; }; -in - davical +} diff --git a/nixops/modules/websites/tools/dav/default.nix b/nixops/modules/websites/tools/dav/default.nix index 2a82a1d..c24f8db 100644 --- a/nixops/modules/websites/tools/dav/default.nix +++ b/nixops/modules/websites/tools/dav/default.nix @@ -1,8 +1,23 @@ { lib, pkgs, config, myconfig, mylibs, ... }: let - infcloud = pkgs.callPackage ./infcloud.nix {}; + infcloud = rec { + webappName = "tools_infcloud"; + root = "/run/current-system/webapps/${webappName}"; + vhostConf = '' + Alias /carddavmate ${root} + Alias /caldavzap ${root} + Alias /infcloud ${root} + + AllowOverride All + Options FollowSymlinks + Require all granted + DirectoryIndex index.html + + ''; + }; davical = pkgs.callPackage ./davical.nix { env = myconfig.env.tools.davical; + inherit (pkgs.webapps) davical awl; }; cfg = config.services.myWebsites.tools.dav; @@ -22,7 +37,7 @@ in { hosts = ["dav.immae.eu" ]; root = null; extraConfig = [ - infcloud.apache.vhostConf + infcloud.vhostConf davical.apache.vhostConf ]; }; @@ -34,7 +49,7 @@ in { system.extraSystemBuilderCmds = '' mkdir -p $out/webapps ln -s ${davical.webRoot} $out/webapps/${davical.apache.webappName} - ln -s ${infcloud.webRoot} $out/webapps/${infcloud.apache.webappName} + ln -s ${pkgs.webapps.infcloud} $out/webapps/${infcloud.webappName} ''; }; } diff --git a/nixops/modules/websites/tools/dav/infcloud.nix b/nixops/modules/websites/tools/dav/infcloud.nix deleted file mode 100644 index f1204ab..0000000 --- a/nixops/modules/websites/tools/dav/infcloud.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ stdenv, fetchzip, ed }: -let - infcloud = rec { - webRoot = stdenv.mkDerivation rec { - version = "0.13.1"; - name = "InfCloud-${version}"; - src = fetchzip { - url = "https://www.inf-it.com/InfCloud_${version}.zip"; - sha256 = "1fjhs0cj0b9fhf5ysfz281mknmmg1z551bas143sxfcqlpa5aiiq"; - }; - buildPhase = '' - ./cache_update.sh - rm config.js - ''; - installPhase = '' - cp -a . $out - ln -s ${./infcloud_config.js} $out/config.js - ''; - buildInputs = [ ed ]; - }; - apache = rec { - user = "wwwrun"; - group = "wwwrun"; - webappName = "tools_infcloud"; - root = "/run/current-system/webapps/${webappName}"; - vhostConf = '' - Alias /carddavmate ${root} - Alias /caldavzap ${root} - Alias /infcloud ${root} - - AllowOverride All - Options FollowSymlinks - Require all granted - DirectoryIndex index.html - - ''; - }; - }; -in - infcloud diff --git a/pkgs/default.nix b/pkgs/default.nix index d1d8fa4..0833cc2 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -34,7 +34,5 @@ in mpd = (callPackage ../pkgs/mpd_0_21 {}).mpd; mpd-small = (callPackage ../pkgs/mpd_0_21 {}).mpd-small; - webapps = { - mastodon = (callPackage ./webapps/mastodon { inherit mylibs; }); - }; + webapps = callPackage ./webapps { inherit mylibs; }; } diff --git a/pkgs/webapps/awl/default.nix b/pkgs/webapps/awl/default.nix new file mode 100644 index 0000000..8564fc3 --- /dev/null +++ b/pkgs/webapps/awl/default.nix @@ -0,0 +1,16 @@ +{ stdenv, fetchurl }: +stdenv.mkDerivation rec { + version = "0.59"; + name = "awl-${version}"; + src = fetchurl { + url = "https://www.davical.org/downloads/awl_${version}.orig.tar.xz"; + sha256 = "01b7km7ga3ggbpp8axkc55nizgk5c35fl2z93iydb3hwbxmsvnjp"; + }; + unpackCmd = '' + tar --one-top-level -xf $curSrc + ''; + installPhase = '' + mkdir -p $out + cp -ra dba docs inc scripts tests $out + ''; +} diff --git a/nixops/modules/websites/tools/dav/davical_19eb79ebf9250e5f339675319902458c40ed1755.patch b/pkgs/webapps/davical/davical_19eb79ebf9250e5f339675319902458c40ed1755.patch similarity index 100% rename from nixops/modules/websites/tools/dav/davical_19eb79ebf9250e5f339675319902458c40ed1755.patch rename to pkgs/webapps/davical/davical_19eb79ebf9250e5f339675319902458c40ed1755.patch diff --git a/pkgs/webapps/davical/default.nix b/pkgs/webapps/davical/default.nix new file mode 100644 index 0000000..fefc00f --- /dev/null +++ b/pkgs/webapps/davical/default.nix @@ -0,0 +1,20 @@ +{ config ? "/etc/davical/config.php", stdenv, fetchurl, gettext }: +stdenv.mkDerivation rec { + version = "1.1.7"; + name = "davical-${version}"; + src = fetchurl { + url = "https://www.davical.org/downloads/davical_${version}.orig.tar.xz"; + sha256 = "1ar5m2dxr92b204wkdi8z33ir9vz2jbh5k1p74icpv9ywifvjjp9"; + }; + unpackCmd = '' + tar --one-top-level -xf $curSrc + ''; + makeFlags = "all"; + patches = [ ./davical_19eb79ebf9250e5f339675319902458c40ed1755.patch ]; + installPhase = '' + mkdir -p $out + cp -ra config dba docs htdocs inc locale po scripts testing zonedb $out + ln -s ${config} $out/config/config.php + ''; + buildInputs = [ gettext ]; +} diff --git a/pkgs/webapps/default.nix b/pkgs/webapps/default.nix new file mode 100644 index 0000000..94d2157 --- /dev/null +++ b/pkgs/webapps/default.nix @@ -0,0 +1,7 @@ +{ callPackage, mylibs }: +{ + mastodon = callPackage ./mastodon { inherit mylibs; }; + awl = callPackage ./awl {}; + davical = callPackage ./davical {}; + infcloud = callPackage ./infcloud {}; +} diff --git a/pkgs/webapps/infcloud/default.nix b/pkgs/webapps/infcloud/default.nix new file mode 100644 index 0000000..0d73f52 --- /dev/null +++ b/pkgs/webapps/infcloud/default.nix @@ -0,0 +1,18 @@ +{ infcloud_config ? ./infcloud_config.js, stdenv, fetchzip, ed }: +stdenv.mkDerivation rec { + version = "0.13.1"; + name = "InfCloud-${version}"; + src = fetchzip { + url = "https://www.inf-it.com/InfCloud_${version}.zip"; + sha256 = "1fjhs0cj0b9fhf5ysfz281mknmmg1z551bas143sxfcqlpa5aiiq"; + }; + buildPhase = '' + ./cache_update.sh + rm config.js + ''; + installPhase = '' + cp -a . $out + ln -s ${infcloud_config} $out/config.js + ''; + buildInputs = [ ed ]; +} diff --git a/nixops/modules/websites/tools/dav/infcloud_config.js b/pkgs/webapps/infcloud/infcloud_config.js similarity index 100% rename from nixops/modules/websites/tools/dav/infcloud_config.js rename to pkgs/webapps/infcloud/infcloud_config.js -- 2.41.0