How to Install Shlink on NixOS Latest

Shlink is a self-hosted URL shortening and link management platform that helps to track clicks and other link-related data. In this tutorial, you will learn how to install Shlink on NixOS Latest.

Step 1 - Update the System

Before starting with the installation of Shlink, it is recommended to update your NixOS system to ensure that all packages are up to date. Use the following command:

sudo nix-channel --update

Step 2 - Install Shlink

To install Shlink on NixOS, follow the steps below:

Enable PHP

If PHP is not enabled on your system, enable it by adding the following lines to your configuration.nix file:

services.php.enable = true;
services.php.version = "7.4";

Save the changes and run the following command to apply the changes:

sudo nixos-rebuild switch

Install Shlink

To install Shlink, add the following lines to your configuration.nix file:

services.shlink = {
  enable = true;
  user = "shlink";
  group = "shlink";
  dbDriver = "mysql";
  dbHost = "localhost";
  dbName = "shlink";
  dbUser = "shlink";
  dbPassword = "yourpassword";
  secretKey = "mysecretkey";
  cookieToken = "mycookietoken";
  urlShortenerDomain = "shlink.example.com";
};
  • enable - Enables Shlink.
  • user and group - Set the user and group for the Shlink process.
  • dbDriver, dbHost, dbName, dbUser, and dbPassword - Set the database details for the Shlink installation.
  • secretKey and cookieToken - Set the secret key and the cookie token for Shlink.
  • urlShortenerDomain - Set the domain name for the short URLs created by Shlink.

Save the changes and run the following command to apply the changes:

sudo nixos-rebuild switch

Initialize the Database

After installing Shlink, initialize the database by running the following command:

shlink db init

Start the Service

Start the Shlink service by running the following command:

sudo systemctl start shlink

Ensure that the service is running by checking its status:

sudo systemctl status shlink

Open the Firewall

Open the firewall by adding the following line to your configuration.nix file:

networking.firewall.allowedTCPPorts = [ 80 443 ];

Save the changes and run the following command to apply the changes:

sudo nixos-rebuild switch

Step 3 - Access Shlink

Access Shlink by navigating to http://yourdomain.com or https://yourdomain.com in your web browser.

You will be prompted to create an administrator account. Once done, you can start using Shlink.

Conclusion

You have learned how to install Shlink on NixOS Latest. Enjoy using it!