1 { config, lib, options, pkgs, ... }:
3 cfg = config.services.airsonic;
4 opt = options.services.airsonic;
9 enable = lib.mkEnableOption "Airsonic, the Free and Open Source media streaming server (fork of Subsonic and Libresonic)";
14 description = "User account under which airsonic runs.";
18 type = lib.types.path;
19 default = "/var/lib/airsonic";
21 The directory where Airsonic will create files.
22 Make sure it is writable.
26 virtualHost = lib.mkOption {
27 type = lib.types.nullOr lib.types.str;
30 Name of the nginx virtualhost to use and setup. If null, do not setup any virtualhost.
34 listenAddress = lib.mkOption {
36 default = "127.0.0.1";
38 The host name or IP address on which to bind Airsonic.
39 The default value is appropriate for first launch, when the
40 default credentials are easy to guess. It is also appropriate
41 if you intend to use the virtualhost option in the service
42 module. In other cases, you may want to change this to a
43 specific IP or 0.0.0.0 to listen on all interfaces.
48 type = lib.types.port;
51 The port on which Airsonic will listen for
52 incoming HTTP traffic. Set to 0 to disable.
56 contextPath = lib.mkOption {
57 type = lib.types.path;
60 The context path, i.e., the last part of the Airsonic
61 URL. Typically '/' or '/airsonic'. Default '/'
65 maxMemory = lib.mkOption {
69 The memory limit (max Java heap size) in megabytes.
74 transcoders = lib.mkOption {
75 type = lib.types.listOf lib.types.path;
76 default = [ "${pkgs.ffmpeg.bin}/bin/ffmpeg" ];
77 defaultText = lib.literalExpression ''[ "''${pkgs.ffmpeg.bin}/bin/ffmpeg" ]'';
79 List of paths to transcoder executables that should be accessible
80 from Airsonic. Symlinks will be created to each executable inside
81 ''${config.${opt.home}}/transcoders.
85 jre = lib.mkPackageOption pkgs "jre8" {
88 Airsonic only supports Java 8, airsonic-advanced requires at least
95 type = lib.types.path;
96 default = "${pkgs.airsonic}/webapps/airsonic.war";
97 defaultText = lib.literalExpression ''"''${pkgs.airsonic}/webapps/airsonic.war"'';
98 description = "Airsonic war file to use.";
101 jvmOptions = lib.mkOption {
103 Extra command line options for the JVM running AirSonic.
104 Useful for sending jukebox output to non-default alsa
109 type = lib.types.listOf lib.types.str;
111 "-Djavax.sound.sampled.Clip='#CODEC [plughw:1,0]'"
112 "-Djavax.sound.sampled.Port='#Port CODEC [hw:1]'"
113 "-Djavax.sound.sampled.SourceDataLine='#CODEC [plughw:1,0]'"
114 "-Djavax.sound.sampled.TargetDataLine='#CODEC [plughw:1,0]'"
121 config = lib.mkIf cfg.enable {
122 systemd.services.airsonic = {
123 description = "Airsonic Media Server";
124 after = [ "network.target" ];
125 wantedBy = [ "multi-user.target" ];
128 # Install transcoders.
129 rm -rf ${cfg.home}/transcode
130 mkdir -p ${cfg.home}/transcode
131 for exe in ${toString cfg.transcoders}; do
132 ln -sf "$exe" ${cfg.home}/transcode
137 ${cfg.jre}/bin/java -Xmx${toString cfg.maxMemory}m \
138 -Dairsonic.home=${cfg.home} \
139 -Dserver.address=${cfg.listenAddress} \
140 -Dserver.port=${toString cfg.port} \
141 -Dserver.context-path=${cfg.contextPath} \
142 -Djava.awt.headless=true \
143 ${lib.optionalString (cfg.virtualHost != null)
144 "-Dserver.use-forward-headers=true"} \
145 ${toString cfg.jvmOptions} \
155 services.nginx = lib.mkIf (cfg.virtualHost != null) {
157 recommendedProxySettings = true;
158 virtualHosts.${cfg.virtualHost} = {
159 locations.${cfg.contextPath}.proxyPass = "http://${cfg.listenAddress}:${toString cfg.port}";
163 users.users.airsonic = {
164 description = "Airsonic service user";
171 users.groups.airsonic = {};