2024-10-17 00:28:57 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, lib, ... }:
|
2018-06-16 20:52:25 +00:00
|
|
|
let
|
|
|
|
track = pkgs.fetchurl {
|
|
|
|
# Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
|
|
|
|
|
|
|
|
name = "Blue_Wave_Theory-Skyhawk_Beach.mp3";
|
2020-04-01 01:11:51 +00:00
|
|
|
url = "https://freemusicarchive.org/file/music/ccCommunity/Blue_Wave_Theory/Surf_Music_Month_Challenge/Blue_Wave_Theory_-_04_-_Skyhawk_Beach.mp3";
|
2024-10-17 00:28:57 +00:00
|
|
|
hash = "sha256-91VDWwrcP6Cw4rk72VHvZ8RGfRBrpRE8xo/02dcJhHc=";
|
|
|
|
meta.license = lib.licenses.cc-by-sa-40;
|
2018-06-16 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
defaultCfg = rec {
|
|
|
|
user = "mpd";
|
|
|
|
group = "mpd";
|
|
|
|
dataDir = "/var/lib/mpd";
|
|
|
|
musicDirectory = "${dataDir}/music";
|
|
|
|
};
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
defaultMpdCfg = {
|
|
|
|
inherit (defaultCfg)
|
|
|
|
dataDir
|
|
|
|
musicDirectory
|
|
|
|
user
|
|
|
|
group
|
|
|
|
;
|
2018-06-16 20:52:25 +00:00
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
musicService =
|
|
|
|
{
|
|
|
|
user,
|
|
|
|
group,
|
|
|
|
musicDirectory,
|
|
|
|
}:
|
|
|
|
{
|
|
|
|
description = "Sets up the music file(s) for MPD to use.";
|
|
|
|
requires = [ "mpd.service" ];
|
|
|
|
after = [ "mpd.service" ];
|
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
script = ''
|
|
|
|
cp ${track} ${musicDirectory}
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
User = user;
|
|
|
|
Group = group;
|
|
|
|
};
|
2020-11-25 13:14:48 +00:00
|
|
|
};
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
mkServer =
|
|
|
|
{ mpd, musicService }:
|
|
|
|
{
|
|
|
|
boot.kernelModules = [ "snd-dummy" ];
|
2018-06-16 20:52:25 +00:00
|
|
|
services.mpd = mpd;
|
|
|
|
systemd.services.musicService = musicService;
|
|
|
|
};
|
2024-10-17 00:28:57 +00:00
|
|
|
in
|
|
|
|
{
|
2018-06-16 20:52:25 +00:00
|
|
|
name = "mpd";
|
2024-10-17 00:28:57 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ emmanuelrosa ];
|
2018-06-16 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
nodes = {
|
|
|
|
client = { ... }: { };
|
2018-06-16 20:52:25 +00:00
|
|
|
|
|
|
|
serverALSA =
|
2024-10-17 00:28:57 +00:00
|
|
|
{ ... }:
|
|
|
|
lib.mkMerge [
|
2019-11-13 15:41:36 +00:00
|
|
|
(mkServer {
|
|
|
|
mpd = defaultMpdCfg // {
|
|
|
|
network.listenAddress = "any";
|
|
|
|
extraConfig = ''
|
|
|
|
audio_output {
|
|
|
|
type "alsa"
|
|
|
|
name "ALSA"
|
|
|
|
mixer_type "null"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2024-10-17 00:28:57 +00:00
|
|
|
musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
|
2019-11-13 15:41:36 +00:00
|
|
|
})
|
|
|
|
{ networking.firewall.allowedTCPPorts = [ 6600 ]; }
|
|
|
|
];
|
2018-06-16 20:52:25 +00:00
|
|
|
|
|
|
|
serverPulseAudio =
|
2024-10-17 00:28:57 +00:00
|
|
|
{ ... }:
|
|
|
|
lib.mkMerge [
|
2019-11-13 15:41:36 +00:00
|
|
|
(mkServer {
|
|
|
|
mpd = defaultMpdCfg // {
|
|
|
|
extraConfig = ''
|
|
|
|
audio_output {
|
|
|
|
type "pulse"
|
|
|
|
name "The Pulse"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
|
2019-11-13 15:41:36 +00:00
|
|
|
})
|
|
|
|
{
|
|
|
|
hardware.pulseaudio = {
|
|
|
|
enable = true;
|
|
|
|
systemWide = true;
|
|
|
|
tcp.enable = true;
|
|
|
|
tcp.anonymousClients.allowAll = true;
|
|
|
|
};
|
|
|
|
systemd.services.mpd.environment.PULSE_SERVER = "localhost";
|
|
|
|
}
|
|
|
|
];
|
2018-06-16 20:52:25 +00:00
|
|
|
};
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
testScript = ''
|
|
|
|
mpc = "${lib.getExe pkgs.mpc} --wait"
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
# Connects to the given server and attempts to play a tune.
|
|
|
|
def play_some_music(server):
|
|
|
|
server.wait_for_unit("mpd.service")
|
|
|
|
server.succeed(f"{mpc} update")
|
|
|
|
_, tracks = server.execute(f"{mpc} ls")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
for track in tracks.splitlines():
|
|
|
|
server.succeed(f"{mpc} add {track}")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
_, added_tracks = server.execute(f"{mpc} playlist")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
# Check we succeeded adding audio tracks to the playlist
|
|
|
|
assert len(added_tracks.splitlines()) > 0
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
server.succeed(f"{mpc} play")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
_, output = server.execute(f"{mpc} status")
|
|
|
|
# Assure audio track is playing
|
|
|
|
assert "playing" in output
|
2019-11-22 20:21:05 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
server.succeed(f"{mpc} stop")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
play_some_music(serverALSA)
|
|
|
|
play_some_music(serverPulseAudio)
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
client.wait_for_unit("multi-user.target")
|
|
|
|
client.succeed(f"{mpc} -h serverALSA status")
|
2018-06-16 20:52:25 +00:00
|
|
|
|
2024-10-17 00:28:57 +00:00
|
|
|
# The PulseAudio-based server is configured not to accept external client connections
|
|
|
|
# to perform the following test:
|
|
|
|
client.fail(f"{mpc} -h serverPulseAudio status")
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|