How to Deploy Nextcloud on Your NixOS Home Server: A Comprehensive Guide

If you’re utilizing NixOS as your home server’s operating system and are eager to set up Nextcloud, you’re in the right place. This detailed guide will walk you through the entire process, ensuring a smooth installation of Nextcloud on your NixOS environment.

Creating a Nextcloud Nix Module

To deploy Nextcloud effectively, tweaking your configuration.nix file is essential for incorporating Nextcloud settings. Instead of cluttering this file with extensive code, you can streamline the process by creating a dedicated nextcloud-server.nix module.

Step-by-Step Instructions

  1. Open a Terminal on Your NixOS Server: Access your server via SSH.
  2. Create the Nextcloud Module: Execute the following command:

    sudo touch /etc/nixos/nextcloud-server.nix
  3. Modify the Configuration File: Next, open your configuration.nix file for editing:

    sudo nano -w /etc/nixos/configuration.nix
  4. Add the Module to Imports: Integrate the newly created module into the “imports” section. It should resemble this template:

    { config, pkgs, ... }:
    
    {
     imports = 
       [ 
         ./hardware-configuration.nix
         ./nextcloud-server.nix
         # Other imports...
       ];
     # Other settings...
    }
  5. Save and Exit: Use Ctrl + O to save your changes and Ctrl + X to exit.

  6. Edit the Nextcloud Module: Now, open your nextcloud-server.nix file:

    sudo nano -w /etc/nixos/nextcloud-server.nix
  7. Insert the Configuration Code: Paste the following configuration into the file:

    { config, pkgs, ... }:
    
    {
     # Environment setup for Nextcloud admin and DB passwords
     environment.etc."nextcloud-admin-pass".text = "SECURE_PASSWORD_HERE";
     environment.etc."nextcloud-db-pass".text = "SECURE_PASSWORD_HERE";
    
     # PostgreSQL Configuration
     services.postgresql = {
       enable = true;
       package = pkgs.postgresql_14;
       initialScript = pkgs.writeText "nextcloud-db-init.sql" ''
         CREATE ROLE nextcloud WITH LOGIN PASSWORD 'SECURE_PASSWORD_HERE';
         CREATE DATABASE nextcloud WITH OWNER nextcloud;
       '';
     };
    
     # PHP-FPM Configuration
     services.phpfpm.pools.nextcloud = {
       user = "nextcloud";
       group = "nextcloud";
       phpOptions = ''
         upload_max_filesize = 1G
         post_max_size = 1G
         memory_limit = 512M
         max_execution_time = 300
         date.timezone = "America/Detroit"
       '';
     };
    
     # Nextcloud Settings
     services.nextcloud = {
       enable = true;
       package = pkgs.nextcloud28;
       hostName = "nixos-server";
       config = {
         dbtype = "pgsql";
         dbname = "nextcloud";
         dbuser = "nextcloud";
         dbpassFile = "/etc/nextcloud-db-pass";
         adminpassFile = "/etc/nextcloud-admin-pass";
       };
       maxUploadSize = "1G";
     };
    
     # Other configurations...
    }

This code configures a basic Nextcloud server that operates on PostgreSQL within the NixOS framework. It’s important to fine-tune PHP settings to control the server’s upload limits.

Personalizing Your Nextcloud Module

To ensure your installation matches your requirements, you’ll need to customize fields in the nextcloud-server.nix module:

  • Locate the password entries and replace SECURE_PASSWORD_HERE with your strong password in three different places.
  • If necessary, alter the timezone by updating date.timezone = "America/Detroit" to match your location.
  • Change the hostName = "nixos-server"; parameter to set your preferred hostname for accessing Nextcloud.

Saving Your Changes

After applying your modifications, save the changes using Ctrl + O and exit with Ctrl + X.

Deploying Nextcloud on Your NixOS Server

The crucial configurations are now complete. It’s time to integrate the Nextcloud setup into your NixOS server. Use the following command to rebuild your NixOS setup:

sudo nixos-rebuild boot

Running this command will compile Nextcloud into your configuration and set it as the default option. However, a reboot is necessary to activate the changes.

Reboot Your Server

Once the build process is finished, restart your NixOS server. Upon logging back in, Nextcloud will be ready for use.

Setting Up Nextcloud

After deployment, it’s time to configure your Nextcloud instance. Open a web browser on a device connected to the same network as your NixOS server to begin the user creation process.

Follow the prompts to set up your admin account, and you’ll be equipped to create additional users who can access your Nextcloud environment via the web interface.


By following these steps, you can successfully set up Nextcloud on your NixOS server, creating a powerful personal cloud solution for your data needs.

By Alex Reynolds

Tech journalist and digital trends analyst, Alex Reynolds has a passion for emerging technologies, AI, and cybersecurity. With years of experience in the industry, he delivers in-depth insights and engaging articles for tech enthusiasts and professionals alike.