anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / tools / audio / yabridge / default.nix
blob540ffb8eaff3204885038047dae3ff5269a08340
1 { lib
2 , multiStdenv
3 , fetchFromGitHub
4 , substituteAll
5 , pkgsi686Linux
6 , dbus
7 , meson
8 , ninja
9 , pkg-config
10 , wine
11 , libxcb
12 , nix-update-script
15 let
16   # Derived from subprojects/asio.wrap
17   asio = fetchFromGitHub {
18     owner = "chriskohlhoff";
19     repo = "asio";
20     rev = "refs/tags/asio-1-28-2";
21     hash = "sha256-8Sw0LuAqZFw+dxlsTstlwz5oaz3+ZnKBuvSdLW6/DKQ=";
22   };
24   # Derived from subprojects/bitsery.wrap
25   bitsery = fetchFromGitHub {
26     owner = "fraillt";
27     repo = "bitsery";
28     rev = "refs/tags/v5.2.3";
29     hash = "sha256-rmfcIYCrANycFuLtibQ5wOPwpMVhpTMpdGsUfpR3YsM=";
30   };
32   # Derived from subprojects/clap.wrap
33   clap = fetchFromGitHub {
34     owner = "free-audio";
35     repo = "clap";
36     rev = "refs/tags/1.1.9";
37     hash = "sha256-z2P0U2NkDK1/5oDV35jn/pTXCcspuM1y2RgZyYVVO3w=";
38   };
40   # Derived from subprojects/function2.wrap
41   function2 = fetchFromGitHub {
42     owner = "Naios";
43     repo = "function2";
44     rev = "refs/tags/4.2.3";
45     hash = "sha256-+fzntJn1fRifOgJhh5yiv+sWR9pyaeeEi2c1+lqX3X8=";
46   };
48   # Derived from subprojects/ghc_filesystem.wrap
49   ghc_filesystem = fetchFromGitHub {
50     owner = "gulrak";
51     repo = "filesystem";
52     rev = "refs/tags/v1.5.14";
53     hash = "sha256-XZ0IxyNIAs2tegktOGQevkLPbWHam/AOFT+M6wAWPFg=";
54   };
56   # Derived from subprojects/tomlplusplus.wrap
57   tomlplusplus = fetchFromGitHub {
58     owner = "marzer";
59     repo = "tomlplusplus";
60     rev = "refs/tags/v3.4.0";
61     hash = "sha256-h5tbO0Rv2tZezY58yUbyRVpsfRjY3i+5TPkkxr6La8M=";
62   };
64   # Derived from vst3.wrap
65   vst3 = fetchFromGitHub {
66     owner = "robbert-vdh";
67     repo = "vst3sdk";
68     rev = "refs/tags/v3.7.7_build_19-patched";
69     fetchSubmodules = true;
70     hash = "sha256-LsPHPoAL21XOKmF1Wl/tvLJGzjaCLjaDAcUtDvXdXSU=";
71   };
73 multiStdenv.mkDerivation (finalAttrs: {
74   pname = "yabridge";
75   version = "5.1.1";
77   # NOTE: Also update yabridgectl's cargoHash when this is updated
78   src = fetchFromGitHub {
79     owner = "robbert-vdh";
80     repo = "yabridge";
81     rev = "refs/tags/${finalAttrs.version}";
82     hash = "sha256-4eA3vQFklIWkhtbd3Nw39bnJT6gPcni79ZyQVqU4+GQ=";
83   };
85   # Unpack subproject sources
86   postUnpack = ''
87     (
88       cd "$sourceRoot/subprojects"
89       cp -R --no-preserve=mode,ownership ${asio} asio
90       cp -R --no-preserve=mode,ownership ${bitsery} bitsery
91       cp -R --no-preserve=mode,ownership ${clap} clap
92       cp -R --no-preserve=mode,ownership ${function2} function2
93       cp -R --no-preserve=mode,ownership ${ghc_filesystem} ghc_filesystem
94       cp -R --no-preserve=mode,ownership ${tomlplusplus} tomlplusplus
95       cp -R --no-preserve=mode,ownership ${vst3} vst3
96     )
97   '';
99   patches = [
100     # Hard code bitbridge & runtime dependencies
101     (substituteAll {
102       src = ./hardcode-dependencies.patch;
103       libdbus = dbus.lib;
104       libxcb32 = pkgsi686Linux.xorg.libxcb;
105       inherit wine;
106     })
108     # Patch the chainloader to search for libyabridge through NIX_PROFILES
109     ./libyabridge-from-nix-profiles.patch
110   ];
112   postPatch = ''
113     patchShebangs .
114     (
115       cd subprojects
116       cp packagefiles/asio/* asio
117       cp packagefiles/bitsery/* bitsery
118       cp packagefiles/clap/* clap
119       cp packagefiles/function2/* function2
120       cp packagefiles/ghc_filesystem/* ghc_filesystem
121     )
122   '';
124   nativeBuildInputs = [
125     meson
126     ninja
127     pkg-config
128     wine
129   ];
131   buildInputs = [
132     libxcb
133     dbus
134   ];
136   mesonFlags = [
137     "--cross-file" "cross-wine.conf"
138     "-Dbitbridge=true"
140     # Requires CMake and is unnecessary
141     "-Dtomlplusplus:generate_cmake_config=false"
142   ];
144   installPhase = ''
145     runHook preInstall
146     mkdir -p "$out/bin" "$out/lib"
147     cp yabridge-host{,-32}.exe{,.so} "$out/bin"
148     cp libyabridge{,-chainloader}-{vst2,vst3,clap}.so "$out/lib"
149     runHook postInstall
150   '';
152   # Hard code wine path in wrapper scripts generated by winegcc
153   postFixup = ''
154     substituteInPlace "$out/bin/yabridge-host-32.exe" \
155       --replace 'WINELOADER="wine"' 'WINELOADER="${wine}/bin/wine"'
157     substituteInPlace "$out/bin/yabridge-host.exe" \
158       --replace 'WINELOADER="wine"' 'WINELOADER="${wine}/bin/wine64"'
159   '';
161   passthru.updateScript = nix-update-script { };
163   meta = with lib; {
164     description = "Modern and transparent way to use Windows VST2 and VST3 plugins on Linux";
165     homepage = "https://github.com/robbert-vdh/yabridge";
166     changelog = "https://github.com/robbert-vdh/yabridge/blob/${finalAttrs.version}/CHANGELOG.md";
167     license = licenses.gpl3Plus;
168     maintainers = with maintainers; [ kira-bruneau ];
169     platforms = [ "x86_64-linux" ];
170   };