From 0ede7366409e14482017f70f1efc53426279b8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sun, 5 May 2019 19:06:39 +0200 Subject: Move nextcloud and apps to pkgs --- nixops/modules/websites/tools/cloud/default.nix | 151 ++++++++++-- nixops/modules/websites/tools/cloud/nextcloud.nix | 276 ---------------------- 2 files changed, 136 insertions(+), 291 deletions(-) delete mode 100644 nixops/modules/websites/tools/cloud/nextcloud.nix (limited to 'nixops/modules/websites/tools/cloud') diff --git a/nixops/modules/websites/tools/cloud/default.nix b/nixops/modules/websites/tools/cloud/default.nix index 5c3e9a8..f7d25cf 100644 --- a/nixops/modules/websites/tools/cloud/default.nix +++ b/nixops/modules/websites/tools/cloud/default.nix @@ -1,10 +1,48 @@ { lib, pkgs, config, myconfig, mylibs, ... }: let - nextcloud = pkgs.callPackage ./nextcloud.nix { - env = myconfig.env.tools.nextcloud; - }; + nextcloud = pkgs.webapps.nextcloud.withApps (builtins.attrValues pkgs.webapps.nextcloud-apps); + env = myconfig.env.tools.nextcloud; + varDir = "/var/lib/nextcloud"; + webappName = "tools_nextcloud"; + apacheRoot = "/run/current-system/webapps/${webappName}"; + cfg = config.services.myWebsites.tools.cloud; + phpFpm = rec { + basedir = builtins.concatStringsSep ":" ( + [ nextcloud varDir ] + ++ builtins.attrValues pkgs.webapps.nextcloud-apps); + socket = "/var/run/phpfpm/nextcloud.sock"; + phpConfig = '' + extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so + extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so + zend_extension=${pkgs.php}/lib/php/extensions/opcache.so + ''; + pool = '' + listen = ${socket} + user = wwwrun + group = wwwrun + listen.owner = wwwrun + listen.group = wwwrun + pm = ondemand + pm.max_children = 60 + pm.process_idle_timeout = 60 + + php_admin_value[output_buffering] = 0 + php_admin_value[max_execution_time] = 1800 + php_admin_value[zend_extension] = "opcache" + ;already enabled by default? + ;php_value[opcache.enable] = 1 + php_value[opcache.enable_cli] = 1 + php_value[opcache.interned_strings_buffer] = 8 + php_value[opcache.max_accelerated_files] = 10000 + php_value[opcache.memory_consumption] = 128 + php_value[opcache.save_comments] = 1 + php_value[opcache.revalidate_freq] = 1 + php_admin_value[memory_limit] = 512M - cfg = config.services.myWebsites.tools.cloud; + php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp" + php_admin_value[session.save_path] = "${varDir}/phpSessions" + ''; + }; in { options.services.myWebsites.tools.cloud = { enable = lib.mkEnableOption "enable cloud website"; @@ -13,23 +51,98 @@ in { config = lib.mkIf cfg.enable { security.acme.certs."eldiron".extraDomains."cloud.immae.eu" = null; - services.myWebsites.tools.modules = nextcloud.apache.modules; + services.myWebsites.tools.modules = [ "proxy_fcgi" ]; services.myWebsites.tools.vhostConfs.cloud = { certName = "eldiron"; hosts = ["cloud.immae.eu" ]; - root = nextcloud.apache.root; + root = apacheRoot; extraConfig = [ - nextcloud.apache.vhostConf + '' + SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 + + AcceptPathInfo On + DirectoryIndex index.php + Options FollowSymlinks + Require all granted + AllowOverride all + + + Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" + + + CGIPassAuth on + SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" + + + + '' ]; }; - mySecrets.keys = nextcloud.keys; + mySecrets.keys = [{ + dest = "webapps/tools-nextcloud"; + user = "wwwrun"; + group = "wwwrun"; + permissions = "0600"; + text = '' + '${env.instance_id}1', + 'datadirectory' => '/var/lib/nextcloud/', + 'passwordsalt' => '${env.password_salt}', + 'debug' => false, + 'dbtype' => 'pgsql', + 'version' => '15.0.4.0', + 'dbname' => '${env.postgresql.database}', + 'dbhost' => '${env.postgresql.socket}', + 'dbtableprefix' => 'oc_', + 'dbuser' => '${env.postgresql.user}', + 'dbpassword' => '${env.postgresql.password}', + 'installed' => true, + 'maxZipInputSize' => 0, + 'allowZipDownload' => true, + 'forcessl' => true, + 'theme' => ${"''"}, + 'maintenance' => false, + 'trusted_domains' => + array ( + 0 => 'cloud.immae.eu', + ), + 'secret' => '${env.secret}', + 'appstoreenabled' => false, + 'appstore.experimental.enabled' => true, + 'loglevel' => 2, + 'trashbin_retention_obligation' => 'auto', + 'htaccess.RewriteBase' => '/', + 'mail_smtpmode' => 'sendmail', + 'mail_smtphost' => '127.0.0.1', + 'mail_smtpname' => ''', + 'mail_smtppassword' => ''', + 'mail_from_address' => 'nextcloud', + 'mail_smtpauth' => false, + 'mail_domain' => 'tools.immae.eu', + 'memcache.local' => '\\OC\\Memcache\\APCu', + 'memcache.locking' => '\\OC\\Memcache\\Redis', + 'filelocking.enabled' => true, + 'redis' => + array ( + 'host' => '${env.redis.socket}', + 'port' => 0, + 'dbindex' => ${env.redis.db_index}, + ), + 'overwrite.cli.url' => 'https://cloud.immae.eu', + 'ldapIgnoreNamingRules' => false, + 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory', + ); + ''; + }]; users.users.root.packages = let occ = pkgs.writeScriptBin "nextcloud-occ" '' #! ${pkgs.stdenv.shell} - cd ${nextcloud.webRoot} - NEXTCLOUD_CONFIG_DIR="${nextcloud.webRoot}/config" \ + cd ${nextcloud} + NEXTCLOUD_CONFIG_DIR="${nextcloud}/config" \ exec \ sudo -u wwwrun ${pkgs.php}/bin/php \ -c ${pkgs.php}/etc/php.ini \ @@ -37,15 +150,23 @@ in { ''; in [ occ ]; - system.activationScripts.nextcloud = nextcloud.activationScript; + system.activationScripts.nextcloud = { + deps = [ ]; + text = '' + install -m 0755 -o wwwrun -g wwwrun -d ${varDir} + install -m 0750 -o wwwrun -g wwwrun -d ${varDir}/phpSessions + install -D -m 0644 -o wwwrun -g wwwrun ${./nextcloud-config}/* -t ${varDir}/config + install -D -m 0600 -o wwwrun -g wwwrun -T /var/secrets/webapps/tools-nextcloud ${varDir}/config/config.php + ''; + }; system.extraSystemBuilderCmds = '' mkdir -p $out/webapps - ln -s ${nextcloud.webRoot} $out/webapps/${nextcloud.apache.webappName} + ln -s ${nextcloud} $out/webapps/${webappName} ''; services.myPhpfpm = { - poolPhpConfigs.nextcloud = nextcloud.phpFpm.phpConfig; - poolConfigs.nextcloud = nextcloud.phpFpm.pool; + poolPhpConfigs.nextcloud = phpFpm.phpConfig; + poolConfigs.nextcloud = phpFpm.pool; }; services.cron = { @@ -53,7 +174,7 @@ in { systemCronJobs = [ '' LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive - */15 * * * * wwwrun ${pkgs.php}/bin/php -f ${nextcloud.webRoot}/cron.php + */15 * * * * wwwrun ${pkgs.php}/bin/php -f ${nextcloud}/cron.php '' ]; }; diff --git a/nixops/modules/websites/tools/cloud/nextcloud.nix b/nixops/modules/websites/tools/cloud/nextcloud.nix deleted file mode 100644 index b62606f..0000000 --- a/nixops/modules/websites/tools/cloud/nextcloud.nix +++ /dev/null @@ -1,276 +0,0 @@ -{ stdenv, fetchurl, env, writeText, lib, phpPackages, php }: -let - nextcloud = let - buildApp = { appName, version, url, sha256, installPhase ? "mkdir -p $out && cp -R . $out/" }: - stdenv.mkDerivation rec { - name = "nextcloud-app-${appName}-${version}"; - inherit version; - phases = "unpackPhase installPhase"; - inherit installPhase; - src = fetchurl { inherit url sha256; }; - }; - apps = { - audioplayer = buildApp rec { - appName = "audioplayer"; - version = "2.6.0"; - url = "https://github.com/Rello/${appName}/releases/download/${version}/${appName}-${version}.tar.gz"; - sha256 = "08apm7dhnljagcvq8b1dsqcck4nqwmz60bf3mx44xvbhiaq6nim4"; - }; - bookmarks = buildApp rec { - appName = "bookmarks"; - version = "0.16.2"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}-${version}.tar.gz"; - sha256 = "0ghk71iyk5xlqsfahg0d0lpp9lparpdnv2qx11a7j64pc9gzcfl4"; - }; - calendar = buildApp rec { - appName = "calendar"; - version = "1.6.4"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "00dijvcvy7snsjslfbyzvpp9anhms22zp1f0zkj89ln33jmana63"; - }; - contacts = buildApp rec { - appName = "contacts"; - version = "3.0.3"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "026hfigfzqb1cvq6a7mg9656nkm21c19a6ipqzgv00ycf38qyk95"; - }; - deck = buildApp rec { - appName = "deck"; - version = "0.5.2"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "1kygzixxdkp3dbma009p3pw0fj8wgcqcv39n7pay78lh6zi3nic7"; - }; - files_markdown = buildApp rec { - appName = "files_markdown"; - version = "2.0.5"; - url = "https://github.com/icewind1991/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "1dzvy4c6vff2qmkwqw13dx92xdkafaxgnipswjw44mh0ncc2n9ym"; - }; - gpxedit = buildApp rec { - appName = "gpxedit"; - version = "0.0.10"; - url = "https://gitlab.com/eneiluj/gpxedit-oc/wikis/uploads/33d187268c5f6f6a55350d656305701c/${appName}-${version}.tar.gz"; - sha256 = "0ynpaxm0xhvcj8xax6rm1w0p6j57wbqidhi7bhn268n483gwl2sw"; - }; - gpxpod = buildApp rec { - appName = "gpxpod"; - version = "3.0.1"; - url = "https://gitlab.com/eneiluj/gpxpod-oc/wikis/uploads/3f5fbc895de15f11f90582c4872839dc/${appName}-${version}.tar.gz"; - sha256 = "1g3602phrdpybamr4bnk5niv1znmwp19lqyw6d8yxmc84lg99dny"; - }; - keeweb = buildApp rec { - appName = "keeweb"; - version = "0.4.0"; - url = "https://github.com/jhass/nextcloud-keeweb/releases/download/v${version}/${appName}-${version}.tar.gz"; - sha256 = "0453kkb0a8vfivmibpwpx4bvhyn64jhns6cdfjacmnvbm6d75nj1"; - installPhase = '' - mkdir -p $out - cp -R . $out/ - sed -i -e 's/max-version="12"/max-version="16"/' $out/appinfo/info.xml - ''; - }; - music = buildApp rec { - appName = "music"; - version = "0.9.3"; - url = "https://github.com/owncloud/${appName}/archive/v${version}.tar.gz"; - sha256 = "1x4c2v8hnm9yi3fzjglfwd2brzn99v8zavgfczc5jfj30v3n555z"; - }; - notes = buildApp rec { - appName = "notes"; - version = "2.5.1"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "1albzqqsdirzyw8vhvs7r0qm2wqp8vm9vmxm4crhncd85bk01hmh"; - }; - ocsms = buildApp rec { - appName = "ocsms"; - version = "2.1.1"; - url = "https://github.com/nextcloud/${appName}/releases/download/${version}/${appName}-${version}.tar.gz"; - sha256 = "0sgfbmy1c8rgzjvf9snc7rzgp8aqsc65zfwgi6qcsf2g6gam5n7a"; - installPhase = '' - sed -i -e "/addScript.*devel/d" -e "s@//\(.*addScript.*app.min\)@\1@" templates/main.php - mkdir -p $out - cp -R . $out/ - ''; - }; - passman = buildApp rec { - appName = "passman"; - version = "2.2.1"; - url = "https://releases.passman.cc/${appName}_${version}.tar.gz"; - sha256 = "064pq9d0pl3y1vcywpi19fg47zy7j4h0jaxy6jklwzwcrmzagbka"; - }; - spreed = buildApp rec { - appName = "spreed"; - version = "5.0.2"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}-${version}.tar.gz"; - sha256 = "0z9zhpkq485lhwirc2f04427rd47hzv0r8frz72dkrszb037qjvv"; - }; - tasks = buildApp rec { - appName = "tasks"; - version = "0.9.8"; - url = "https://github.com/nextcloud/${appName}/releases/download/v${version}/${appName}.tar.gz"; - sha256 = "089m124lfsfk09fqj50x9n7zndq97jp5afgb8s001rpmzym4g6ny"; - }; - }; - in rec { - varDir = "/var/lib/nextcloud"; - keys = [{ - dest = "webapps/tools-nextcloud"; - user = apache.user; - group = apache.group; - permissions = "0600"; - text = '' - '${env.instance_id}1', - 'datadirectory' => '/var/lib/nextcloud/', - 'passwordsalt' => '${env.password_salt}', - 'debug' => false, - 'dbtype' => 'pgsql', - 'version' => '15.0.4.0', - 'dbname' => '${env.postgresql.database}', - 'dbhost' => '${env.postgresql.socket}', - 'dbtableprefix' => 'oc_', - 'dbuser' => '${env.postgresql.user}', - 'dbpassword' => '${env.postgresql.password}', - 'installed' => true, - 'maxZipInputSize' => 0, - 'allowZipDownload' => true, - 'forcessl' => true, - 'theme' => ${"''"}, - 'maintenance' => false, - 'trusted_domains' => - array ( - 0 => 'cloud.immae.eu', - ), - 'secret' => '${env.secret}', - 'appstoreenabled' => false, - 'appstore.experimental.enabled' => true, - 'loglevel' => 2, - 'trashbin_retention_obligation' => 'auto', - 'htaccess.RewriteBase' => '/', - 'mail_smtpmode' => 'sendmail', - 'mail_smtphost' => '127.0.0.1', - 'mail_smtpname' => ''', - 'mail_smtppassword' => ''', - 'mail_from_address' => 'nextcloud', - 'mail_smtpauth' => false, - 'mail_domain' => 'tools.immae.eu', - 'memcache.local' => '\\OC\\Memcache\\APCu', - 'memcache.locking' => '\\OC\\Memcache\\Redis', - 'filelocking.enabled' => true, - 'redis' => - array ( - 'host' => '${env.redis.socket}', - 'port' => 0, - 'dbindex' => ${env.redis.db_index}, - ), - 'overwrite.cli.url' => 'https://cloud.immae.eu', - 'ldapIgnoreNamingRules' => false, - 'ldapProviderFactory' => '\\OCA\\User_LDAP\\LDAPProviderFactory', - ); - ''; - }]; - webRoot = stdenv.mkDerivation rec { - name = "nextcloud-${version}"; - version = "15.0.4"; - - src = fetchurl { - url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2"; - sha256 = "0xwg7p31y1pkjk1pzygh9shpqxnfkafrab52j7in7xblq53v0zgq"; - }; - - installPhase = '' - mkdir -p $out/ - cp -R . $out/ - rm -r $out/config - ln -sf ${varDir}/config $out/config - ${builtins.concatStringsSep "\n" ( - lib.attrsets.mapAttrsToList (name: value: "ln -sf ${value} $out/apps/${name}") apps - )} - ''; - - meta = { - description = "Sharing solution for files, calendars, contacts and more"; - homepage = https://nextcloud.com; - maintainers = with lib.maintainers; [ schneefux bachp globin fpletz ]; - license = lib.licenses.agpl3Plus; - platforms = with lib.platforms; unix; - }; - }; - activationScript = { - deps = [ ]; - text = '' - install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} - install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions - install -D -m 0644 -o ${apache.user} -g ${apache.group} ${./nextcloud-config}/* -t ${varDir}/config - install -D -m 0600 -o ${apache.user} -g ${apache.group} -T /var/secrets/webapps/tools-nextcloud ${varDir}/config/config.php - ''; - }; - apache = rec { - user = "wwwrun"; - group = "wwwrun"; - modules = [ "proxy_fcgi" ]; - webappName = "tools_nextcloud"; - root = "/run/current-system/webapps/${webappName}"; - vhostConf = '' - SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 - - AcceptPathInfo On - DirectoryIndex index.php - Options FollowSymlinks - Require all granted - AllowOverride all - - - Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" - - - CGIPassAuth on - SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" - - - - - ''; - }; - phpFpm = rec { - basedir = builtins.concatStringsSep ":" ( - [ webRoot varDir ] - ++ lib.attrsets.mapAttrsToList (name: value: value) apps); - socket = "/var/run/phpfpm/nextcloud.sock"; - phpConfig = '' - extension=${phpPackages.redis}/lib/php/extensions/redis.so - extension=${phpPackages.apcu}/lib/php/extensions/apcu.so - zend_extension=${php}/lib/php/extensions/opcache.so - ''; - 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 - - php_admin_value[output_buffering] = 0 - php_admin_value[max_execution_time] = 1800 - php_admin_value[zend_extension] = "opcache" - ;already enabled by default? - ;php_value[opcache.enable] = 1 - php_value[opcache.enable_cli] = 1 - php_value[opcache.interned_strings_buffer] = 8 - php_value[opcache.max_accelerated_files] = 10000 - php_value[opcache.memory_consumption] = 128 - php_value[opcache.save_comments] = 1 - php_value[opcache.revalidate_freq] = 1 - php_admin_value[memory_limit] = 512M - - php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:${basedir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp" - php_admin_value[session.save_path] = "${varDir}/phpSessions" - ''; - }; - }; -in - nextcloud -- cgit v1.2.3