1 import ./make-test-python.nix (
4 track = pkgs.fetchurl {
5 # Sourced from http://freemusicarchive.org/music/Blue_Wave_Theory/Surf_Music_Month_Challenge/Skyhawk_Beach_fade_in
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 hash = "sha256-91VDWwrcP6Cw4rk72VHvZ8RGfRBrpRE8xo/02dcJhHc=";
10 meta.license = lib.licenses.cc-by-sa-40;
16 dataDir = "/var/lib/mpd";
17 musicDirectory = "${dataDir}/music";
37 description = "Sets up the music file(s) for MPD to use.";
38 requires = [ "mpd.service" ];
39 after = [ "mpd.service" ];
40 wantedBy = [ "default.target" ];
42 cp ${track} ${musicDirectory}
51 { mpd, musicService }:
53 boot.kernelModules = [ "snd-dummy" ];
55 systemd.services.musicService = musicService;
61 maintainers = with lib.maintainers; [ emmanuelrosa ];
65 client = { ... }: { };
71 mpd = defaultMpdCfg // {
72 network.listenAddress = "any";
81 musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
83 { networking.firewall.allowedTCPPorts = [ 6600 ]; }
90 mpd = defaultMpdCfg // {
99 musicService = musicService { inherit (defaultMpdCfg) user group musicDirectory; };
102 hardware.pulseaudio = {
106 tcp.anonymousClients.allowAll = true;
108 systemd.services.mpd.environment.PULSE_SERVER = "localhost";
114 mpc = "${lib.getExe pkgs.mpc} --wait"
116 # Connects to the given server and attempts to play a tune.
117 def play_some_music(server):
118 server.wait_for_unit("mpd.service")
119 server.succeed(f"{mpc} update")
120 _, tracks = server.execute(f"{mpc} ls")
122 for track in tracks.splitlines():
123 server.succeed(f"{mpc} add {track}")
125 _, added_tracks = server.execute(f"{mpc} playlist")
127 # Check we succeeded adding audio tracks to the playlist
128 assert len(added_tracks.splitlines()) > 0
130 server.succeed(f"{mpc} play")
132 _, output = server.execute(f"{mpc} status")
133 # Assure audio track is playing
134 assert "playing" in output
136 server.succeed(f"{mpc} stop")
139 play_some_music(serverALSA)
140 play_some_music(serverPulseAudio)
142 client.wait_for_unit("multi-user.target")
143 client.succeed(f"{mpc} -h serverALSA status")
145 # The PulseAudio-based server is configured not to accept external client connections
146 # to perform the following test:
147 client.fail(f"{mpc} -h serverPulseAudio status")