How to Install Wiki.js on NixOS

In this tutorial, we will learn how to install Wiki.js on NixOS.

Step 1: Update the System

Firstly, you need to update your system to make sure that you have the latest version of the packages on your system.

sudo nix-channel --update
sudo nixos-rebuild switch

Step 2: Install the Required Dependencies

Before we install Wiki.js, we need to install some of its dependencies so that our application can run without any problem.

sudo nix-env -iA nixos.nodejs-lts-14_x
sudo nix-env -iA nixos.postgresql

Step 3: Download and Install Wiki.js

In this step, we will download and install Wiki.js on our NixOS machine.

sudo mkdir /var/wiki
sudo chown $USER /var/wiki
cd /var/wiki
sudo npm install wiki.js@latest

Step 4: Setup PostgreSQL

To use Wiki.js, we need to create a PostgreSQL database and user.

Create a new database:

sudo -i -u postgres
createdb wikijs

Create a new PostgreSQL user and set a password:

createuser wikijs
psql
ALTER USER wikijs PASSWORD 'wikijs_password';
GRANT ALL PRIVILEGES ON DATABASE wikijs TO wikijs;
\q

Step 5: Configure Wiki.js

Now that we have Wiki.js and PostgreSQL installed, we need to configure Wiki.js to use PostgreSQL.

Copy the sample configuration file:

cd /var/wiki
cp config.sample.yml config.yml

Edit the config file to include your PostgreSQL database details:

nano config.yml

Update the following fields:

# ...
db:
  client: pg
  connection:
    host: localhost
    port: 5432
    database: wikijs
    user: wikijs
    password: wikijs_password
# ...

Step 6: Start Wiki.js

Now that we have configured Wiki.js, we need to start the application.

cd /var/wiki
sudo npm start

You should see the following message indicating that the server has started:

Wiki.js v2.x.x
Environment  : production
Port         : 3000
Process ID   : XXX
Node Version : v14.x.x
Database     : PostgreSQL

Open your web browser and go to http://localhost:3000 to access your Wiki.js site.

Conclusion

In this tutorial, we learned how to install Wiki.js on NixOS. We also configured PostgreSQL and started Wiki.js successfully. Enjoy exploring Wiki.js!