2022-12-24 17:16:39 +00:00
|
|
|
{
|
2023-09-18 03:56:58 +01:00
|
|
|
self,
|
|
|
|
hostPath,
|
2022-12-24 17:16:39 +00:00
|
|
|
tree,
|
|
|
|
lib,
|
|
|
|
inputs,
|
2023-09-16 16:06:16 +01:00
|
|
|
pkgs,
|
2023-09-21 05:06:27 +01:00
|
|
|
config,
|
2022-12-24 17:16:39 +00:00
|
|
|
...
|
|
|
|
}: let
|
2023-09-18 03:56:58 +01:00
|
|
|
inherit (lib.modules) mkMerge;
|
|
|
|
inherit (lib.lists) forEach;
|
|
|
|
|
2023-09-21 05:06:27 +01:00
|
|
|
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;
|
2023-09-21 05:06:27 +01:00
|
|
|
|
|
|
|
# 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 {
|
2023-10-30 13:57:30 +00:00
|
|
|
nixpkgs.overlays = [
|
2024-03-09 22:18:26 +00:00
|
|
|
(final: _prev: {
|
2023-10-30 14:27:25 +00:00
|
|
|
mpd = final.mpd-headless;
|
2023-10-30 13:57:30 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2022-12-24 17:16:39 +00:00
|
|
|
containers.music = {
|
|
|
|
autoStart = true;
|
|
|
|
privateNetwork = true;
|
|
|
|
hostAddress = hostIP;
|
|
|
|
localAddress = containerIP;
|
|
|
|
|
2023-09-16 16:06:16 +01:00
|
|
|
specialArgs = {
|
|
|
|
inherit inputs;
|
|
|
|
inherit tree;
|
2023-09-18 03:56:58 +01:00
|
|
|
inherit self;
|
|
|
|
inherit hostPath;
|
2023-09-16 16:06:16 +01:00
|
|
|
};
|
|
|
|
|
2023-09-21 05:06:27 +01:00
|
|
|
config = {...}: {
|
2023-09-16 16:06:16 +01:00
|
|
|
nixpkgs.pkgs = pkgs;
|
2022-12-24 17:16:39 +00:00
|
|
|
|
|
|
|
imports = with tree;
|
|
|
|
[
|
2023-09-18 03:56:58 +01:00
|
|
|
presets.nixos.containerBase
|
2022-12-24 17:16:39 +00:00
|
|
|
|
2023-09-18 03:56:58 +01:00
|
|
|
profiles.nginx
|
|
|
|
profiles.firewallAllow.httpCommon
|
2023-09-21 05:06:27 +01:00
|
|
|
|
|
|
|
./secrets.nix
|
2022-12-24 17:16:39 +00:00
|
|
|
]
|
2023-09-30 16:49:52 +01:00
|
|
|
++ (with hosts.hetzner-arm.containers.music.profiles; [
|
|
|
|
mpd
|
|
|
|
musicSync
|
2024-03-09 22:18:26 +00:00
|
|
|
#soulseek # takes up too much ram :(
|
2022-12-24 17:16:39 +00:00
|
|
|
]);
|
2024-05-11 16:29:43 +01:00
|
|
|
home-manager.users.root.imports = with tree; [home.apps.musicutil];
|
2022-12-24 17:16:39 +00:00
|
|
|
|
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";
|
2023-09-11 23:22:18 +01:00
|
|
|
system.stateVersion = "23.05";
|
2022-12-24 17:16:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-08 21:29:08 +01:00
|
|
|
services.nginx.virtualHosts."soulseek.owo.monster" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://${containerIP}:${toString ports.slskd-web}";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-10-27 16:44:17 +01:00
|
|
|
services.nginx.virtualHosts."mpd.owo.monster" = let
|
2022-12-24 17:16:39 +00:00
|
|
|
extraConfig = ''
|
|
|
|
auth_basic "Music Password";
|
2023-09-21 05:06:27 +01:00
|
|
|
auth_basic_user_file ${pathInContainer containerSecrets.music_stream_passwd.path};
|
2022-12-24 17:16:39 +00:00
|
|
|
'';
|
|
|
|
in {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2023-10-16 20:02:47 +01:00
|
|
|
locations = mkMerge [
|
|
|
|
{
|
2023-10-27 16:44:17 +01:00
|
|
|
"/flac" = {
|
2023-10-16 20:02:47 +01:00
|
|
|
proxyPass = "http://${containerIP}:${toString ports.mpd-flac}";
|
|
|
|
inherit extraConfig;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
(mkMerge (forEach ["low" "medium" "high"] (quality: {
|
2023-10-27 16:44:17 +01:00
|
|
|
"/opus-${quality}" = {
|
2022-12-24 17:16:39 +00:00
|
|
|
proxyPass = "http://${containerIP}:${toString ports."mpd-opus-${quality}"}";
|
|
|
|
inherit extraConfig;
|
|
|
|
};
|
2023-10-16 20:02:47 +01:00
|
|
|
})))
|
|
|
|
];
|
2022-12-24 17:16:39 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
];
|
|
|
|
};
|
2022-12-24 17:16:39 +00:00
|
|
|
}
|