NixOS, Gitea/Forgejo, and Catppuccin

I spent a couple hours today figuring out how to get the official Catppuccin theme for Gitea and Forgejo integrated into my NixOS environment. Originally, I had taken the user theme for Codeberg, tweaked and cleaned it up for my server, and then used that. But, I decided to go a little further and submitted a request to make it official. Someone then made an entirely new package and made it the official version. After a little pouting, I decided that I'd rather have someone else maintain it so I can focus on other things.

The first part was pulling it down. Originally, I thought I would grab it via the Nix flake, but that ended up being too difficult. After fumbling around, I came up with using fetchzip (which apparently does tarballs also) because the release files don't have a top-level directory (all the CSS are on the root).

inputs @ {
  config,
  pkgs,
  lib,
  ...
}: let
  theme = pkgs.fetchzip {
    url = "https://github.com/catppuccin/gitea/releases/download/v0.2.1/catppuccin-gitea.tar.gz";
    sha256 = "sha256-HqVLW58lKPn81p3gTSjzkACHSBbmqPqeobAlJMubb8Y=";
    stripRoot = false;
  };
in {}

From there, I needed to set it up. There aren't a lot of good ways (that I've found) with setting up data structures for services on NixOS, so I set everything up in the preStart of the service. The stanza below gets all the files into the right place.

systemd.services.gitea = {
  preStart = lib.mkAfter ''
    rm -rf ${config.services.gitea.stateDir}/custom/public
    mkdir -p ${config.services.gitea.stateDir}/custom/public
    ln -sf ${theme} ${config.services.gitea.stateDir}/custom/public/css
  '';
};

The last bit is to tell Gitea about the themes. I considered writing them all down, but there are quite a few of them (four basic types plus accents for each one), so I decided to dynamically build the list from the input.

services.gitea = {
  settings = {
    ui = {
      THEMES =
        builtins.concatStringsSep
        ","
        (["auto"]
          ++ (map (name: lib.removePrefix "theme-" (lib.removeSuffix ".css" name))
            (builtins.attrNames (builtins.readDir theme))));
      DEFAULT_THEME = "catppuccin-mocha-blue";
    };
  };
};

Thanks to ottidmes from the #nix:nixos.org matrix room for all the help.

In other news, I switched from Gitea to Forgejo on src.mfgames.com. There wasn't a compelling reason other than I feel that I fit the philosophy more. I also disabled registrations on that server for now. If you want to send me an update, just use my contact page and send directly.

Metadata

Categories:

Tags: