nixfiles/hosts/hetzner-arm/containers/music/default.nix

126 lines
2.8 KiB
Nix
Raw Normal View History

{
2023-09-18 03:56:58 +01:00
self,
hostPath,
tree,
lib,
inputs,
pkgs,
config,
...
}: let
2023-09-18 03:56:58 +01:00
inherit (lib.modules) mkMerge;
inherit (lib.lists) forEach;
containerName = "music";
2023-09-18 03:56:58 +01:00
containerAddresses = import "${hostPath}/data/containerAddresses.nix";
hostIP = containerAddresses.host;
containerIP = containerAddresses.containers.${containerName};
ports = import ./data/ports.nix;
# these secrets should probs be in host but im lazy
containerSecrets = config.containers.${containerName}.config.services.secrets.secrets;
pathInContainer = path: "/var/lib/nixos-containers/${containerName}" + path;
2023-09-18 03:56:58 +01:00
in {
containers.music = {
autoStart = true;
privateNetwork = true;
hostAddress = hostIP;
localAddress = containerIP;
specialArgs = {
inherit inputs;
inherit tree;
2023-09-18 03:56:58 +01:00
inherit self;
inherit hostPath;
};
config = {...}: {
nixpkgs.pkgs = pkgs;
imports = with tree;
[
2023-09-18 03:56:58 +01:00
presets.nixos.containerBase
profiles.sshd
2023-09-18 03:56:58 +01:00
profiles.firewallAllow.ssh
2023-09-18 03:56:58 +01:00
profiles.nginx
profiles.firewallAllow.httpCommon
./secrets.nix
]
2023-09-30 16:49:52 +01:00
++ (with hosts.hetzner-arm.containers.music.profiles; [
mpd
musicSync
soulseek
]);
2023-09-18 03:56:58 +01:00
networking.firewall.allowedTCPPorts = with ports; [
mpd
mpd-opus-low
mpd-opus-medium
mpd-opus-high
mpd-flac
slskd
slskd-web
];
home-manager.users.root.home.stateVersion = "23.05";
system.stateVersion = "23.05";
};
};
services.nginx.virtualHosts."soulseek.owo.monster" = {
forceSSL = true;
enableACME = true;
locations."/" = {
proxyPass = "http://${containerIP}:${toString ports.slskd-web}";
proxyWebsockets = true;
};
};
services.nginx.virtualHosts."stream.owo.monster" = let
extraConfig = ''
auth_basic "Music Password";
auth_basic_user_file ${pathInContainer containerSecrets.music_stream_passwd.path};
'';
in {
forceSSL = true;
enableACME = true;
2023-09-18 03:56:58 +01:00
locations = mkMerge ([
{
"/mpd/flac" = {
proxyPass = "http://${containerIP}:${toString ports.mpd-flac}";
inherit extraConfig;
};
}
]
2023-09-18 03:56:58 +01:00
++ (forEach ["low" "medium" "high"] (quality: {
"/mpd/opus-${quality}" = {
proxyPass = "http://${containerIP}:${toString ports."mpd-opus-${quality}"}";
inherit extraConfig;
};
})));
};
2023-09-18 03:56:58 +01:00
networking = {
nat.forwardPorts = [
{
sourcePort = ports.mpd;
destination = "${containerIP}\:${toString ports.mpd}";
}
{
sourcePort = ports.slskd;
destination = "${containerIP}\:${toString ports.slskd}";
}
];
firewall.allowedTCPPorts = with ports; [
mpd
slskd
];
};
}