How to Install Grocy on NixOS Latest

Grocy is a self-hosted, web-based application that helps you keep track of your groceries, household supplies, and to-do list. In this tutorial, we will guide you through the process of installing Grocy on the latest version of NixOS.

Prerequisites

Before you proceed with the installation process, you need to meet the following prerequisites:

  • A server running NixOS Latest.
  • A non-root user with sudo privileges.

Step 1: Update NixOS

The first step is to ensure that your system is up to date by running the following command:

sudo nixos-rebuild switch

Step 2: Install PHP and MariaDB

Next, you need to install PHP and MariaDB by running the following command:

sudo nix-env -iA nixos.php nixos.mariadb

Step 3: Download Grocy

You can download the latest version of Grocy from the official website or GitHub repository. To download Grocy, use the following command:

wget -O grocy.zip https://github.com/grocy/grocy/releases/download/v3.0.2/grocy_3.0.2.zip

Step 4: Extract Grocy

The downloaded file is a compressed ZIP archive. You need to extract it to the appropriate directory. To extract Grocy, use the following command:

unzip grocy.zip -d /var/www/

Step 5: Configure MariaDB

You need to configure MariaDB by creating a new database and user for Grocy. To do this, use the following commands:

sudo mysql -u root -p
CREATE DATABASE grocy;
CREATE USER 'grocy_user'@'localhost' IDENTIFIED BY 'grocy_password';
GRANT ALL PRIVILEGES ON grocy.* TO 'grocy_user'@'localhost';
EXIT;

Step 6: Configure Grocy

Next, you need to configure Grocy by copying the configuration file and modifying it to include your database credentials. To do this, use the following commands:

cp /var/www/grocy/data/config-dist.php /var/www/grocy/data/config.php
nano /var/www/grocy/data/config.php

In the configuration file, update the following parameters with your database credentials:

$dbConnectionDetails = [
	'host' => 'localhost',
	'port' => 3306,
	'database' => 'grocy',
	'username' => 'grocy_user',
	'password' => 'grocy_password'
];

Step 7: Enable PHP-FPM

Now, you need to enable PHP-FPM by including it in the Nginx configuration file. To do this, use the following command to edit the Nginx configuration file:

sudo nano /etc/nixos/configuration.nix

In the configuration file, add the following lines:

services.nginx = {
  enable = true;
  recommendedTlsSettings = true;
  virtualHosts."grocy" = {
    serverName = "grocy.example.com";
    root = "/var/www/grocy";
    index = "index.php";
    errorLog = "/var/log/nginx/grocy.error.log";
    accessLog = "/var/log/nginx/grocy.access.log";

    location ~ \.php$ {
      include fastcgi.conf;
      fastcgi_pass unix:/run/php-fpm.sock;
    }
  };
};
services.phpfpm = {
  enable = true;
  socketGroup = "www-data";
};

Save the configuration file and then run the following command to rebuild the system:

sudo nixos-rebuild switch

Step 8: Access Grocy

Once the installation is complete, you can access Grocy by visiting the server's IP address or domain name in a web browser. For example, if your domain name is grocy.example.com, you can access Grocy by visiting https://grocy.example.com.

You will be prompted to create a new account and set up your household information. Once you have completed the setup process, you can start to use Grocy to keep track of your household supplies, groceries, and to-do list.

Conclusion

In this tutorial, we have shown you how to install Grocy on the latest version of NixOS. By following these steps, you can set up an effective and easy-to-use grocery and household supply management system.