2021-08-18 13:19:15 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.navidrome;
|
|
|
|
settingsFormat = pkgs.formats.json {};
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.navidrome = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Navidrome music server");
|
2021-08-18 13:19:15 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "navidrome" { };
|
2023-05-24 13:37:59 +00:00
|
|
|
|
2021-08-18 13:19:15 +00:00
|
|
|
settings = mkOption rec {
|
|
|
|
type = settingsFormat.type;
|
|
|
|
apply = recursiveUpdate default;
|
|
|
|
default = {
|
|
|
|
Address = "127.0.0.1";
|
|
|
|
Port = 4533;
|
|
|
|
};
|
|
|
|
example = {
|
|
|
|
MusicFolder = "/mnt/music";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Configuration for Navidrome, see <https://www.navidrome.org/docs/usage/configuration-options/> for supported values.
|
2021-08-18 13:19:15 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc "Whether to open the TCP port in the firewall";
|
|
|
|
};
|
2021-08-18 13:19:15 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-11-16 04:20:00 +00:00
|
|
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [cfg.settings.Port];
|
|
|
|
|
2021-08-18 13:19:15 +00:00
|
|
|
systemd.services.navidrome = {
|
|
|
|
description = "Navidrome Media Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
2023-05-24 13:37:59 +00:00
|
|
|
${cfg.package}/bin/navidrome --configfile ${settingsFormat.generate "navidrome.json" cfg.settings}
|
2021-08-18 13:19:15 +00:00
|
|
|
'';
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "navidrome";
|
|
|
|
WorkingDirectory = "/var/lib/navidrome";
|
|
|
|
RuntimeDirectory = "navidrome";
|
|
|
|
RootDirectory = "/run/navidrome";
|
|
|
|
ReadWritePaths = "";
|
2024-02-07 01:22:34 +00:00
|
|
|
BindPaths = lib.optional (cfg.settings ? DataFolder) cfg.settings.DataFolder;
|
2021-08-18 13:19:15 +00:00
|
|
|
BindReadOnlyPaths = [
|
2022-06-26 10:26:21 +00:00
|
|
|
# navidrome uses online services to download additional album metadata / covers
|
|
|
|
"${config.environment.etc."ssl/certs/ca-certificates.crt".source}:/etc/ssl/certs/ca-certificates.crt"
|
2021-08-18 13:19:15 +00:00
|
|
|
builtins.storeDir
|
2022-07-14 12:49:19 +00:00
|
|
|
"/etc"
|
2021-08-18 13:19:15 +00:00
|
|
|
] ++ lib.optional (cfg.settings ? MusicFolder) cfg.settings.MusicFolder;
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
SystemCallArchitectures = "native";
|
2022-10-30 15:09:59 +00:00
|
|
|
SystemCallFilter = [ "@system-service" "~@privileged" ];
|
2021-08-18 13:19:15 +00:00
|
|
|
RestrictRealtime = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
UMask = "0066";
|
|
|
|
ProtectHostname = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|