linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / tools / audio / beets / default.nix
blobef47578ac578d132992f33c9a70b7da97880bba4
1 { stdenv, lib, fetchFromGitHub, writeScript, glibcLocales, diffPlugins, substituteAll
2 , pythonPackages, imagemagick, gobject-introspection, gst_all_1
3 , runtimeShell, unstableGitUpdater
5 # external plugins package set
6 , beetsExternalPlugins
8 , enableAbsubmit         ? lib.elem stdenv.hostPlatform.system essentia-extractor.meta.platforms, essentia-extractor
9 , enableAcousticbrainz   ? true
10 , enableAcoustid         ? true
11 , enableAura             ? true
12 , enableBadfiles         ? true, flac, mp3val
13 , enableBeatport         ? true
14 , enableBpsync           ? true
15 , enableConvert          ? true, ffmpeg
16 , enableDeezer           ? true
17 , enableDiscogs          ? true
18 , enableEmbyupdate       ? true
19 , enableFetchart         ? true
20 , enableKeyfinder        ? true, keyfinder-cli
21 , enableKodiupdate       ? true
22 , enableLastfm           ? true
23 , enableLoadext          ? true
24 , enableLyrics           ? true
25 , enableMpd              ? true
26 , enablePlaylist         ? true
27 , enableReplaygain       ? true
28 , enableSonosUpdate      ? true
29 , enableSubsonicplaylist ? true
30 , enableSubsonicupdate   ? true
31 , enableThumbnails       ? true
32 , enableWeb              ? true
34 # External plugins
35 , enableAlternatives     ? false
36 , enableCopyArtifacts    ? false
37 , enableExtraFiles       ? false
39 , bashInteractive, bash-completion
42 assert enableBpsync      -> enableBeatport;
44 let
45   optionalPlugins = {
46     absubmit = enableAbsubmit;
47     acousticbrainz = enableAcousticbrainz;
48     aura = enableAura;
49     badfiles = enableBadfiles;
50     beatport = enableBeatport;
51     bpsync = enableBpsync;
52     chroma = enableAcoustid;
53     convert = enableConvert;
54     deezer = enableDeezer;
55     discogs = enableDiscogs;
56     embyupdate = enableEmbyupdate;
57     fetchart = enableFetchart;
58     keyfinder = enableKeyfinder;
59     kodiupdate = enableKodiupdate;
60     lastgenre = enableLastfm;
61     lastimport = enableLastfm;
62     loadext = enableLoadext;
63     lyrics = enableLyrics;
64     mpdstats = enableMpd;
65     mpdupdate = enableMpd;
66     playlist = enablePlaylist;
67     replaygain = enableReplaygain;
68     sonosupdate = enableSonosUpdate;
69     subsonicplaylist = enableSubsonicplaylist;
70     subsonicupdate = enableSubsonicupdate;
71     thumbnails = enableThumbnails;
72     web = enableWeb;
73   };
75   pluginsWithoutDeps = [
76     "bareasc" "bench" "bpd" "bpm" "bucket" "duplicates" "edit" "embedart"
77     "export" "filefilter" "fish" "freedesktop" "fromfilename" "ftintitle" "fuzzy"
78     "hook" "ihate" "importadded" "importfeeds" "info" "inline" "ipfs"
79     "mbcollection" "mbsubmit" "mbsync" "metasync" "missing" "parentwork" "permissions" "play"
80     "plexupdate" "random" "rewrite" "scrub" "smartplaylist" "spotify" "the"
81     "types" "unimported" "zero"
82   ];
84   enabledOptionalPlugins = lib.attrNames (lib.filterAttrs (_: lib.id) optionalPlugins);
86   allPlugins = pluginsWithoutDeps ++ lib.attrNames optionalPlugins;
87   allEnabledPlugins = pluginsWithoutDeps ++ enabledOptionalPlugins;
89   testShell = "${bashInteractive}/bin/bash --norc";
90   completion = "${bash-completion}/share/bash-completion/bash_completion";
92   # This is a stripped down beets for testing of the external plugins.
93   externalTestArgs.beets = (lib.beets.override {
94     enableAlternatives = false;
95     enableCopyArtifacts = false;
96     enableExtraFiles = false;
97   }).overrideAttrs (lib.const {
98     doInstallCheck = false;
99   });
101 in pythonPackages.buildPythonApplication rec {
102   pname = "beets";
103   # While there is a stable version, 1.4.9, it is more than 1000 commits behind
104   # master and lacks many bug fixes and improvements[1]. Also important,
105   # unstable does not require bs1770gain[2].
106   # [1]: https://discourse.beets.io/t/forming-a-beets-core-team/639
107   # [2]: https://github.com/NixOS/nixpkgs/pull/90504
108   version = "unstable-2021-03-24";
110   src = fetchFromGitHub {
111     owner = "beetbox";
112     repo = "beets";
113     rev = "854b4ab48324afe8884fcd11fa47bd6258d2f4f7";
114     sha256 = "sha256-y5EWVNF4bd9fNvU6VkucMpenyFZuqdPkrqQDgG9ZPJY=";
115   };
117   propagatedBuildInputs = [
118     pythonPackages.six
119     pythonPackages.enum34
120     pythonPackages.jellyfish
121     pythonPackages.munkres
122     pythonPackages.musicbrainzngs
123     pythonPackages.mutagen
124     pythonPackages.pyyaml
125     pythonPackages.unidecode
126     pythonPackages.gst-python
127     pythonPackages.pygobject3
128     pythonPackages.reflink
129     pythonPackages.confuse
130     pythonPackages.mediafile
131     gobject-introspection
132   ] ++ lib.optional enableAbsubmit         essentia-extractor
133     ++ lib.optional enableAcoustid         pythonPackages.pyacoustid
134     ++ lib.optional enableBeatport         pythonPackages.requests_oauthlib
135     ++ lib.optional enableConvert          ffmpeg
136     ++ lib.optional enableDiscogs          pythonPackages.discogs_client
137     ++ lib.optional (enableFetchart
138                   || enableDeezer
139                   || enableEmbyupdate
140                   || enableKodiupdate
141                   || enableLoadext
142                   || enablePlaylist
143                   || enableSubsonicplaylist
144                   || enableSubsonicupdate
145                   || enableAcousticbrainz) pythonPackages.requests
146     ++ lib.optional enableKeyfinder        keyfinder-cli
147     ++ lib.optional enableLastfm           pythonPackages.pylast
148     ++ lib.optional enableLyrics           pythonPackages.beautifulsoup4
149     ++ lib.optional enableMpd              pythonPackages.mpd2
150     ++ lib.optional enableSonosUpdate      pythonPackages.soco
151     ++ lib.optional enableThumbnails       pythonPackages.pyxdg
152     ++ lib.optional (enableAura
153                   || enableWeb)            pythonPackages.flask
154     ++ lib.optional enableAlternatives     beetsExternalPlugins.alternatives
155     ++ lib.optional enableCopyArtifacts    beetsExternalPlugins.copyartifacts
156     ++ lib.optional enableExtraFiles       beetsExternalPlugins.extrafiles
157   ;
159   buildInputs = [
160     imagemagick
161   ] ++ (with gst_all_1; [
162     gst-plugins-base
163     gst-plugins-good
164     gst-plugins-ugly
165   ]);
167   checkInputs = with pythonPackages; [
168     beautifulsoup4
169     mock
170     nose
171     rarfile
172     responses
173     # Although considered as plugin dependencies, they are needed for the
174     # tests, for disabling them via an override makes the build fail. see:
175     # https://github.com/beetbox/beets/blob/v1.4.9/setup.py
176     pylast
177     mpd2
178     discogs_client
179     pyxdg
180   ];
182   patches = [
183     # Bash completion fix for Nix
184     ./bash-completion-always-print.patch
185     # From some reason upstream assumes the program 'keyfinder-cli' is located
186     # in the path as `KeyFinder`
187     ./keyfinder-default-bin.patch
188   ]
189     # We need to force ffmpeg as the default, since we do not package
190     # bs1770gain, and set the absolute path there, to avoid impurities.
191     ++ lib.optional enableReplaygain (substituteAll {
192       src = ./replaygain-default-ffmpeg.patch;
193       ffmpeg = lib.getBin ffmpeg;
194     })
195     # Put absolute Nix paths in place
196     ++ lib.optional enableConvert (substituteAll {
197       src = ./convert-plugin-ffmpeg-path.patch;
198       ffmpeg = lib.getBin ffmpeg;
199     })
200     ++ lib.optional enableBadfiles (substituteAll {
201       src = ./badfiles-plugin-nix-paths.patch;
202       inherit mp3val flac;
203     })
204   ;
206   # Disable failing tests
207   postPatch = ''
208     sed -i -e '/assertIn.*item.*path/d' test/test_info.py
209     echo echo completion tests passed > test/rsrc/test_completion.sh
211     sed -i -e 's/len(mf.images)/0/' test/test_zero.py
213     # Google Play Music was discontinued
214     rm -r beetsplug/gmusic.py
215   '';
217   postInstall = ''
218     mkdir -p $out/share/zsh/site-functions
219     cp extra/_beet $out/share/zsh/site-functions/
220   '';
222   doCheck = true;
224   preCheck = ''
225     find beetsplug -mindepth 1 \
226       \! -path 'beetsplug/__init__.py' -a \
227       \( -name '*.py' -o -path 'beetsplug/*/__init__.py' \) -print \
228       | sed -n -re 's|^beetsplug/([^/.]+).*|\1|p' \
229       | sort -u > plugins_available
231      ${diffPlugins allPlugins "plugins_available"}
232   '';
234   checkPhase = ''
235     runHook preCheck
237     LANG=en_US.UTF-8 \
238     LOCALE_ARCHIVE=${assert stdenv.isLinux; glibcLocales}/lib/locale/locale-archive \
239     BEETS_TEST_SHELL="${testShell}" \
240     BASH_COMPLETION_SCRIPT="${completion}" \
241     HOME="$(mktemp -d)" nosetests -v
243     runHook postCheck
244   '';
246   doInstallCheck = true;
248   installCheckPhase = ''
249     runHook preInstallCheck
251     tmphome="$(mktemp -d)"
253     EDITOR="${writeScript "beetconfig.sh" ''
254       #!${runtimeShell}
255       cat > "$1" <<CFG
256       plugins: ${lib.concatStringsSep " " allEnabledPlugins}
257       CFG
258     ''}" HOME="$tmphome" "$out/bin/beet" config -e
259     EDITOR=true HOME="$tmphome" "$out/bin/beet" config -e
261     runHook postInstallCheck
262   '';
264   makeWrapperArgs = [ "--set GI_TYPELIB_PATH \"$GI_TYPELIB_PATH\"" "--set GST_PLUGIN_SYSTEM_PATH_1_0 \"$GST_PLUGIN_SYSTEM_PATH_1_0\"" ];
266   passthru = {
267     # FIXME: remove in favor of pkgs.beetsExternalPlugins
268     externalPlugins = beetsExternalPlugins;
269     updateScript = unstableGitUpdater { url = "https://github.com/beetbox/beets"; };
270   };
272   meta = with lib; {
273     description = "Music tagger and library organizer";
274     homepage = "http://beets.io";
275     license = licenses.mit;
276     maintainers = with maintainers; [ aszlig doronbehar lovesegfault pjones ];
277     platforms = platforms.linux;
278   };