2024-05-20 12:27:01 -04:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2024-06-24 11:38:28 -04:00
|
|
|
cfg = config.aux.system.services.airsonic;
|
2024-05-20 12:27:01 -04:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
2024-06-24 11:38:28 -04:00
|
|
|
aux.system.services.airsonic = {
|
2024-05-20 12:27:01 -04:00
|
|
|
enable = lib.mkEnableOption (lib.mdDoc "Enables Airsonic Advanced media streaming service.");
|
|
|
|
home = lib.mkOption {
|
2024-05-21 09:22:03 -04:00
|
|
|
default = "";
|
2024-05-20 12:27:01 -04:00
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where to store Airsonic's files";
|
|
|
|
};
|
2024-06-25 14:13:15 -04:00
|
|
|
domain = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The root domain that Airsonic will be hosted on.";
|
|
|
|
example = "example.com";
|
|
|
|
};
|
|
|
|
url = lib.mkOption {
|
|
|
|
default = "";
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "The complete URL where Airsonic is hosted.";
|
|
|
|
example = "https://forgejo.example.com";
|
|
|
|
};
|
2024-05-20 12:27:01 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
aux.system.users.media.enable = true;
|
|
|
|
users.users.airsonic.extraGroups = [ "media" ];
|
2024-05-20 12:27:01 -04:00
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
services = {
|
|
|
|
nginx.virtualHosts."${cfg.url}" = {
|
|
|
|
useACMEHost = cfg.domain;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:4040";
|
|
|
|
proxyWebsockets = true;
|
2024-07-12 10:52:43 -04:00
|
|
|
extraConfig = ''
|
2024-07-12 11:11:20 -04:00
|
|
|
# Taken from https://airsonic.github.io/docs/proxy/nginx/
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
proxy_set_header X-Forwarded-Proto https;
|
|
|
|
proxy_set_header X-Forwarded-Host $host;
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
proxy_max_temp_file_size 0;
|
|
|
|
proxy_ssl_server_name on;
|
2024-07-12 10:52:43 -04:00
|
|
|
'';
|
2024-05-20 12:27:01 -04:00
|
|
|
};
|
2024-07-02 14:40:49 -04:00
|
|
|
};
|
2024-05-20 12:27:01 -04:00
|
|
|
|
2024-07-02 16:19:15 -04:00
|
|
|
airsonic = {
|
|
|
|
enable = true;
|
|
|
|
war = "${
|
|
|
|
(pkgs.callPackage ../../packages/airsonic-advanced.nix { inherit lib; })
|
|
|
|
}/webapps/airsonic.war";
|
|
|
|
port = 4040;
|
|
|
|
jre = pkgs.jdk17;
|
|
|
|
jvmOptions = [
|
|
|
|
"-Dserver.use-forward-headers=true"
|
|
|
|
"-Xmx4G" # Increase Java heap size to 4GB
|
|
|
|
];
|
|
|
|
} // lib.optionalAttrs (cfg.home != "") { home = cfg.home; };
|
|
|
|
};
|
|
|
|
|
2024-08-29 11:59:28 -04:00
|
|
|
systemd.services = {
|
|
|
|
airsonic = lib.mkIf (cfg.home != "") { unitConfig.RequiresMountsFor = cfg.home; };
|
|
|
|
nginx.wants = [ config.systemd.services.airsonic.name ];
|
|
|
|
};
|
2024-07-02 16:19:15 -04:00
|
|
|
};
|
2024-05-20 12:27:01 -04:00
|
|
|
}
|