refactor(nixos): simplify navidrome options
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.guests.navidrome;
|
||||
dataDir = "/var/lib/navidrome";
|
||||
musicDir = "/music";
|
||||
envFile = "/run/secrets/navidrome.env";
|
||||
hasLastfmSecrets = cfg.lastfmApiKeySecret != null && cfg.lastfmSecretSecret != null;
|
||||
lastfmApiKeySecret = "services/navidrome/lastfm/api-key";
|
||||
lastfmSecretSecret = "services/navidrome/lastfm/secret";
|
||||
hostSecrets = ../secrets + "/${config.networking.hostName}.yaml";
|
||||
in
|
||||
{
|
||||
@@ -15,105 +17,50 @@ in
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "/srv/navidrome";
|
||||
description = "Host path bind-mounted as Navidrome's state directory.";
|
||||
description = "Host path mounted as Navidrome's data folder.";
|
||||
};
|
||||
|
||||
musicPath = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
example = "/srv/music";
|
||||
description = "Host path bind-mounted as Navidrome's music directory.";
|
||||
};
|
||||
|
||||
dataDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/lib/navidrome";
|
||||
description = "Guest path where Navidrome stores state.";
|
||||
};
|
||||
|
||||
musicDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/music";
|
||||
description = "Guest path where Navidrome reads the music library.";
|
||||
};
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 4533;
|
||||
description = "Port Navidrome listens on.";
|
||||
};
|
||||
|
||||
enableSharing = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Enables Navidrome sharing support.";
|
||||
};
|
||||
|
||||
settings = lib.mkOption {
|
||||
type = lib.types.attrs;
|
||||
default = { };
|
||||
description = "Additional non-secret Navidrome settings.";
|
||||
};
|
||||
|
||||
lastfmApiKeySecret = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "services/navidrome/lastfm/api-key";
|
||||
description = "SOPS secret name containing the Navidrome Last.fm API key.";
|
||||
};
|
||||
|
||||
lastfmSecretSecret = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = "services/navidrome/lastfm/secret";
|
||||
description = "SOPS secret name containing the Navidrome Last.fm secret.";
|
||||
description = "Host path mounted as Navidrome's music library.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
config = lib.mkIf config.guests.navidrome.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = cfg.dataPath != null;
|
||||
message = "guests.navidrome.dataPath must point at the host directory that stores Navidrome state.";
|
||||
assertion = config.guests.navidrome.dataPath != null;
|
||||
message = "guests.navidrome.dataPath must point at the host directory that stores Navidrome data.";
|
||||
}
|
||||
{
|
||||
assertion = cfg.musicPath != null;
|
||||
assertion = config.guests.navidrome.musicPath != null;
|
||||
message = "guests.navidrome.musicPath must point at the host directory that stores the music library.";
|
||||
}
|
||||
];
|
||||
|
||||
guests.navidrome = {
|
||||
interior.modules.services.navidrome = {
|
||||
enable = true;
|
||||
inherit (cfg)
|
||||
dataDir
|
||||
musicDir
|
||||
port
|
||||
enableSharing
|
||||
settings
|
||||
;
|
||||
environmentFile = if hasLastfmSecrets then envFile else null;
|
||||
};
|
||||
interior.modules.services.navidrome.enable = true;
|
||||
|
||||
mounts =
|
||||
{
|
||||
${cfg.dataDir} = {
|
||||
directory = cfg.dataPath;
|
||||
owner = config.registry."stable-uid".${config.networking.hostName}.navidrome;
|
||||
group = "storage";
|
||||
mode = "2770";
|
||||
};
|
||||
${cfg.musicDir} = {
|
||||
directory = cfg.musicPath;
|
||||
owner = "root";
|
||||
group = "storage";
|
||||
mode = "2770";
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs hasLastfmSecrets {
|
||||
${envFile} = {
|
||||
file = config.sops.templates."navidrome.env".path;
|
||||
readOnly = true;
|
||||
};
|
||||
mounts = {
|
||||
${dataDir} = {
|
||||
directory = config.guests.navidrome.dataPath;
|
||||
owner = config.registry."stable-uid".${config.networking.hostName}.navidrome;
|
||||
group = "storage";
|
||||
mode = "2770";
|
||||
};
|
||||
${musicDir} = {
|
||||
directory = config.guests.navidrome.musicPath;
|
||||
owner = "root";
|
||||
group = "storage";
|
||||
mode = "2770";
|
||||
};
|
||||
${envFile} = {
|
||||
file = config.sops.templates."navidrome.env".path;
|
||||
readOnly = true;
|
||||
};
|
||||
};
|
||||
|
||||
limits = {
|
||||
memory = lib.mkDefault "2G";
|
||||
@@ -122,18 +69,18 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
sops.secrets = lib.optionalAttrs hasLastfmSecrets {
|
||||
${cfg.lastfmApiKeySecret}.sopsFile = hostSecrets;
|
||||
${cfg.lastfmSecretSecret}.sopsFile = hostSecrets;
|
||||
sops.secrets = {
|
||||
${lastfmApiKeySecret}.sopsFile = hostSecrets;
|
||||
${lastfmSecretSecret}.sopsFile = hostSecrets;
|
||||
};
|
||||
|
||||
sops.templates."navidrome.env" = lib.mkIf hasLastfmSecrets {
|
||||
sops.templates."navidrome.env" = {
|
||||
owner = "root";
|
||||
group = "storage";
|
||||
mode = "0440";
|
||||
content = ''
|
||||
ND_LASTFM_APIKEY=${config.sops.placeholder.${cfg.lastfmApiKeySecret}}
|
||||
ND_LASTFM_SECRET=${config.sops.placeholder.${cfg.lastfmSecretSecret}}
|
||||
ND_LASTFM_APIKEY=${config.sops.placeholder.${lastfmApiKeySecret}}
|
||||
ND_LASTFM_SECRET=${config.sops.placeholder.${lastfmSecretSecret}}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user