Building a package for Boomaga

Hi I’m trying to create a package for Boomaga (GitHub - Boomaga/boomaga: Boomaga provides a virtual printer for CUPS. This can be used for print preview or for print booklets.). The package compiles well and it install two things, a cups backend for it and a corresponding gui app. The GUI app works well, but the cups_backend does not work, because it needs to write to /var/cache/boomaga and it fails as permission denied. How can I make this work?

This what I could come up with:

{ lib
, stdenv
, fetchFromGitHub
, cmake
, cups
, qtbase
, qttools
, wrapQtAppsHook
, pkg-config
, poppler
}:

stdenv.mkDerivation rec {
  pname = "boomaga";
  version = "3.0.0"; # Update this to the correct version

  src = fetchFromGitHub {
    owner = "Boomaga";
    repo = "boomaga";
    rev = "v${version}";
    sha256 = "sha256-ThiyZ/fTwp+E639HavUv9WbRE+RxGbRwcPqXSuVWdaQ="; # Update with correct hash
  };

  nativeBuildInputs = [ 
    cmake
    wrapQtAppsHook
    pkg-config
  ];

  buildInputs = [
    cups.dev
    qtbase
    qttools
    poppler
  ];

  cmakeFlags = [
    "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
    "-DCUPS_PPD_DIR=${placeholder "out"}/share/cups/model/boomaga"
    "-DCUPS_BACKEND_DIR=${placeholder "out"}/lib/cups/backend" 
  ];

  # postPatch = ''
  #     substituteInPlace src/backend/cups_backend/main.cpp \
  #         --replace "/var/cache/boomaga" "/var/cache/cups/boomaga"
  # '';

  meta = with lib; {
    description = "Virtual printer for viewing and editing before printing";
    homepage = "https://www.boomaga.org/";
    license = licenses.gpl2Plus;
    maintainers = with maintainers; [ ]; # Add your name if you're maintaining this package
    platforms = platforms.linux;
  };
}

This is the virtual printer config I am using to create the virtual printer in my configuration:

{pkgs, ...}: let 
  boomaga = pkgs.libsForQt5.callPackage ./boomaga.nix {};
 in {
  services.avahi = {
    enable = true;
    nssmdns4 = true;
    openFirewall = true;
  };
  environment.systemPackages = with pkgs; [
    boomaga
  ];

  hardware.printers = {
    ensurePrinters = [
      {
        name = "Boomaga";
        deviceUri = "boomaga:/";
        model = "boomaga/boomaga.ppd"; 
        description = "Boomaga Virtual Printer";
        location = "Local Virtual Printer";
        ppdOptions = {
          # Add any specific PPD options here if needed
        };
      }
    ];
  };
  services.dbus.packages = [boomaga];
  services.printing.drivers = with pkgs; [hplipWithPlugin boomaga];
}

It feels like /var/cache/boomaga is a directory that needs to be created from your NixOS configuration, with the right ownership/permissions using systemd.tmpfiles.rules, for example:

    systemd.tmpfiles.rules = [
      "d /var/cache/boomaga 0700 user group - -"
    ];

^ Adjust user & group for your needs.

I did that, like this

  systemd.tmpfiles.rules = [
      "d /var/cache/boomaga 0775 cups lp - -"
    ];

But then boomaga also creates a user directory in the folder and changes the owner to the user, which is errors out

“[Boomaga backend] ERROR: Can’t change owner on directory /var/cache/boomaga/nithin: Operation not permitted”

Edit: I also added
tmp-files for the user folder too, then it tries to change owner of the job files, it fails too.

This is the source code.
https://github.com/Boomaga/boomaga/blob/7f7ad4754b20a1027c5095b660c5229353b64c8d/src/backend/cups_backend/main.cpp#L116

I’ve modified it to ignore this chown, then it errors while creating a job file, seen here
https://github.com/Boomaga/boomaga/blob/7f7ad4754b20a1027c5095b660c5229353b64c8d/src/backend/cups_backend/main.cpp#L153