1{ config, coreutils, lib, pkgs, ... }: 2 3with lib; 4 5let cfg = config.services.tvheadend; 6 pidFile = "${config.users.extraUsers.tvheadend.home}/tvheadend.pid"; 7in 8 9{ 10 options = { 11 services.tvheadend = { 12 enable = mkEnableOption "Tvheadend"; 13 httpPort = mkOption { 14 type = types.int; 15 default = 9981; 16 description = "Port to bind HTTP to."; 17 }; 18 19 htspPort = mkOption { 20 type = types.int; 21 default = 9982; 22 description = "Port to bind HTSP to."; 23 }; 24 }; 25 }; 26 27 config = mkIf cfg.enable { 28 users.extraUsers.tvheadend = { 29 description = "Tvheadend Service user"; 30 home = "/var/lib/tvheadend"; 31 createHome = true; 32 uid = config.ids.uids.tvheadend; 33 }; 34 35 systemd.services.tvheadend = { 36 description = "Tvheadend TV streaming server"; 37 wantedBy = [ "multi-user.target" ]; 38 after = [ "network.target" ]; 39 40 serviceConfig = { 41 Type = "forking"; 42 PIDFile = pidFile; 43 Restart = "always"; 44 RestartSec = 5; 45 User = "tvheadend"; 46 Group = "video"; 47 ExecStart = '' 48 ${pkgs.tvheadend}/bin/tvheadend \ 49 --http_port ${toString cfg.httpPort} \ 50 --htsp_port ${toString cfg.htspPort} \ 51 -f \ 52 -C \ 53 -p ${pidFile} \ 54 -u tvheadend \ 55 -g video 56 ''; 57 ExecStop = "${pkgs.coreutils}/bin/rm ${pidFile}"; 58 }; 59 }; 60 }; 61}