nixcfg/nixosModules/containers/nixos/navidrome/default.nix

82 lines
3.2 KiB
Nix
Raw Normal View History

2024-04-07 22:16:33 -04:00
{
config,
2024-06-09 00:08:00 -04:00
inputs,
lib,
pkgs,
2024-06-08 10:04:44 -04:00
self,
2024-04-07 22:16:33 -04:00
...
}: {
config = lib.mkIf config.alyraffauf.containers.nixos.navidrome.enable {
2024-06-09 00:08:00 -04:00
# Spotify secrets aren't exactly safe, because they are world-readable in the nix store.
# But they're reasonably disposable and hidden from the public git repo.
age.secrets.lastFMApiKey.file = ../../../../secrets/lastFM/apiKey.age;
age.secrets.lastFMSecret.file = ../../../../secrets/lastFM/secret.age;
2024-06-09 00:08:00 -04:00
age.secrets.spotifyClientId.file = ../../../../secrets/spotify/clientId.age;
age.secrets.spotifyClientSecret.file = ../../../../secrets/spotify/clientSecret.age;
containers.navidrome = let
navidromeConfig = builtins.toFile "navidrome.json" ''
{
"Address": "0.0.0.0",
"DefaultTheme": "Auto",
"MusicFolder": "/Music",
"Port": ${toString config.alyraffauf.containers.nixos.navidrome.port},
"SubsonicArtistParticipations": true,
"UIWelcomeMessage": "Welcome to Navidrome! Registrations are closed.",
"Spotify.ID": "@spotifyClientId@",
"Spotify.Secret": "@spotifyClientSecret@",
"LastFM.Enabled": true,
"LastFM.ApiKey": "@lastFMApiKey@",
"LastFM.Secret": "@lastFMSecret@",
"LastFM.Language": "en"
}
'';
in {
autoStart = true;
bindMounts = {
"/Music".hostPath = config.alyraffauf.containers.nixos.navidrome.musicDirectory;
"/var/lib/navidrome/rawNavidrome.json".hostPath = navidromeConfig;
"${config.age.secrets.lastFMApiKey.path}".isReadOnly = true;
"${config.age.secrets.lastFMSecret.path}".isReadOnly = true;
"${config.age.secrets.spotifyClientId.path}".isReadOnly = true;
"${config.age.secrets.spotifyClientSecret.path}".isReadOnly = true;
};
2024-06-08 10:04:44 -04:00
config = let
lastFMApiKey = config.age.secrets.lastFMApiKey.path;
lastFMSecret = config.age.secrets.lastFMSecret.path;
spotifyClientId = config.age.secrets.spotifyClientId.path;
spotifyClientSecret = config.age.secrets.spotifyClientSecret.path;
2024-06-08 10:04:44 -04:00
in
{
config,
pkgs,
lib,
...
}: {
system.stateVersion = "24.05";
system.activationScripts."navidrome-secrets" = ''
lastFMApiKey=$(cat "${lastFMApiKey}")
lastFMSecret=$(cat "${lastFMSecret}")
spotifyClientId=$(cat "${spotifyClientId}")
spotifyClientSecret=$(cat "${spotifyClientSecret}")
${pkgs.gnused}/bin/sed -e "s/@lastFMApiKey@/$lastFMApiKey/" -e "s/@lastFMSecret@/$lastFMSecret/" \
-e "s/@spotifyClientId@/$spotifyClientId/" -e "s/@spotifyClientSecret@/$spotifyClientSecret/" \
/var/lib/navidrome/rawNavidrome.json > /var/lib/navidrome/navidrome.json
'';
systemd.services.navidrome.serviceConfig = {
ExecStart = lib.mkForce ''
${config.services.navidrome.package}/bin/navidrome --configfile /var/lib/navidrome/navidrome.json \
--datafolder /var/lib/navidrome/
'';
BindReadOnlyPaths = "/Music";
};
2024-06-08 10:04:44 -04:00
services.navidrome = {
enable = true;
openFirewall = true;
};
};
};
};
2024-03-28 16:40:23 -04:00
}