Merge pull request #119638 from beardhatcode/feat/nextcloud-packages

nextcloud: add option to set datadir and extensions

authored by

Maximilian Bosch and committed by
GitHub
eb3a3725 be5d1c3c

+142 -8
+91 -8
nixos/modules/services/web-apps/nextcloud.nix
··· 6 6 cfg = config.services.nextcloud; 7 7 fpm = config.services.phpfpm.pools.nextcloud; 8 8 9 + inherit (cfg) datadir; 10 + 9 11 phpPackage = cfg.phpPackage.buildEnv { 10 12 extensions = { enabled, all }: 11 13 (with all; ··· 40 42 if [[ "$USER" != nextcloud ]]; then 41 43 sudo='exec /run/wrappers/bin/sudo -u nextcloud --preserve-env=NEXTCLOUD_CONFIG_DIR --preserve-env=OC_PASS' 42 44 fi 43 - export NEXTCLOUD_CONFIG_DIR="${cfg.home}/config" 45 + export NEXTCLOUD_CONFIG_DIR="${datadir}/config" 44 46 $sudo \ 45 47 ${phpPackage}/bin/php \ 46 48 occ "$@" ··· 84 86 type = types.str; 85 87 default = "/var/lib/nextcloud"; 86 88 description = "Storage path of nextcloud."; 89 + }; 90 + datadir = mkOption { 91 + type = types.str; 92 + defaultText = "config.services.nextcloud.home"; 93 + description = '' 94 + Data storage path of nextcloud. Will be <xref linkend="opt-services.nextcloud.home" /> by default. 95 + This folder will be populated with a config.php and data folder which contains the state of the instance (excl the database)."; 96 + ''; 97 + example = "/mnt/nextcloud-file"; 98 + }; 99 + extraApps = mkOption { 100 + type = types.attrsOf types.package; 101 + default = { }; 102 + description = '' 103 + Extra apps to install. Should be an attrSet of appid to packages generated by fetchNextcloudApp. 104 + The appid must be identical to the "id" value in the apps appinfo/info.xml. 105 + Using this will disable the appstore to prevent Nextcloud from updating these apps (see <xref linkend="opt-services.nextcloud.appstoreEnable" />). 106 + ''; 107 + example = literalExpression '' 108 + { 109 + maps = pkgs.fetchNextcloudApp { 110 + name = "maps"; 111 + sha256 = "007y80idqg6b6zk6kjxg4vgw0z8fsxs9lajnv49vv1zjy6jx2i1i"; 112 + url = "https://github.com/nextcloud/maps/releases/download/v0.1.9/maps-0.1.9.tar.gz"; 113 + version = "0.1.9"; 114 + }; 115 + phonetrack = pkgs.fetchNextcloudApp { 116 + name = "phonetrack"; 117 + sha256 = "0qf366vbahyl27p9mshfma1as4nvql6w75zy2zk5xwwbp343vsbc"; 118 + url = "https://gitlab.com/eneiluj/phonetrack-oc/-/wikis/uploads/931aaaf8dca24bf31a7e169a83c17235/phonetrack-0.6.9.tar.gz"; 119 + version = "0.6.9"; 120 + }; 121 + } 122 + ''; 123 + }; 124 + extraAppsEnable = mkOption { 125 + type = types.bool; 126 + default = true; 127 + description = '' 128 + Automatically enable the apps in <xref linkend="opt-services.nextcloud.extraApps" /> every time nextcloud starts. 129 + If set to false, apps need to be enabled in the Nextcloud user interface or with nextcloud-occ app:enable. 130 + ''; 131 + }; 132 + appstoreEnable = mkOption { 133 + type = types.nullOr types.bool; 134 + default = null; 135 + example = true; 136 + description = '' 137 + Allow the installation of apps and app updates from the store. 138 + Enabled by default unless there are packages in <xref linkend="opt-services.nextcloud.extraApps" />. 139 + Set to true to force enable the store even if <xref linkend="opt-services.nextcloud.extraApps" /> is used. 140 + Set to false to disable the installation of apps from the global appstore. App management is always enabled regardless of this setting. 141 + ''; 87 142 }; 88 143 logLevel = mkOption { 89 144 type = types.ints.between 0 4; ··· 524 579 else nextcloud22 525 580 ); 526 581 582 + services.nextcloud.datadir = mkOptionDefault config.services.nextcloud.home; 583 + 527 584 services.nextcloud.phpPackage = 528 585 if versionOlder cfg.package.version "21" then pkgs.php74 529 586 else pkgs.php80; ··· 563 620 ] 564 621 ''; 565 622 623 + showAppStoreSetting = cfg.appstoreEnable != null || cfg.extraApps != {}; 624 + renderedAppStoreSetting = 625 + let 626 + x = cfg.appstoreEnable; 627 + in 628 + if x == null then "false" 629 + else boolToString x; 630 + 566 631 overrideConfig = pkgs.writeText "nextcloud-config.php" '' 567 632 <?php 568 633 ${optionalString requiresReadSecretFunction '' ··· 581 646 ''} 582 647 $CONFIG = [ 583 648 'apps_paths' => [ 649 + ${optionalString (cfg.extraApps != { }) "[ 'path' => '${cfg.home}/nix-apps', 'url' => '/nix-apps', 'writable' => false ],"} 584 650 [ 'path' => '${cfg.home}/apps', 'url' => '/apps', 'writable' => false ], 585 651 [ 'path' => '${cfg.home}/store-apps', 'url' => '/store-apps', 'writable' => true ], 586 652 ], 587 - 'datadirectory' => '${cfg.home}/data', 653 + ${optionalString (showAppStoreSetting) "'appstoreenabled' => ${renderedAppStoreSetting},"} 654 + 'datadirectory' => '${datadir}/data', 588 655 'skeletondirectory' => '${cfg.skeletonDirectory}', 589 656 ${optionalString cfg.caching.apcu "'memcache.local' => '\\OC\\Memcache\\APCu',"} 590 657 'log_type' => 'syslog', ··· 628 695 "--database-pass" = "\$${dbpass.arg}"; 629 696 "--admin-user" = ''"${c.adminuser}"''; 630 697 "--admin-pass" = "\$${adminpass.arg}"; 631 - "--data-dir" = ''"${cfg.home}/data"''; 698 + "--data-dir" = ''"${datadir}/data"''; 632 699 }); 633 700 in '' 634 701 ${mkExport dbpass} ··· 670 737 671 738 ln -sf ${cfg.package}/apps ${cfg.home}/ 672 739 740 + # Install extra apps 741 + ln -sfT \ 742 + ${pkgs.linkFarm "nix-apps" 743 + (mapAttrsToList (name: path: { inherit name path; }) cfg.extraApps)} \ 744 + ${cfg.home}/nix-apps 745 + 673 746 # create nextcloud directories. 674 747 # if the directories exist already with wrong permissions, we fix that 675 - for dir in ${cfg.home}/config ${cfg.home}/data ${cfg.home}/store-apps; do 748 + for dir in ${datadir}/config ${datadir}/data ${cfg.home}/store-apps ${cfg.home}/nix-apps; do 676 749 if [ ! -e $dir ]; then 677 750 install -o nextcloud -g nextcloud -d $dir 678 751 elif [ $(stat -c "%G" $dir) != "nextcloud" ]; then ··· 680 753 fi 681 754 done 682 755 683 - ln -sf ${overrideConfig} ${cfg.home}/config/override.config.php 756 + ln -sf ${overrideConfig} ${datadir}/config/override.config.php 684 757 685 758 # Do not install if already installed 686 - if [[ ! -e ${cfg.home}/config/config.php ]]; then 759 + if [[ ! -e ${datadir}/config/config.php ]]; then 687 760 ${occInstallCmd} 688 761 fi 689 762 690 763 ${occ}/bin/nextcloud-occ upgrade 691 764 692 765 ${occ}/bin/nextcloud-occ config:system:delete trusted_domains 766 + 767 + ${optionalString (cfg.extraAppsEnable && cfg.extraApps != { }) '' 768 + # Try to enable apps (don't fail when one of them cannot be enabled , eg. due to incompatible version) 769 + ${occ}/bin/nextcloud-occ app:enable ${concatStringsSep " " (attrNames cfg.extraApps)} 770 + ''} 771 + 693 772 ${occSetTrustedDomainsCmd} 694 773 ''; 695 774 serviceConfig.Type = "oneshot"; 696 775 serviceConfig.User = "nextcloud"; 697 776 }; 698 777 nextcloud-cron = { 699 - environment.NEXTCLOUD_CONFIG_DIR = "${cfg.home}/config"; 778 + environment.NEXTCLOUD_CONFIG_DIR = "${datadir}/config"; 700 779 serviceConfig.Type = "oneshot"; 701 780 serviceConfig.User = "nextcloud"; 702 781 serviceConfig.ExecStart = "${phpPackage}/bin/php -f ${cfg.package}/cron.php"; ··· 715 794 group = "nextcloud"; 716 795 phpPackage = phpPackage; 717 796 phpEnv = { 718 - NEXTCLOUD_CONFIG_DIR = "${cfg.home}/config"; 797 + NEXTCLOUD_CONFIG_DIR = "${datadir}/config"; 719 798 PATH = "/run/wrappers/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/usr/bin:/bin"; 720 799 }; 721 800 settings = mapAttrs (name: mkDefault) { ··· 762 841 extraConfig = "rewrite ^ /index.php;"; 763 842 }; 764 843 "~ ^/store-apps" = { 844 + priority = 201; 845 + extraConfig = "root ${cfg.home};"; 846 + }; 847 + "~ ^/nix-apps" = { 765 848 priority = 201; 766 849 extraConfig = "root ${cfg.home};"; 767 850 };
+6
nixos/modules/services/web-apps/nextcloud.xml
··· 237 237 Some apps may require extra PHP extensions to be installed. 238 238 This can be configured with the <xref linkend="opt-services.nextcloud.phpExtraExtensions" /> setting. 239 239 </para> 240 + 241 + <para> 242 + Alternatively, extra apps can also be declared with the <xref linkend="opt-services.nextcloud.extraApps" /> setting. 243 + When using this setting, apps can no longer be managed statefully because this can lead to Nextcloud updating apps 244 + that are managed by Nix. If you want automatic updates it is recommended that you use web interface to install apps. 245 + </para> 240 246 </section> 241 247 242 248 <section xml:id="module-services-nextcloud-maintainer-info">
+6
nixos/tests/nextcloud/basic.nix
··· 33 33 in { 34 34 networking.firewall.allowedTCPPorts = [ 80 ]; 35 35 36 + systemd.tmpfiles.rules = [ 37 + "d /var/lib/nextcloud-data 0750 nextcloud nginx - -" 38 + ]; 39 + 36 40 services.nextcloud = { 37 41 enable = true; 42 + datadir = "/var/lib/nextcloud-data"; 38 43 hostName = "nextcloud"; 39 44 config = { 40 45 # Don't inherit adminuser since "root" is supposed to be the default ··· 98 103 "${withRcloneEnv} ${copySharedFile}" 99 104 ) 100 105 client.wait_for_unit("multi-user.target") 106 + nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file") 101 107 client.succeed( 102 108 "${withRcloneEnv} ${diffSharedFile}" 103 109 )
+37
pkgs/build-support/fetchnextcloudapp/default.nix
··· 1 + { stdenv, gnutar, findutils, fetchurl, ... }: 2 + { name 3 + , url 4 + , version 5 + , sha256 6 + , patches ? [ ] 7 + }: 8 + stdenv.mkDerivation { 9 + name = "nc-app-${name}"; 10 + inherit version patches; 11 + 12 + src = fetchurl { 13 + inherit url sha256; 14 + }; 15 + 16 + nativeBuildInputs = [ 17 + gnutar 18 + findutils 19 + ]; 20 + 21 + unpackPhase = '' 22 + tar -xzpf $src 23 + ''; 24 + 25 + installPhase = '' 26 + approot="$(dirname $(dirname $(find -path '*/appinfo/info.xml' | head -n 1)))" 27 + 28 + if [ -d "$approot" ]; 29 + then 30 + mv "$approot/" $out 31 + chmod -R a-w $out 32 + else 33 + echo "Could not find appinfo/info.xml" 34 + exit 1; 35 + fi 36 + ''; 37 + }
+2
pkgs/top-level/all-packages.nix
··· 520 520 tests = callPackages ../build-support/fetchfirefoxaddon/tests.nix { }; 521 521 }; 522 522 523 + fetchNextcloudApp = callPackage ../build-support/fetchnextcloudapp {}; 524 + 523 525 # `fetchurl' downloads a file from the network. 524 526 fetchurl = if stdenv.buildPlatform != stdenv.hostPlatform 525 527 then buildPackages.fetchurl # No need to do special overrides twice,