I have been playing around with Nextcloud on NixOS. So far everything is working well, however I am not having successes getting Nextcloud to uses Redis for distributed cache (memcache.distributed
) and file locking (memcache.locking
). Below is a link to the Nextcloud documentation on this topic, I have successfully followed this in the past to get it setup on a Debian install.
Memory caching — Nextcloud latest Administration Manual latest documentation
The following is my attempt at a Nix config to get this working. FYI, I know it is not best practices to put password in plan text in a Nix config. At his point, I am just testing and doing this more for ease.
# /etc/nixos/nextcloud.nix
{config, pkgs, ...}:
{
# Nextcloud Configuration
services.nextcloud = {
enable = true;
package = pkgs.nextcloud25;
hostName = "redacted";
https = true;
maxUploadSize = "10G";
caching.redis = true;
config = {
# Further forces Nextcloud to use HTTPS
overwriteProtocol = "https";
# ISO 3611-1 country codes for automatic phone-number detection
defaultPhoneRegion = "redacted";
# Nextcloud PostegreSQL Database Configuration
dbtype = "pgsql";
dbuser = "nextcloud";
dbhost = "/run/postgresql";
dbname = "nextcloud";
dbpassFile = "${pkgs.writeText "dbpass" "redacted"}";
# Setup Admin User
adminuser = "admin";
adminpassFile = "${pkgs.writeText "adminpass" "redacted"}";
};
extraOptions = {
# Setup Redis
memcache.distributed = "\OC\Memcache\Redis";
memcache.locking = "\OC\Memcache\Redis";
filelocking.enabled = true;
redis = {
host = "/run/redis-nextcloud/redis.sock";
port = 0;
};
# Setup Mail
#redacted
};
};
# Setup Nextcloud virtual host to listen on ports
services.nginx.virtualHosts.${config.services.nextcloud.hostName} = {
forceSSL = true;
enableACME = true;
};
# Enable PostgreSQL
services.postgresql = {
enable = true;
package = pkgs.postgresql_14;
# Ensure the database, user, and permissions always exist
ensureDatabases = [ "nextcloud" ];
ensureUsers = [
{ name = "nextcloud";
ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
}
];
# Enable Redis
services.redis.servers.nextcloud = {
enable = true;
user = "nextcloud";
unixSocket = "/run/redis-nextcloud/redis.sock";
port = 0;
};
}
I have tested this by running the following command:
sudo -u nextcloud redis-cli -s /run/redis-nextcloud/redis.sock monitor
When I do this, I get the “OK” indicating that Redis is up in running. However, when I open the Nextcloud web interface and poke around, I don’t see the terminal filling with text. The text filling up the terminal is what I would expect, as this is what I have seen on a Debian install I have. Also, I can stop the Redis Systemd unit and on the NixOS install Nextcloud work fine, whereas on the Debian install Nextcloud give an error. All this is leading me to believe that I don’t have NixOS/Nextcloud setup correctly to uses Redis.
Any suggestion on how to get Redis distributed cashing and file locking for Nextcloud working on NixOS? Is my config even on the right track?
Thank you