From ec6b31f4a6d475fe94cbbdc4b598f842c6979c7c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 19 Aug 2021 11:56:32 +0200 Subject: [PATCH] modules: services: add navidrome --- modules/services/default.nix | 1 + modules/services/navidrome.nix | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 modules/services/navidrome.nix diff --git a/modules/services/default.nix b/modules/services/default.nix index 29ae034..4760ab1 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -15,6 +15,7 @@ ./matrix.nix ./miniflux.nix ./monitoring.nix + ./navidrome.nix ./nextcloud.nix ./nginx.nix ./pirate.nix diff --git a/modules/services/navidrome.nix b/modules/services/navidrome.nix new file mode 100644 index 0000000..779884e --- /dev/null +++ b/modules/services/navidrome.nix @@ -0,0 +1,62 @@ +# A FLOSS self-hosted, subsonic compatible music server +{ config, lib, pkgs, ... }: +let + cfg = config.my.services.navidrome; + domain = config.networking.domain; + navidromeDomain = "music.${config.networking.domain}"; +in +{ + options.my.services.navidrome = with lib; { + enable = mkEnableOption "Navidrome Music Server"; + + settings = mkOption { + type = (pkgs.formats.json { }).type; + default = { }; + example = { + "LastFM.ApiKey" = "MYKEY"; + "LastFM.Secret" = "MYSECRET"; + "Spotify.ID" = "MYKEY"; + "Spotify.Secret" = "MYSECRET"; + }; + description = '' + Additional settings. + ''; + }; + + privatePort = mkOption { + type = types.port; + default = 4533; + example = 8080; + description = "Internal port for webui"; + }; + + musicFolder = mkOption { + type = types.str; + example = "/mnt/music/"; + description = "Music folder"; + }; + }; + + config = lib.mkIf cfg.enable { + services.navidrome = { + enable = true; + + settings = cfg.settings // { + Port = cfg.privatePort; + Address = "127.0.0.1"; # Behind reverse proxy, so only loopback + MusicFolder = cfg.musicFolder; + LogLevel = "info"; + }; + }; + + services.nginx.virtualHosts."${navidromeDomain}" = { + forceSSL = true; + useACMEHost = domain; + + locations."/" = { + proxyPass = "http://127.0.0.1:${toString cfg.privatePort}/"; + proxyWebsockets = true; + }; + }; + }; +}