{
  name = "Sonarr";
  description = ''
    Sonarr PVR
  '';

  traefikRoutes =
    {
      host,
      ...
    }:
    let
      hostname = host.hostname;
      config = host.config.sonarr;
    in
    [
      {
        name = "${hostname}-sonarr";
        rule = "Host(`${config.domain}`)";
        target = "http://${host.ip}:8989";
      }
    ];

  nixosModule =
    { lib, ... }:
    {
      options.sonarr = {
        domain = lib.mkOption {
          type = lib.types.str;
        };
      };

      config = {
        # Enable the sonarr service
        services.sonarr = {
          enable = true;
          openFirewall = true;
          group = "media";
        };

        # Ensure that the media group exists
        users.groups.media = { };
      };
    };
}