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" ];
42 systemd.services.musicService = musicService;
46 meta = with pkgs.lib.maintainers; {
47 maintainers = [ emmanuelrosa ];
55 { ... }: lib.mkMerge [
57 mpd = defaultMpdCfg // {
58 network.listenAddress = "any";
67 musicService = with defaultMpdCfg; musicService { inherit user group musicDirectory; };
69 { networking.firewall.allowedTCPPorts = [ 6600 ]; }
73 { ... }: lib.mkMerge [
75 mpd = defaultMpdCfg // {
84 musicService = with defaultCfg; musicService { inherit user group musicDirectory; };
87 hardware.pulseaudio = {
91 tcp.anonymousClients.allowAll = true;
93 systemd.services.mpd.environment.PULSE_SERVER = "localhost";
99 mpc = "${pkgs.mpc-cli}/bin/mpc --wait"
101 # Connects to the given server and attempts to play a tune.
102 def play_some_music(server):
103 server.wait_for_unit("mpd.service")
104 server.succeed(f"{mpc} update")
105 _, tracks = server.execute(f"{mpc} ls")
107 for track in tracks.splitlines():
108 server.succeed(f"{mpc} add {track}")
110 _, added_tracks = server.execute(f"{mpc} playlist")
112 # Check we succeeded adding audio tracks to the playlist
113 assert len(added_tracks.splitlines()) > 0
115 server.succeed(f"{mpc} play")
117 _, output = server.execute(f"{mpc} status")
118 # Assure audio track is playing
119 assert "playing" in output
121 server.succeed(f"{mpc} stop")
124 play_some_music(serverALSA)
125 play_some_music(serverPulseAudio)
127 client.wait_for_unit("multi-user.target")
128 client.succeed(f"{mpc} -h serverALSA status")
130 # The PulseAudio-based server is configured not to accept external client connections
131 # to perform the following test:
132 client.fail(f"{mpc} -h serverPulseAudio status")