1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3 track = pkgs.fetchurl {
4 # Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
5 # License: http://creativecommons.org/licenses/by-sa/4.0/
7 name = "Blue_Wave_Theory-Skyhawk_Beach.mp3";
8 url = "https://freemusicarchive.org/file/music/ccCommunity/Blue_Wave_Theory/Surf_Music_Month_Challenge/Blue_Wave_Theory_-_04_-_Skyhawk_Beach.mp3";
9 sha256 = "0xw417bxkx4gqqy139bb21yldi37xx8xjfxrwaqa0gyw19dl6mgp";
15 dataDir = "/var/lib/mpd";
16 musicDirectory = "${dataDir}/music";
19 defaultMpdCfg = with defaultCfg; {
20 inherit dataDir musicDirectory user group;
24 musicService = { user, group, musicDirectory }: {
25 description = "Sets up the music file(s) for MPD to use.";
26 requires = [ "mpd.service" ];
27 after = [ "mpd.service" ];
28 wantedBy = [ "default.target" ];
30 cp ${track} ${musicDirectory}
38 mkServer = { mpd, musicService, }:
39 { boot.kernelModules = [ "snd-dummy" ];
41 systemd.services.musicService = musicService;
45 meta = with pkgs.lib.maintainers; {
46 maintainers = [ emmanuelrosa ];
54 { ... }: lib.mkMerge [
56 mpd = defaultMpdCfg // {
57 network.listenAddress = "any";
66 musicService = with defaultMpdCfg; musicService { inherit user group musicDirectory; };
68 { networking.firewall.allowedTCPPorts = [ 6600 ]; }
72 { ... }: lib.mkMerge [
74 mpd = defaultMpdCfg // {
83 musicService = with defaultCfg; musicService { inherit user group musicDirectory; };
86 hardware.pulseaudio = {
90 tcp.anonymousClients.allowAll = true;
92 systemd.services.mpd.environment.PULSE_SERVER = "localhost";
98 mpc = "${pkgs.mpc-cli}/bin/mpc --wait"
100 # Connects to the given server and attempts to play a tune.
101 def play_some_music(server):
102 server.wait_for_unit("mpd.service")
103 server.succeed(f"{mpc} update")
104 _, tracks = server.execute(f"{mpc} ls")
106 for track in tracks.splitlines():
107 server.succeed(f"{mpc} add {track}")
109 _, added_tracks = server.execute(f"{mpc} playlist")
111 # Check we succeeded adding audio tracks to the playlist
112 assert len(added_tracks.splitlines()) > 0
114 server.succeed(f"{mpc} play")
116 _, output = server.execute(f"{mpc} status")
117 # Assure audio track is playing
118 assert "playing" in output
120 server.succeed(f"{mpc} stop")
123 play_some_music(serverALSA)
124 play_some_music(serverPulseAudio)
126 client.wait_for_unit("multi-user.target")
127 client.succeed(f"{mpc} -h serverALSA status")
129 # The PulseAudio-based server is configured not to accept external client connections
130 # to perform the following test:
131 client.fail(f"{mpc} -h serverPulseAudio status")