From 57b38a417e347ebe697abb0219410906b7c96341 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 2 Aug 2023 11:32:54 +0000 Subject: [PATCH] switch nextcloud from sqlite to mysql --- docs/repair-nextcloud.md | 46 ++++++++++++++++++++++++++++ modules/nixos/services/nextcloud.nix | 29 +++--------------- 2 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 docs/repair-nextcloud.md diff --git a/docs/repair-nextcloud.md b/docs/repair-nextcloud.md new file mode 100644 index 0000000..b624e3b --- /dev/null +++ b/docs/repair-nextcloud.md @@ -0,0 +1,46 @@ +# Repairing Nextcloud + +You can run the maintenance commands like this: + +``` +sudo -u nextcloud nextcloud-occ maintenance:mode --on +sudo -u nextcloud nextcloud-occ maintenance:repair +sudo -u nextcloud nextcloud-occ maintenance:mode --off +``` + +Converting from SQLite to MySQL (mariadb) + +First: keep Nextcloud set to SQLite as its dbtype, and separately launch MySQL +as a service by copying the configuration found +[here](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/web-apps/nextcloud.nix). + +No password is necessary, since the user-based auth works with UNIX sockets. + +You can connect to the MySQL instance like this: + +``` +sudo -u nextcloud mysql -S /run/mysqld/mysqld.sock +``` + +Create a blank database for Nextcloud: + +```sql +create database nextcloud; +``` + +Now setup the [conversion](https://docs.nextcloud.com/server/17/admin_manual/configuration_database/db_conversion.html): + +``` +sudo -u nextcloud nextcloud-occ db:convert-type mysql nextcloud localhost nextcloud +``` + +Ignore the password prompt. Proceed with the conversion. + +Now `config.php` will be updated but the override config from NixOS will not +be. Now update your NixOS configuration: + +- Remove the `mysql` service you created. +- Set `dbtype` to `mysql`. +- Set `database.createLocally` to `true`. + +Rebuild your configuration. diff --git a/modules/nixos/services/nextcloud.nix b/modules/nixos/services/nextcloud.nix index 25675ad..4d5bbf6 100644 --- a/modules/nixos/services/nextcloud.nix +++ b/modules/nixos/services/nextcloud.nix @@ -4,15 +4,19 @@ services.nextcloud = { package = pkgs.nextcloud27; # Required to specify + configureRedis = true; datadir = "/data/nextcloud"; + database.createLocally = true; https = true; hostName = "localhost"; maxUploadSize = "50G"; config = { adminpassFile = config.secrets.nextcloud.dest; + dbtype = "mysql"; extraTrustedDomains = [ config.hostnames.content ]; trustedProxies = [ "127.0.0.1" ]; }; + extraOptions = { default_phone_region = "US"; }; }; # Don't let Nginx use main ports (using Caddy instead) @@ -147,35 +151,10 @@ # Grant user access to Nextcloud directories users.users.${config.user}.extraGroups = [ "nextcloud" ]; - ## Backup config - # Open to groups, allowing for backups systemd.services.phpfpm-nextcloud.serviceConfig.StateDirectoryMode = lib.mkForce "0770"; - # Allow litestream and nextcloud to share a sqlite database - users.users.litestream.extraGroups = [ "nextcloud" ]; - users.users.nextcloud.extraGroups = [ "litestream" ]; - - # Backup sqlite database with litestream - services.litestream = { - settings = { - dbs = [{ - path = "${config.services.nextcloud.datadir}/data/nextcloud.db"; - replicas = [{ - url = - "s3://${config.backup.s3.bucket}.${config.backup.s3.endpoint}/nextcloud"; - }]; - }]; - }; - }; - - # Don't start litestream unless nextcloud is up - systemd.services.litestream = { - after = [ "phpfpm-nextcloud.service" ]; - requires = [ "phpfpm-nextcloud.service" ]; - }; - # Log metrics to prometheus networking.hosts."127.0.0.1" = [ config.hostnames.content ]; services.prometheus.exporters.nextcloud = {