# ~/nixconfig/modules/nextcloud-setup.nix { config, pkgs, lib, ... }: let nextcloudExternalDomain = "cloud.death916.xyz"; # Domain used by NPM adminPassFilePath = "/etc/nixos/secrets/nextcloud_admin_password"; dbPassFilePath = "/etc/nixos/secrets/nextcloud_db_password"; nextcloudDataPath = "/storage/nextcloud-data"; nginxProxyManagerTailscaleIP = "100.117.212.36"; # IP of your NPM # Port Nextcloud's internal webserver listens on (default 80 for HTTP). # NPM forwards to : # Direct Tailscale clients will connect to : internalNextcloudHttpPort = 80; # --- For Direct Tailscale Access to homelab's Nextcloud --- homelabTailscaleIP = "100.65.36.116"; # REPLACE with homelab's actual Tailscale IP homelabMagicDNSName = "homelab"; # Or homelab.your-tailnet-name.ts.net if you use the full name in { # --- PostgreSQL & Redis setup ... (as before) --- services.postgresql = { enable = true; package = pkgs.postgresql_14; ensureDatabases = [ "nextcloud" ]; ensureUsers = [ { name = "nextcloud"; } ]; }; services.redis.servers.nextcloud = { enable = true; user = "nextcloud"; unixSocket = "/run/redis-nextcloud/redis.sock"; port = 0; }; systemd.tmpfiles.rules = [ "d /run/redis-nextcloud 0750 nextcloud nextcloud - -" ]; # --- Nextcloud Service Configuration --- services.nextcloud = { enable = true; package = pkgs.nextcloud31; # Verify this version hostName = nextcloudExternalDomain; https = false; datadir = nextcloudDataPath; maxUploadSize = "2G"; config = { dbtype = "pgsql"; dbuser = "nextcloud"; dbhost = "/run/postgresql"; dbname = "nextcloud"; dbpassFile = dbPassFilePath; adminuser = "death916"; adminpassFile = adminPassFilePath; }; settings = { trusted_domains = [ nextcloudExternalDomain homelabTailscaleIP homelabMagicDNSName ]; trusted_proxies = [ nginxProxyManagerTailscaleIP ]; overwriteprotocol = "https"; overwritehost = nextcloudExternalDomain; "overwrite.cli.url" = "https://${nextcloudExternalDomain}"; overwritecondaddr = "^${nginxProxyManagerTailscaleIP}$"; "memcache.local" = "\\OC\\Memcache\\APCu"; "memcache.distributed" = "\\OC\\Memcache\\Redis"; "memcache.locking" = "\\OC\\Memcache\\Redis"; filelocking.enabled = true; redis = { host = "/run/redis-nextcloud/redis.sock"; port = 0; }; }; caching.redis = true; phpOptions = lib.mkForce { "memory_limit" = "2G"; }; }; # --- MODIFICATION: Attempt to "disable" setup/update services from auto-starting --- # This removes their default "WantedBy" directives, which is how services are # typically enabled to start at boot or with general system targets. systemd.services."nextcloud-setup.service" = { # This service unit is generated by the services.nextcloud module. # We are overriding its 'wantedBy' to an empty list. # This should prevent it from being linked into targets like multi-user.target. wantedBy = lib.mkForce [ ]; # We are NOT changing what command it runs (ExecStart). }; systemd.services."nextcloud-update-db.service" = { # Similar to above, for the database update service. wantedBy = lib.mkForce [ ]; # We are NOT changing what command it runs (ExecStart). }; # --- END MODIFICATION --- users.users.nextcloud = { isSystemUser = true; group = "nextcloud"; }; users.groups.nextcloud = {}; networking.firewall.allowedTCPPorts = [ internalNextcloudHttpPort ]; }