nixos/nextcloud: fixup #119638

A few minor changes to get #119638 - nextcloud: add option to set
datadir and extensions - ready:

* `cfg.datadir` now gets `cfg.home` as default to make the type
non-nullable.
* Enhanced the `basic` test to check the behavior with a custom datadir
that's not `/var/lib/nextcloud`.
* Fix hashes for apps in option example.
* Simplify if/else for `appstoreenable` in override config.
* Simplify a few `mapAttrsToList`-expressions in
`nextcloud-setup.service`.

Changed files
+30 -16
nixos
modules
services
web-apps
tests
nextcloud
pkgs
build-support
fetchnextcloudapp
+23 -14
nixos/modules/services/web-apps/nextcloud.nix
···
let
cfg = config.services.nextcloud;
fpm = config.services.phpfpm.pools.nextcloud;
-
datadir = if cfg.datadir == null then "${cfg.home}" else "${cfg.datadir}";
+
+
inherit (cfg) datadir;
phpPackage = cfg.phpPackage.buildEnv {
extensions = { enabled, all }:
···
description = "Storage path of nextcloud.";
};
datadir = mkOption {
-
type = types.nullOr types.str;
-
default = null;
+
type = types.str;
+
defaultText = "config.services.nextcloud.home";
description = ''
Data storage path of nextcloud. Will be <xref linkend="opt-services.nextcloud.home" /> by default.
This folder will be populated with a config.php and data folder which contains the state of the instance (excl the database).";
···
{
maps = pkgs.fetchNextcloudApp {
name = "maps";
-
sha256 = "007y80idqg6b6zk6kjxg4vgw0z8fsxs9lajnv49vv1zjy6jx2i1i+useTheLatestVersion";
+
sha256 = "007y80idqg6b6zk6kjxg4vgw0z8fsxs9lajnv49vv1zjy6jx2i1i";
url = "https://github.com/nextcloud/maps/releases/download/v0.1.9/maps-0.1.9.tar.gz";
version = "0.1.9";
};
phonetrack = pkgs.fetchNextcloudApp {
name = "phonetrack";
-
sha256 = "0qf366vbahyl27p9mshfma1as4nvql6w75zy2zk5xwwbp343vsbc+breakSha";
+
sha256 = "0qf366vbahyl27p9mshfma1as4nvql6w75zy2zk5xwwbp343vsbc";
url = "https://gitlab.com/eneiluj/phonetrack-oc/-/wikis/uploads/931aaaf8dca24bf31a7e169a83c17235/phonetrack-0.6.9.tar.gz";
version = "0.6.9";
};
···
else nextcloud22
);
+
services.nextcloud.datadir = mkOptionDefault config.services.nextcloud.home;
+
services.nextcloud.phpPackage =
if versionOlder cfg.package.version "21" then pkgs.php74
else pkgs.php80;
···
]
'';
+
showAppStoreSetting = cfg.appstoreEnable != null || cfg.extraApps != {};
+
renderedAppStoreSetting =
+
let
+
x = cfg.appstoreEnable;
+
in
+
if x == null then "false"
+
else boolToString x;
+
overrideConfig = pkgs.writeText "nextcloud-config.php" ''
<?php
${optionalString requiresReadSecretFunction ''
···
[ 'path' => '${cfg.home}/apps', 'url' => '/apps', 'writable' => false ],
[ 'path' => '${cfg.home}/store-apps', 'url' => '/store-apps', 'writable' => true ],
],
-
${if (cfg.appstoreEnable != null)
-
then '''appstoreenabled' => ${lib.boolToString cfg.appstoreEnable},''
-
else (if (cfg.extraApps != { })
-
then '''appstoreenabled' => false,''
-
else "")}
+
${optionalString (showAppStoreSetting) "'appstoreenabled' => ${renderedAppStoreSetting},"}
'datadirectory' => '${datadir}/data',
'skeletondirectory' => '${cfg.skeletonDirectory}',
${optionalString cfg.caching.apcu "'memcache.local' => '\\OC\\Memcache\\APCu',"}
···
fi
ln -sf ${cfg.package}/apps ${cfg.home}/
-
rm -rf ${cfg.home}/nix-apps
-
#Install extra apps
-
ln -sfT ${pkgs.linkFarm "nix-apps" (lib.mapAttrsToList (name: target: {name=name; path=target;}) cfg.extraApps)} ${cfg.home}/nix-apps
+
# Install extra apps
+
ln -sfT \
+
${pkgs.linkFarm "nix-apps"
+
(mapAttrsToList (name: path: { inherit name path; }) cfg.extraApps)} \
+
${cfg.home}/nix-apps
# create nextcloud directories.
# if the directories exist already with wrong permissions, we fix that
···
${optionalString (cfg.extraAppsEnable && cfg.extraApps != { }) ''
# Try to enable apps (don't fail when one of them cannot be enabled , eg. due to incompatible version)
-
${occ}/bin/nextcloud-occ app:enable ${builtins.concatStringsSep " " ( lib.mapAttrsToList (name: target: "${name}") cfg.extraApps)}
+
${occ}/bin/nextcloud-occ app:enable ${concatStringsSep " " (attrNames cfg.extraApps)}
''}
${occSetTrustedDomainsCmd}
+6
nixos/tests/nextcloud/basic.nix
···
in {
networking.firewall.allowedTCPPorts = [ 80 ];
+
systemd.tmpfiles.rules = [
+
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
+
];
+
services.nextcloud = {
enable = true;
+
datadir = "/var/lib/nextcloud-data";
hostName = "nextcloud";
config = {
# Don't inherit adminuser since "root" is supposed to be the default
···
"${withRcloneEnv} ${copySharedFile}"
)
client.wait_for_unit("multi-user.target")
+
nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file")
client.succeed(
"${withRcloneEnv} ${diffSharedFile}"
)
+1 -2
pkgs/build-support/fetchnextcloudapp/default.nix
···
inherit version patches;
src = fetchurl {
-
url = url;
-
sha256 = sha256;
+
inherit url sha256;
};
nativeBuildInputs = [