nixos: swap navidrome container for bare metal service

This commit is contained in:
Aly Raffauf 2024-07-05 12:14:48 -04:00
parent 4208efb78f
commit db40755c05
8 changed files with 70 additions and 164 deletions

View file

@ -158,7 +158,7 @@ in {
forceSSL = true; forceSSL = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:${toString config.ar.containers.nixos.navidrome.port}"; proxyPass = "http://127.0.0.1:${toString config.ar.services.navidrome.port}";
proxyWebsockets = true; proxyWebsockets = true;
extraConfig = '' extraConfig = ''
@ -289,8 +289,6 @@ in {
}; };
containers = { containers = {
nixos.navidrome.enable = true;
oci = { oci = {
audiobookshelf.enable = true; audiobookshelf.enable = true;
freshRSS.enable = true; freshRSS.enable = true;
@ -332,6 +330,7 @@ in {
musicPath = "${mediaDirectory}/Music"; musicPath = "${mediaDirectory}/Music";
}; };
navidrome.enable = true;
tailscale.enable = true; tailscale.enable = true;
}; };
}; };

View file

@ -4,5 +4,5 @@
config, config,
... ...
}: { }: {
imports = [./nixos ./oci]; imports = [./oci];
} }

View file

@ -1,33 +0,0 @@
{
pkgs,
lib,
config,
...
}: {
config = lib.mkIf config.ar.containers.nixos.audiobookshelf.enable {
containers.audiobookshelf = {
autoStart = true;
bindMounts."/Media" = {
hostPath = config.ar.containers.nixos.audiobookshelf.mediaDirectory;
isReadOnly = false;
};
config = let
port = config.ar.containers.nixos.audiobookshelf.port;
in
{
config,
lib,
pkgs,
...
}: {
system.stateVersion = "24.05";
services.audiobookshelf = {
enable = true;
openFirewall = true;
host = "0.0.0.0";
port = port;
};
};
};
};
}

View file

@ -1,11 +0,0 @@
{
pkgs,
lib,
config,
...
}: {
imports = [
./audiobookshelf
./navidrome
];
}

View file

@ -1,82 +0,0 @@
{
config,
lib,
pkgs,
...
}: {
config = lib.mkIf config.ar.containers.nixos.navidrome.enable {
age.secrets.lastFMApiKey.file = ../../../../secrets/lastFM/apiKey.age;
age.secrets.lastFMSecret.file = ../../../../secrets/lastFM/secret.age;
age.secrets.spotifyClientId.file = ../../../../secrets/spotify/clientId.age;
age.secrets.spotifyClientSecret.file = ../../../../secrets/spotify/clientSecret.age;
containers.navidrome = let
navidromeConfig = builtins.toFile "navidrome.json" (lib.generators.toJSON {} {
Address = "0.0.0.0";
DefaultTheme = "Auto";
MusicFolder = "/Music";
Port = config.ar.containers.nixos.navidrome.port;
SubsonicArtistParticipations = true;
UIWelcomeMessage = "Welcome to Navidrome @ RaffaufLabs.com";
"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.ar.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;
};
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;
in
{
config,
pkgs,
lib,
...
}: {
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
'';
stateVersion = "24.05";
};
systemd.services.navidrome.serviceConfig = {
BindReadOnlyPaths = "/Music";
ExecStart = lib.mkForce ''
${config.services.navidrome.package}/bin/navidrome --configfile /var/lib/navidrome/navidrome.json \
--datafolder /var/lib/navidrome/
'';
};
services.navidrome = {
enable = true;
openFirewall = true;
};
};
};
};
}

View file

@ -16,40 +16,6 @@
}; };
containers = { containers = {
nixos = {
audiobookshelf = {
enable = lib.mkEnableOption "audiobookshelf server in NixOS container.";
mediaDirectory = lib.mkOption {
description = "Media directory for audiobookshelf.";
default = "/mnt/Media";
type = lib.types.str;
};
port = lib.mkOption {
description = "Port for audiobookshelf.";
default = 13378;
type = lib.types.int;
};
};
navidrome = {
enable = lib.mkEnableOption "Navidrome music server in NixOS container.";
musicDirectory = lib.mkOption {
description = "Music directory for Navidrome.";
default = "/mnt/Media/Music";
type = lib.types.str;
};
port = lib.mkOption {
description = "Port for Navidrome.";
default = 4533;
type = lib.types.int;
};
};
};
oci = { oci = {
audiobookshelf = { audiobookshelf = {
enable = lib.mkEnableOption "audiobookshelf server in OCI container."; enable = lib.mkEnableOption "audiobookshelf server in OCI container.";
@ -189,6 +155,22 @@
services = { services = {
flatpak.enable = lib.mkEnableOption "Flatpak support with GUI."; flatpak.enable = lib.mkEnableOption "Flatpak support with GUI.";
navidrome = {
enable = lib.mkEnableOption "Navidrome music server with secrets.";
musicDirectory = lib.mkOption {
description = "Music directory for Navidrome.";
default = "/mnt/Media/Music";
type = lib.types.str;
};
port = lib.mkOption {
description = "Port for Navidrome.";
default = 4533;
type = lib.types.int;
};
};
syncthing = { syncthing = {
enable = lib.mkEnableOption "Syncthing sync service."; enable = lib.mkEnableOption "Syncthing sync service.";

View file

@ -6,6 +6,7 @@
}: { }: {
imports = [ imports = [
./flatpak ./flatpak
./navidrome
./syncthing ./syncthing
./tailscale ./tailscale
]; ];

View file

@ -0,0 +1,50 @@
{
config,
lib,
pkgs,
...
}: {
config = lib.mkIf config.ar.services.navidrome.enable {
age.secrets.lastFMApiKey.file = ../../../secrets/lastFM/apiKey.age;
age.secrets.lastFMSecret.file = ../../../secrets/lastFM/secret.age;
age.secrets.spotifyClientId.file = ../../../secrets/spotify/clientId.age;
age.secrets.spotifyClientSecret.file = ../../../secrets/spotify/clientSecret.age;
system.activationScripts."navidrome-secrets" = let
navidromeConfig = builtins.toFile "navidrome.json" (lib.generators.toJSON {} {
Address = "0.0.0.0";
DefaultTheme = "Auto";
MusicFolder = config.ar.services.navidrome.musicDirectory;
Port = config.ar.services.navidrome.port;
SubsonicArtistParticipations = true;
UIWelcomeMessage = "Welcome to Navidrome @ RaffaufLabs.com";
"Spotify.ID" = "@spotifyClientId@";
"Spotify.Secret" = "@spotifyClientSecret@";
"LastFM.Enabled" = true;
"LastFM.ApiKey" = "@lastFMApiKey@";
"LastFM.Secret" = "@lastFMSecret@";
"LastFM.Language" = "en";
});
in ''
lastFMApiKey=$(cat "${config.age.secrets.lastFMApiKey.path}")
lastFMSecret=$(cat "${config.age.secrets.lastFMSecret.path}")
spotifyClientId=$(cat "${config.age.secrets.spotifyClientId.path}")
spotifyClientSecret=$(cat "${config.age.secrets.spotifyClientSecret.path}")
${pkgs.gnused}/bin/sed -e "s/@lastFMApiKey@/$lastFMApiKey/" -e "s/@lastFMSecret@/$lastFMSecret/" \
-e "s/@spotifyClientId@/$spotifyClientId/" -e "s/@spotifyClientSecret@/$spotifyClientSecret/" \
${navidromeConfig} > /var/lib/navidrome/navidrome.json
'';
systemd.services.navidrome.serviceConfig = {
BindReadOnlyPaths = "${config.ar.services.navidrome.musicDirectory}";
ExecStart = lib.mkForce ''
${config.services.navidrome.package}/bin/navidrome --configfile /var/lib/navidrome/navidrome.json \
--datafolder /var/lib/navidrome/
'';
};
services.navidrome = {
enable = true;
};
};
}