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