python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / nixos / tests / mpd.nix
blob52d9c7fd33a1b18116cf2f9eebf110790c6de0f5
1 import ./make-test-python.nix ({ pkgs, lib, ... }:
2   let
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";
10     };
12     defaultCfg = rec {
13       user = "mpd";
14       group = "mpd";
15       dataDir = "/var/lib/mpd";
16       musicDirectory = "${dataDir}/music";
17     };
19     defaultMpdCfg = with defaultCfg; {
20       inherit dataDir musicDirectory user group;
21       enable = true;
22     };
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" ];
29       script = ''
30         cp ${track} ${musicDirectory}
31       '';
32       serviceConfig = {
33         User = user;
34         Group = group;
35       };
36     };
38     mkServer = { mpd, musicService, }:
39       { boot.kernelModules = [ "snd-dummy" ];
40         sound.enable = true;
41         services.mpd = mpd;
42         systemd.services.musicService = musicService;
43       };
44   in {
45     name = "mpd";
46     meta = with pkgs.lib.maintainers; {
47       maintainers = [ emmanuelrosa ];
48     };
50   nodes =
51     { client =
52       { ... }: { };
54       serverALSA =
55         { ... }: lib.mkMerge [
56           (mkServer {
57             mpd = defaultMpdCfg // {
58               network.listenAddress = "any";
59               extraConfig = ''
60                 audio_output {
61                   type "alsa"
62                   name "ALSA"
63                   mixer_type "null"
64                 }
65               '';
66             };
67             musicService = with defaultMpdCfg; musicService { inherit user group musicDirectory; };
68           })
69           { networking.firewall.allowedTCPPorts = [ 6600 ]; }
70         ];
72       serverPulseAudio =
73         { ... }: lib.mkMerge [
74           (mkServer {
75             mpd = defaultMpdCfg // {
76               extraConfig = ''
77                 audio_output {
78                   type "pulse"
79                   name "The Pulse"
80                 }
81               '';
82             };
84             musicService = with defaultCfg; musicService { inherit user group musicDirectory; };
85           })
86           {
87             hardware.pulseaudio = {
88               enable = true;
89               systemWide = true;
90               tcp.enable = true;
91               tcp.anonymousClients.allowAll = true;
92             };
93             systemd.services.mpd.environment.PULSE_SERVER = "localhost";
94           }
95         ];
96     };
98   testScript = ''
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")
133   '';