How to Install Homer on NixOS Latest

In this tutorial, we will guide you through the process of installing Homer, an open-source dashboard for monitoring and analyzing server activity, on the latest version of NixOS. Homer is available on GitHub and can be installed using Nix, the package manager for NixOS.

Prerequisites

Step 1 - Update the System

Before installing any software, it is recommended to update the system to ensure that the latest packages are installed. Open a terminal and run the following command:

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

Step 2 - Install Homer

To install Homer, we will first need to create a Nix package for it. Create a new file with the following contents:

{ stdenv, fetchFromGitHub, python3Packages }:

stdenv.mkDerivation rec {
  pname = "homer";
  version = "latest";
  src = fetchFromGitHub {
    owner = "bastienwirtz";
    repo = "homer";
    rev = "HEAD";
    sha256 = "17v14409sbxlrl8c9fgz1knflp1y3q4y4q0j78kcv4alw2ny82ij";
  };
  buildInputs = with python3Packages; [ pip virtualenv ]
                                               ++ withPackages (ps: [ps.gunicorn ps.flask]);
  pythonPath = python3Packages.python3;
  preBuild = ''
    virtualenv --python=$pythonPath $out
    source $out/bin/activate
    pip install --no-cache-dir -r requirements.txt
    export FLASK_APP=homer/server.py
    export FLASK_ENV=production
    export HOMER_CONFIG=$out/config.yml
  '';
  installPhase = ''
    mkdir -p $out/bin $out/www $out/data $out/logs
    cp $src/server.py $out/bin/
    cp -R $src/homer $out/www/
    cp -R $src/templates $out/www/
    cp $src/config.yml $out/
  '';
  meta = {
    description = "A simple yet powerful dashboard for displaying metrics and monitoring of Unix systems.";
    homepage = "https://github.com/bastienwirtz/homer/";
    license = stdenv.lib.licenses.mit;
  };
}

Save the file as homer.nix in your home directory. This file defines a Nix package for Homer and fetches the latest version of the source code from GitHub.

Next, install Homer using the following command:

sudo nix-env --install -E 'with import <nixpkgs> {}; callPackage /home/YOUR_USERNAME/homer.nix {}'

Replace YOUR_USERNAME with your actual user name.

Step 3 - Configure Homer

After installation, we need to configure Homer to suit our needs. Create a new file with the following contents:

HOMER_APP_SECRET_KEY=YOUR_SECRET_KEY
FLASK_SECRET_KEY=YOUR_FLASK_SECRET_KEY

Replace YOUR_SECRET_KEY and YOUR_FLASK_SECRET_KEY with your own secret keys.

Save the file as homer.env in your home directory.

Step 4 - Run Homer

To run Homer, open a terminal and execute the following command:

sudo -E homer

The -E option preserves environment variables, so that Homer can access the secret keys we defined in homer.env.

After starting up, Homer should be available at http://localhost:8000 in your web browser.

Conclusion

In this tutorial, we showed you how to install Homer on the latest version of NixOS. Homer is a versatile monitoring tool that can help you keep your server in good health. With its user-friendly interface and powerful metrics, Homer is a great addition to any server administrator's toolkit.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!