nixos/navidrome: rfcfmt, rm mdDoc & with lib;

This commit is contained in:
nu-nu-ko 2024-03-01 12:14:36 +13:00 committed by nuko
parent 007f41bff8
commit bbba2bde44
No known key found for this signature in database

View file

@ -1,11 +1,22 @@
{ config, lib, pkgs, ... }: {
config,
with lib; lib,
pkgs,
...
}:
let let
inherit (lib)
mkEnableOption
mkPackageOption
mkOption
recursiveUpdate
;
inherit (lib.types) bool;
cfg = config.services.navidrome; cfg = config.services.navidrome;
settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json { };
in { in
{
options = { options = {
services.navidrome = { services.navidrome = {
@ -23,62 +34,72 @@ in {
example = { example = {
MusicFolder = "/mnt/music"; MusicFolder = "/mnt/music";
}; };
description = '' description = "Configuration for Navidrome, see <https://www.navidrome.org/docs/usage/configuration-options/> for supported values.";
Configuration for Navidrome, see <https://www.navidrome.org/docs/usage/configuration-options/> for supported values.
'';
}; };
openFirewall = mkOption { openFirewall = mkOption {
type = types.bool; type = bool;
default = false; default = false;
description = "Whether to open the TCP port in the firewall"; description = "Whether to open the TCP port in the firewall";
}; };
}; };
}; };
config = mkIf cfg.enable { config =
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [cfg.settings.Port]; let
inherit (lib) mkIf optional;
systemd.services.navidrome = { in
description = "Navidrome Media Server"; mkIf cfg.enable {
after = [ "network.target" ]; systemd.services.navidrome = {
wantedBy = [ "multi-user.target" ]; description = "Navidrome Media Server";
serviceConfig = { after = [ "network.target" ];
ExecStart = '' wantedBy = [ "multi-user.target" ];
${cfg.package}/bin/navidrome --configfile ${settingsFormat.generate "navidrome.json" cfg.settings} serviceConfig = {
''; ExecStart = ''
DynamicUser = true; ${cfg.package}/bin/navidrome --configfile ${settingsFormat.generate "navidrome.json" cfg.settings}
StateDirectory = "navidrome"; '';
WorkingDirectory = "/var/lib/navidrome"; DynamicUser = true;
RuntimeDirectory = "navidrome"; StateDirectory = "navidrome";
RootDirectory = "/run/navidrome"; WorkingDirectory = "/var/lib/navidrome";
ReadWritePaths = ""; RuntimeDirectory = "navidrome";
BindPaths = lib.optional (cfg.settings ? DataFolder) cfg.settings.DataFolder; RootDirectory = "/run/navidrome";
BindReadOnlyPaths = [ ReadWritePaths = "";
# navidrome uses online services to download additional album metadata / covers BindPaths = optional (cfg.settings ? DataFolder) cfg.settings.DataFolder;
"${config.environment.etc."ssl/certs/ca-certificates.crt".source}:/etc/ssl/certs/ca-certificates.crt" BindReadOnlyPaths = [
builtins.storeDir # navidrome uses online services to download additional album metadata / covers
"/etc" "${
] ++ lib.optional (cfg.settings ? MusicFolder) cfg.settings.MusicFolder; config.environment.etc."ssl/certs/ca-certificates.crt".source
CapabilityBoundingSet = ""; }:/etc/ssl/certs/ca-certificates.crt"
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]; builtins.storeDir
RestrictNamespaces = true; "/etc"
PrivateDevices = true; ] ++ optional (cfg.settings ? MusicFolder) cfg.settings.MusicFolder;
PrivateUsers = true; CapabilityBoundingSet = "";
ProtectClock = true; RestrictAddressFamilies = [
ProtectControlGroups = true; "AF_UNIX"
ProtectHome = true; "AF_INET"
ProtectKernelLogs = true; "AF_INET6"
ProtectKernelModules = true; ];
ProtectKernelTunables = true; RestrictNamespaces = true;
SystemCallArchitectures = "native"; PrivateDevices = true;
SystemCallFilter = [ "@system-service" "~@privileged" ]; PrivateUsers = true;
RestrictRealtime = true; ProtectClock = true;
LockPersonality = true; ProtectControlGroups = true;
MemoryDenyWriteExecute = true; ProtectHome = true;
UMask = "0066"; ProtectKernelLogs = true;
ProtectHostname = true; ProtectKernelModules = true;
ProtectKernelTunables = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service"
"~@privileged"
];
RestrictRealtime = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
UMask = "0066";
ProtectHostname = true;
};
}; };
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.Port ];
}; };
};
} }