git.iko.soy/typeable/nixpkgs
on master help sign in
airsonic: Add virtualHost option to set up nginx virtual host

Modeled after nixos/modules/services/web-apps/tt-rss.nix. The setup is slightly non-intuitive, so I think it's worth adding upstream.

commit027d4188b27fc7139edfa4b2c463497c731f66a2 authorRobert Irelan <rirelan@gmail.com> dateThu 31 Jan 2019, 17:09 (8 years ago) parent85ff56c
1 file changed+17
nixos/modules/services/misc/airsonic.nix+17
nixos/modules/services/misc/airsonic.nix+17
@@ -25,6 +25,14 @@ in {
2525 '';
2626 };
2727
28+ virtualHost = mkOption {
29+ type = types.nullOr types.str;
30+ default = null;
31+ description = ''
32+ Name of the nginx virtualhost to use and setup. If null, do not setup any virtualhost.
33+ '';
34+ };
35+
2836 listenAddress = mkOption {
2937 type = types.string;
3038 default = "127.0.0.1";
@@ -116,6 +124,8 @@ in {
116124 -Dserver.port=${toString cfg.port} \
117125 -Dairsonic.contextPath=${cfg.contextPath} \
118126 -Djava.awt.headless=true \
127+ ${optionalString (cfg.virtualHost != null)
128+ "-Dserver.use-forward-headers=true"} \
119129 ${toString cfg.jvmOptions} \
120130 -verbose:gc \
121131 -jar ${pkgs.airsonic}/webapps/airsonic.war
@@ -126,6 +136,13 @@ in {
126136 };
127137 };
128138
139+ services.nginx = mkIf (cfg.virtualHost != null) {
140+ enable = true;
141+ virtualHosts."${cfg.virtualHost}" = {
142+ locations."${cfg.contextPath}".proxyPass = "http://${cfg.listenAddress}:${toString cfg.port}";
143+ };
144+ };
145+
129146 users.users.airsonic = {
130147 description = "Airsonic service user";
131148 name = cfg.user;