···66 cfg = config.services.nextcloud;
77 fpm = config.services.phpfpm.pools.nextcloud;
8899+ inherit (cfg) datadir;
1010+911 phpPackage = cfg.phpPackage.buildEnv {
1012 extensions = { enabled, all }:
1113 (with all;
···4042 if [[ "$USER" != nextcloud ]]; then
4143 sudo='exec /run/wrappers/bin/sudo -u nextcloud --preserve-env=NEXTCLOUD_CONFIG_DIR --preserve-env=OC_PASS'
4244 fi
4343- export NEXTCLOUD_CONFIG_DIR="${cfg.home}/config"
4545+ export NEXTCLOUD_CONFIG_DIR="${datadir}/config"
4446 $sudo \
4547 ${phpPackage}/bin/php \
4648 occ "$@"
···8486 type = types.str;
8587 default = "/var/lib/nextcloud";
8688 description = "Storage path of nextcloud.";
8989+ };
9090+ datadir = mkOption {
9191+ type = types.str;
9292+ defaultText = "config.services.nextcloud.home";
9393+ description = ''
9494+ Data storage path of nextcloud. Will be <xref linkend="opt-services.nextcloud.home" /> by default.
9595+ This folder will be populated with a config.php and data folder which contains the state of the instance (excl the database).";
9696+ '';
9797+ example = "/mnt/nextcloud-file";
9898+ };
9999+ extraApps = mkOption {
100100+ type = types.attrsOf types.package;
101101+ default = { };
102102+ description = ''
103103+ Extra apps to install. Should be an attrSet of appid to packages generated by fetchNextcloudApp.
104104+ The appid must be identical to the "id" value in the apps appinfo/info.xml.
105105+ Using this will disable the appstore to prevent Nextcloud from updating these apps (see <xref linkend="opt-services.nextcloud.appstoreEnable" />).
106106+ '';
107107+ example = literalExpression ''
108108+ {
109109+ maps = pkgs.fetchNextcloudApp {
110110+ name = "maps";
111111+ sha256 = "007y80idqg6b6zk6kjxg4vgw0z8fsxs9lajnv49vv1zjy6jx2i1i";
112112+ url = "https://github.com/nextcloud/maps/releases/download/v0.1.9/maps-0.1.9.tar.gz";
113113+ version = "0.1.9";
114114+ };
115115+ phonetrack = pkgs.fetchNextcloudApp {
116116+ name = "phonetrack";
117117+ sha256 = "0qf366vbahyl27p9mshfma1as4nvql6w75zy2zk5xwwbp343vsbc";
118118+ url = "https://gitlab.com/eneiluj/phonetrack-oc/-/wikis/uploads/931aaaf8dca24bf31a7e169a83c17235/phonetrack-0.6.9.tar.gz";
119119+ version = "0.6.9";
120120+ };
121121+ }
122122+ '';
123123+ };
124124+ extraAppsEnable = mkOption {
125125+ type = types.bool;
126126+ default = true;
127127+ description = ''
128128+ Automatically enable the apps in <xref linkend="opt-services.nextcloud.extraApps" /> every time nextcloud starts.
129129+ If set to false, apps need to be enabled in the Nextcloud user interface or with nextcloud-occ app:enable.
130130+ '';
131131+ };
132132+ appstoreEnable = mkOption {
133133+ type = types.nullOr types.bool;
134134+ default = null;
135135+ example = true;
136136+ description = ''
137137+ Allow the installation of apps and app updates from the store.
138138+ Enabled by default unless there are packages in <xref linkend="opt-services.nextcloud.extraApps" />.
139139+ Set to true to force enable the store even if <xref linkend="opt-services.nextcloud.extraApps" /> is used.
140140+ Set to false to disable the installation of apps from the global appstore. App management is always enabled regardless of this setting.
141141+ '';
87142 };
88143 logLevel = mkOption {
89144 type = types.ints.between 0 4;
···524579 else nextcloud22
525580 );
526581582582+ services.nextcloud.datadir = mkOptionDefault config.services.nextcloud.home;
583583+527584 services.nextcloud.phpPackage =
528585 if versionOlder cfg.package.version "21" then pkgs.php74
529586 else pkgs.php80;
···563620 ]
564621 '';
565622623623+ showAppStoreSetting = cfg.appstoreEnable != null || cfg.extraApps != {};
624624+ renderedAppStoreSetting =
625625+ let
626626+ x = cfg.appstoreEnable;
627627+ in
628628+ if x == null then "false"
629629+ else boolToString x;
630630+566631 overrideConfig = pkgs.writeText "nextcloud-config.php" ''
567632 <?php
568633 ${optionalString requiresReadSecretFunction ''
···581646 ''}
582647 $CONFIG = [
583648 'apps_paths' => [
649649+ ${optionalString (cfg.extraApps != { }) "[ 'path' => '${cfg.home}/nix-apps', 'url' => '/nix-apps', 'writable' => false ],"}
584650 [ 'path' => '${cfg.home}/apps', 'url' => '/apps', 'writable' => false ],
585651 [ 'path' => '${cfg.home}/store-apps', 'url' => '/store-apps', 'writable' => true ],
586652 ],
587587- 'datadirectory' => '${cfg.home}/data',
653653+ ${optionalString (showAppStoreSetting) "'appstoreenabled' => ${renderedAppStoreSetting},"}
654654+ 'datadirectory' => '${datadir}/data',
588655 'skeletondirectory' => '${cfg.skeletonDirectory}',
589656 ${optionalString cfg.caching.apcu "'memcache.local' => '\\OC\\Memcache\\APCu',"}
590657 'log_type' => 'syslog',
···628695 "--database-pass" = "\$${dbpass.arg}";
629696 "--admin-user" = ''"${c.adminuser}"'';
630697 "--admin-pass" = "\$${adminpass.arg}";
631631- "--data-dir" = ''"${cfg.home}/data"'';
698698+ "--data-dir" = ''"${datadir}/data"'';
632699 });
633700 in ''
634701 ${mkExport dbpass}
···670737671738 ln -sf ${cfg.package}/apps ${cfg.home}/
672739740740+ # Install extra apps
741741+ ln -sfT \
742742+ ${pkgs.linkFarm "nix-apps"
743743+ (mapAttrsToList (name: path: { inherit name path; }) cfg.extraApps)} \
744744+ ${cfg.home}/nix-apps
745745+673746 # create nextcloud directories.
674747 # if the directories exist already with wrong permissions, we fix that
675675- for dir in ${cfg.home}/config ${cfg.home}/data ${cfg.home}/store-apps; do
748748+ for dir in ${datadir}/config ${datadir}/data ${cfg.home}/store-apps ${cfg.home}/nix-apps; do
676749 if [ ! -e $dir ]; then
677750 install -o nextcloud -g nextcloud -d $dir
678751 elif [ $(stat -c "%G" $dir) != "nextcloud" ]; then
···680753 fi
681754 done
682755683683- ln -sf ${overrideConfig} ${cfg.home}/config/override.config.php
756756+ ln -sf ${overrideConfig} ${datadir}/config/override.config.php
684757685758 # Do not install if already installed
686686- if [[ ! -e ${cfg.home}/config/config.php ]]; then
759759+ if [[ ! -e ${datadir}/config/config.php ]]; then
687760 ${occInstallCmd}
688761 fi
689762690763 ${occ}/bin/nextcloud-occ upgrade
691764692765 ${occ}/bin/nextcloud-occ config:system:delete trusted_domains
766766+767767+ ${optionalString (cfg.extraAppsEnable && cfg.extraApps != { }) ''
768768+ # Try to enable apps (don't fail when one of them cannot be enabled , eg. due to incompatible version)
769769+ ${occ}/bin/nextcloud-occ app:enable ${concatStringsSep " " (attrNames cfg.extraApps)}
770770+ ''}
771771+693772 ${occSetTrustedDomainsCmd}
694773 '';
695774 serviceConfig.Type = "oneshot";
696775 serviceConfig.User = "nextcloud";
697776 };
698777 nextcloud-cron = {
699699- environment.NEXTCLOUD_CONFIG_DIR = "${cfg.home}/config";
778778+ environment.NEXTCLOUD_CONFIG_DIR = "${datadir}/config";
700779 serviceConfig.Type = "oneshot";
701780 serviceConfig.User = "nextcloud";
702781 serviceConfig.ExecStart = "${phpPackage}/bin/php -f ${cfg.package}/cron.php";
···715794 group = "nextcloud";
716795 phpPackage = phpPackage;
717796 phpEnv = {
718718- NEXTCLOUD_CONFIG_DIR = "${cfg.home}/config";
797797+ NEXTCLOUD_CONFIG_DIR = "${datadir}/config";
719798 PATH = "/run/wrappers/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/usr/bin:/bin";
720799 };
721800 settings = mapAttrs (name: mkDefault) {
···762841 extraConfig = "rewrite ^ /index.php;";
763842 };
764843 "~ ^/store-apps" = {
844844+ priority = 201;
845845+ extraConfig = "root ${cfg.home};";
846846+ };
847847+ "~ ^/nix-apps" = {
765848 priority = 201;
766849 extraConfig = "root ${cfg.home};";
767850 };
+6
nixos/modules/services/web-apps/nextcloud.xml
···237237 Some apps may require extra PHP extensions to be installed.
238238 This can be configured with the <xref linkend="opt-services.nextcloud.phpExtraExtensions" /> setting.
239239 </para>
240240+241241+ <para>
242242+ Alternatively, extra apps can also be declared with the <xref linkend="opt-services.nextcloud.extraApps" /> setting.
243243+ When using this setting, apps can no longer be managed statefully because this can lead to Nextcloud updating apps
244244+ that are managed by Nix. If you want automatic updates it is recommended that you use web interface to install apps.
245245+ </para>
240246 </section>
241247242248 <section xml:id="module-services-nextcloud-maintainer-info">
···520520 tests = callPackages ../build-support/fetchfirefoxaddon/tests.nix { };
521521 };
522522523523+ fetchNextcloudApp = callPackage ../build-support/fetchnextcloudapp {};
524524+523525 # `fetchurl' downloads a file from the network.
524526 fetchurl = if stdenv.buildPlatform != stdenv.hostPlatform
525527 then buildPackages.fetchurl # No need to do special overrides twice,