Files
dev/configs/nixos/guests/navidrome.nix

95 lines
2.6 KiB
Nix

{
config,
lib,
...
}:
let
serviceConfig = config.containers.navidrome.config.modules.services.navidrome;
lastfmApiKeySecret = "services/navidrome/lastfm/api-key";
lastfmSecretSecret = "services/navidrome/lastfm/secret";
lastfmApiKeyFile = "/run/secrets/${lastfmApiKeySecret}";
lastfmSecretFile = "/run/secrets/${lastfmSecretSecret}";
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;
inherit lastfmApiKeyFile lastfmSecretFile;
};
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";
};
${lastfmApiKeyFile} = {
file = config.sops.secrets.${lastfmApiKeySecret}.path;
readOnly = true;
};
${lastfmSecretFile} = {
file = config.sops.secrets.${lastfmSecretSecret}.path;
readOnly = true;
};
};
limits = {
memory = lib.mkDefault "2G";
cpu = lib.mkDefault "200%";
tasksMax = lib.mkDefault 512;
};
};
sops.secrets = {
${lastfmApiKeySecret} = {
sopsFile = hostSecrets;
owner = "root";
group = "storage";
mode = "0440";
};
${lastfmSecretSecret} = {
sopsFile = hostSecrets;
owner = "root";
group = "storage";
mode = "0440";
};
};
};
}