86 lines
2.4 KiB
Nix
86 lines
2.4 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
serviceConfig = config.containers.navidrome.config.modules.services.navidrome;
|
|
lastfmApiKeySecret = "services/navidrome/lastfm/api-key";
|
|
lastfmSecretSecret = "services/navidrome/lastfm/secret";
|
|
hostSecrets = ../secrets + "/${config.networking.hostName}.yaml";
|
|
in
|
|
{
|
|
options.guests.navidrome = {
|
|
dataPath = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
example = "/srv/navidrome";
|
|
description = "Host path mounted as Navidrome's data folder.";
|
|
};
|
|
|
|
libraryPath = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.str;
|
|
default = null;
|
|
example = "/srv/music";
|
|
description = "Host path mounted as Navidrome's library folder.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf config.guests.navidrome.enable {
|
|
assertions = [
|
|
{
|
|
assertion = config.guests.navidrome.dataPath != null;
|
|
message = "guests.navidrome.dataPath must point at the host directory that stores Navidrome data.";
|
|
}
|
|
{
|
|
assertion = config.guests.navidrome.libraryPath != null;
|
|
message = "guests.navidrome.libraryPath must point at the host directory that stores Navidrome's library folder.";
|
|
}
|
|
];
|
|
|
|
guests.navidrome = {
|
|
interior.modules.services.navidrome.enable = true;
|
|
|
|
mounts = {
|
|
${serviceConfig.dataDir} = {
|
|
directory = config.guests.navidrome.dataPath;
|
|
owner = config.registry."stable-uid".${config.networking.hostName}.navidrome;
|
|
group = "storage";
|
|
mode = "2770";
|
|
};
|
|
${serviceConfig.libraryDir} = {
|
|
directory = config.guests.navidrome.libraryPath;
|
|
owner = "root";
|
|
group = "storage";
|
|
mode = "2770";
|
|
};
|
|
${"/run/secrets/navidrome.env"} = {
|
|
file = config.sops.templates."navidrome.env".path;
|
|
readOnly = true;
|
|
};
|
|
};
|
|
|
|
limits = {
|
|
memory = lib.mkDefault "2G";
|
|
cpu = lib.mkDefault "200%";
|
|
tasksMax = lib.mkDefault 512;
|
|
};
|
|
};
|
|
|
|
sops.secrets = {
|
|
${lastfmApiKeySecret}.sopsFile = hostSecrets;
|
|
${lastfmSecretSecret}.sopsFile = hostSecrets;
|
|
};
|
|
|
|
sops.templates."navidrome.env" = {
|
|
owner = "root";
|
|
group = "storage";
|
|
mode = "0440";
|
|
content = ''
|
|
ND_LASTFM_APIKEY=${config.sops.placeholder.${lastfmApiKeySecret}}
|
|
ND_LASTFM_SECRET=${config.sops.placeholder.${lastfmSecretSecret}}
|
|
'';
|
|
};
|
|
};
|
|
}
|