2019-11-22 20:21:05 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
2018-06-16 21:52:25 +01:00
|
|
|
let
|
|
|
|
track = pkgs.fetchurl {
|
|
|
|
# Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
|
|
|
|
# License: http://creativecommons.org/licenses/by-sa/4.0/
|
|
|
|
|
|
|
|
name = "Blue_Wave_Theory-Skyhawk_Beach.mp3";
|
2020-04-01 02:11:51 +01:00
|
|
|
url = "https://freemusicarchive.org/file/music/ccCommunity/Blue_Wave_Theory/Surf_Music_Month_Challenge/Blue_Wave_Theory_-_04_-_Skyhawk_Beach.mp3";
|
2018-06-16 21:52:25 +01:00
|
|
|
sha256 = "0xw417bxkx4gqqy139bb21yldi37xx8xjfxrwaqa0gyw19dl6mgp";
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultCfg = rec {
|
|
|
|
user = "mpd";
|
|
|
|
group = "mpd";
|
|
|
|
dataDir = "/var/lib/mpd";
|
|
|
|
musicDirectory = "${dataDir}/music";
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultMpdCfg = with defaultCfg; {
|
|
|
|
inherit dataDir musicDirectory user group;
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
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}
|
|
|
|
'';
|
2020-11-25 13:14:48 +00:00
|
|
|
serviceConfig = {
|
|
|
|
User = user;
|
|
|
|
Group = group;
|
|
|
|
};
|
2018-06-16 21:52:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mkServer = { mpd, musicService, }:
|
|
|
|
{ boot.kernelModules = [ "snd-dummy" ];
|
|
|
|
sound.enable = true;
|
|
|
|
services.mpd = mpd;
|
|
|
|
systemd.services.musicService = musicService;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "mpd";
|
2021-01-10 19:08:30 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2018-06-16 21:52:25 +01:00
|
|
|
maintainers = [ emmanuelrosa ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes =
|
2019-11-13 15:41:36 +00:00
|
|
|
{ client =
|
2018-07-20 21:56:59 +01:00
|
|
|
{ ... }: { };
|
2018-06-16 21:52:25 +01:00
|
|
|
|
|
|
|
serverALSA =
|
2019-11-13 15:41:36 +00:00
|
|
|
{ ... }: lib.mkMerge [
|
|
|
|
(mkServer {
|
|
|
|
mpd = defaultMpdCfg // {
|
|
|
|
network.listenAddress = "any";
|
|
|
|
extraConfig = ''
|
|
|
|
audio_output {
|
|
|
|
type "alsa"
|
|
|
|
name "ALSA"
|
|
|
|
mixer_type "null"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
musicService = with defaultMpdCfg; musicService { inherit user group musicDirectory; };
|
|
|
|
})
|
|
|
|
{ networking.firewall.allowedTCPPorts = [ 6600 ]; }
|
|
|
|
];
|
2018-06-16 21:52:25 +01:00
|
|
|
|
|
|
|
serverPulseAudio =
|
2019-11-13 15:41:36 +00:00
|
|
|
{ ... }: lib.mkMerge [
|
|
|
|
(mkServer {
|
|
|
|
mpd = defaultMpdCfg // {
|
|
|
|
extraConfig = ''
|
|
|
|
audio_output {
|
|
|
|
type "pulse"
|
|
|
|
name "The Pulse"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
musicService = with defaultCfg; musicService { inherit user group musicDirectory; };
|
|
|
|
})
|
|
|
|
{
|
|
|
|
hardware.pulseaudio = {
|
|
|
|
enable = true;
|
|
|
|
systemWide = true;
|
|
|
|
tcp.enable = true;
|
|
|
|
tcp.anonymousClients.allowAll = true;
|
|
|
|
};
|
|
|
|
systemd.services.mpd.environment.PULSE_SERVER = "localhost";
|
|
|
|
}
|
|
|
|
];
|
2018-06-16 21:52:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2022-01-25 02:15:59 +00:00
|
|
|
mpc = "${pkgs.mpc-cli}/bin/mpc --wait"
|
2018-06-16 21:52:25 +01:00
|
|
|
|
|
|
|
# Connects to the given server and attempts to play a tune.
|
2019-11-22 20:21:05 +00:00
|
|
|
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 21:52:25 +01:00
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
for track in tracks.splitlines():
|
|
|
|
server.succeed(f"{mpc} add {track}")
|
2018-06-16 21:52:25 +01:00
|
|
|
|
2020-09-08 14:40:45 +01:00
|
|
|
_, added_tracks = server.execute(f"{mpc} playlist")
|
2018-06-16 21:52:25 +01:00
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
# Check we succeeded adding audio tracks to the playlist
|
|
|
|
assert len(added_tracks.splitlines()) > 0
|
2018-06-16 21:52:25 +01:00
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
server.succeed(f"{mpc} play")
|
2018-06-16 21:52:25 +01:00
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
_, output = server.execute(f"{mpc} status")
|
|
|
|
# Assure audio track is playing
|
|
|
|
assert "playing" in output
|
|
|
|
|
|
|
|
server.succeed(f"{mpc} stop")
|
2018-06-16 21:52:25 +01:00
|
|
|
|
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
play_some_music(serverALSA)
|
|
|
|
play_some_music(serverPulseAudio)
|
2018-06-16 21:52:25 +01:00
|
|
|
|
2019-11-22 20:21:05 +00:00
|
|
|
client.wait_for_unit("multi-user.target")
|
|
|
|
client.succeed(f"{mpc} -h serverALSA status")
|
2018-06-16 21:52:25 +01:00
|
|
|
|
|
|
|
# The PulseAudio-based server is configured not to accept external client connections
|
|
|
|
# to perform the following test:
|
2019-11-22 20:21:05 +00:00
|
|
|
client.fail(f"{mpc} -h serverPulseAudio status")
|
2018-06-16 21:52:25 +01:00
|
|
|
'';
|
|
|
|
})
|