at 23.11-pre 3.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.icecast; 7 configFile = pkgs.writeText "icecast.xml" '' 8 <icecast> 9 <hostname>${cfg.hostname}</hostname> 10 11 <authentication> 12 <admin-user>${cfg.admin.user}</admin-user> 13 <admin-password>${cfg.admin.password}</admin-password> 14 </authentication> 15 16 <paths> 17 <logdir>${cfg.logDir}</logdir> 18 <adminroot>${pkgs.icecast}/share/icecast/admin</adminroot> 19 <webroot>${pkgs.icecast}/share/icecast/web</webroot> 20 <alias source="/" dest="/status.xsl"/> 21 </paths> 22 23 <listen-socket> 24 <port>${toString cfg.listen.port}</port> 25 <bind-address>${cfg.listen.address}</bind-address> 26 </listen-socket> 27 28 <security> 29 <chroot>0</chroot> 30 <changeowner> 31 <user>${cfg.user}</user> 32 <group>${cfg.group}</group> 33 </changeowner> 34 </security> 35 36 ${cfg.extraConf} 37 </icecast> 38 ''; 39in { 40 41 ###### interface 42 43 options = { 44 45 services.icecast = { 46 47 enable = mkEnableOption (lib.mdDoc "Icecast server"); 48 49 hostname = mkOption { 50 type = types.nullOr types.str; 51 description = lib.mdDoc "DNS name or IP address that will be used for the stream directory lookups or possibly the playlist generation if a Host header is not provided."; 52 default = config.networking.domain; 53 defaultText = literalExpression "config.networking.domain"; 54 }; 55 56 admin = { 57 user = mkOption { 58 type = types.str; 59 description = lib.mdDoc "Username used for all administration functions."; 60 default = "admin"; 61 }; 62 63 password = mkOption { 64 type = types.str; 65 description = lib.mdDoc "Password used for all administration functions."; 66 }; 67 }; 68 69 logDir = mkOption { 70 type = types.path; 71 description = lib.mdDoc "Base directory used for logging."; 72 default = "/var/log/icecast"; 73 }; 74 75 listen = { 76 port = mkOption { 77 type = types.port; 78 description = lib.mdDoc "TCP port that will be used to accept client connections."; 79 default = 8000; 80 }; 81 82 address = mkOption { 83 type = types.str; 84 description = lib.mdDoc "Address Icecast will listen on."; 85 default = "::"; 86 }; 87 }; 88 89 user = mkOption { 90 type = types.str; 91 description = lib.mdDoc "User privileges for the server."; 92 default = "nobody"; 93 }; 94 95 group = mkOption { 96 type = types.str; 97 description = lib.mdDoc "Group privileges for the server."; 98 default = "nogroup"; 99 }; 100 101 extraConf = mkOption { 102 type = types.lines; 103 description = lib.mdDoc "icecast.xml content."; 104 default = ""; 105 }; 106 107 }; 108 109 }; 110 111 112 ###### implementation 113 114 config = mkIf cfg.enable { 115 116 systemd.services.icecast = { 117 after = [ "network.target" ]; 118 description = "Icecast Network Audio Streaming Server"; 119 wantedBy = [ "multi-user.target" ]; 120 121 preStart = "mkdir -p ${cfg.logDir} && chown ${cfg.user}:${cfg.group} ${cfg.logDir}"; 122 serviceConfig = { 123 Type = "simple"; 124 ExecStart = "${pkgs.icecast}/bin/icecast -c ${configFile}"; 125 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 126 }; 127 }; 128 129 }; 130 131}