at 17.09-beta 3.3 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.airsonic; 7in { 8 options = { 9 10 services.airsonic = { 11 enable = mkEnableOption "Airsonic, the Free and Open Source media streaming server (fork of Subsonic and Libresonic)"; 12 13 user = mkOption { 14 type = types.str; 15 default = "airsonic"; 16 description = "User account under which airsonic runs."; 17 }; 18 19 home = mkOption { 20 type = types.path; 21 default = "/var/lib/airsonic"; 22 description = '' 23 The directory where Airsonic will create files. 24 Make sure it is writable. 25 ''; 26 }; 27 28 listenAddress = mkOption { 29 type = types.string; 30 default = "127.0.0.1"; 31 description = '' 32 The host name or IP address on which to bind Airsonic. 33 Only relevant if you have multiple network interfaces and want 34 to make Airsonic available on only one of them. The default value 35 will bind Airsonic to all available network interfaces. 36 ''; 37 }; 38 39 port = mkOption { 40 type = types.int; 41 default = 4040; 42 description = '' 43 The port on which Airsonic will listen for 44 incoming HTTP traffic. Set to 0 to disable. 45 ''; 46 }; 47 48 contextPath = mkOption { 49 type = types.path; 50 default = "/"; 51 description = '' 52 The context path, i.e., the last part of the Airsonic 53 URL. Typically '/' or '/airsonic'. Default '/' 54 ''; 55 }; 56 57 maxMemory = mkOption { 58 type = types.int; 59 default = 100; 60 description = '' 61 The memory limit (max Java heap size) in megabytes. 62 Default: 100 63 ''; 64 }; 65 66 transcoders = mkOption { 67 type = types.listOf types.path; 68 default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ]; 69 defaultText= [ "\${pkgs.ffmpeg.bin}/bin/ffmpeg" ]; 70 description = '' 71 List of paths to transcoder executables that should be accessible 72 from Airsonic. Symlinks will be created to each executable inside 73 ${cfg.home}/transcoders. 74 ''; 75 }; 76 }; 77 }; 78 79 config = mkIf cfg.enable { 80 systemd.services.airsonic = { 81 description = "Airsonic Media Server"; 82 after = [ "local-fs.target" "network.target" ]; 83 wantedBy = [ "multi-user.target" ]; 84 85 preStart = '' 86 # Install transcoders. 87 rm -rf ${cfg.home}/transcode 88 mkdir -p ${cfg.home}/transcode 89 for exe in ${toString cfg.transcoders}; do 90 ln -sf "$exe" ${cfg.home}/transcode 91 done 92 ''; 93 serviceConfig = { 94 ExecStart = '' 95 ${pkgs.jre}/bin/java -Xmx${toString cfg.maxMemory}m \ 96 -Dairsonic.home=${cfg.home} \ 97 -Dserver.address=${cfg.listenAddress} \ 98 -Dserver.port=${toString cfg.port} \ 99 -Dairsonic.contextPath=${cfg.contextPath} \ 100 -Djava.awt.headless=true \ 101 -verbose:gc \ 102 -jar ${pkgs.airsonic}/webapps/airsonic.war 103 ''; 104 Restart = "always"; 105 User = "airsonic"; 106 UMask = "0022"; 107 }; 108 }; 109 110 users.extraUsers.airsonic = { 111 description = "Airsonic service user"; 112 name = cfg.user; 113 home = cfg.home; 114 createHome = true; 115 }; 116 }; 117}