|
| 1 | +{ |
| 2 | + stdenv, |
| 3 | + fetchFromGitHub, |
| 4 | + fetchpatch, |
| 5 | + lib, |
| 6 | + cmake, |
| 7 | + pkg-config, |
| 8 | + writableTmpDirAsHomeHook, |
| 9 | + nix-update-script, |
| 10 | + juce, |
| 11 | + libx11, |
| 12 | + libxrandr, |
| 13 | + libxinerama, |
| 14 | + libxext, |
| 15 | + libxcursor, |
| 16 | + freetype, |
| 17 | + fontconfig, |
| 18 | + alsa-lib, |
| 19 | + |
| 20 | + buildVST3 ? true, |
| 21 | + buildLV2 ? true, |
| 22 | + buildCLAP ? true, |
| 23 | +}: |
| 24 | + |
| 25 | +let |
| 26 | + juce-clap-extensions = fetchFromGitHub { |
| 27 | + owner = "free-audio"; |
| 28 | + repo = "clap-juce-extensions"; |
| 29 | + rev = "02f91b7988298f7f1f05c706da16e1d9da852a87"; |
| 30 | + hash = "sha256-cPi+prl+jLq/KvjZ5M2MxxZVLSKCiJB9SQHK8psW2OU="; |
| 31 | + fetchSubmodules = true; |
| 32 | + }; |
| 33 | + |
| 34 | + chowdsp_utils = fetchFromGitHub { |
| 35 | + owner = "Chowdhury-DSP"; |
| 36 | + repo = "chowdsp_utils"; |
| 37 | + rev = "ffc70ba399f9afaeefb996eb14e55a1d487270b8"; # LIB_CHOWDSP_UTILS_TAG from CMakeLists.txt |
| 38 | + hash = "sha256-rKjrhb+w/lW9k3Dg5jWM2eJRa0fPDF8SNVrCTFrRMoM="; |
| 39 | + }; |
| 40 | + |
| 41 | + # src/dsp/guitarml-byod/CMakeLists.txt |
| 42 | + rtneural = fetchFromGitHub { |
| 43 | + owner = "jatinchowdhury18"; |
| 44 | + repo = "RTNeural"; |
| 45 | + rev = "04cb333bc4b174760958a77c7ce076eae38fe8e4"; # LIB_RTNEURAL_TAG |
| 46 | + hash = "sha256-kTHYEpoXPYNKEs7rHeSwBHVQnOQKhKnST+UWa++uCsc="; |
| 47 | + fetchSubmodules = true; |
| 48 | + |
| 49 | + postFetch = '' |
| 50 | + # note: if rtneural is updated, this won't be needed anymore |
| 51 | + substituteInPlace $out/CMakeLists.txt \ |
| 52 | + --replace-fail "include(cmake/CPM.cmake)" "# No tests" \ |
| 53 | +
|
| 54 | + # Required for CMake 4 |
| 55 | + substituteInPlace $out/CMakeLists.txt \ |
| 56 | + --replace-fail \ |
| 57 | + "cmake_minimum_required(VERSION 3.5)" \ |
| 58 | + "cmake_minimum_required(VERSION 4.0)" |
| 59 | + ''; |
| 60 | + }; |
| 61 | + |
| 62 | + # src/dsp/guitarml-byod/CMakeLists.txt |
| 63 | + math_approx = fetchFromGitHub { |
| 64 | + owner = "Chowdhury-DSP"; |
| 65 | + repo = "math_approx"; |
| 66 | + rev = "0c68d4d17242d707ba07fa7f1901692b7ed72d58"; # LIB_CHOWDSP_MATH_APPROX_TAG |
| 67 | + hash = "sha256-t6UrsZGRJjJVp+aGkwBa++Skj9xkdQuZKAxRrTkfM0E="; |
| 68 | + }; |
| 69 | + |
| 70 | + # src/dsp/guitarml-byod/CMakeLists.txt |
| 71 | + ea_variant = fetchFromGitHub { |
| 72 | + owner = "eyalamirmusic"; |
| 73 | + repo = "Variant"; |
| 74 | + rev = "3fce49cfca50ba3b05026d41ffc4911a8e653378"; # LIB_VARIANT_TAG |
| 75 | + hash = "sha256-2zzam7rKY6zoT2jFqDtr4pwOCAWTu0GTxUqVGxVHbQQ="; |
| 76 | + }; |
| 77 | + |
| 78 | + formats = lib.concatStringsSep " " [ |
| 79 | + (lib.optionalString buildVST3 "VST3") |
| 80 | + (lib.optionalString buildLV2 "LV2") |
| 81 | + ]; |
| 82 | +in |
| 83 | +stdenv.mkDerivation (finalAttrs: { |
| 84 | + pname = "jc303"; |
| 85 | + version = "0.12.3"; |
| 86 | + |
| 87 | + src = fetchFromGitHub { |
| 88 | + owner = "midilab"; |
| 89 | + repo = "jc303"; |
| 90 | + tag = "v${finalAttrs.version}"; |
| 91 | + hash = "sha256-5OA7ir8loT0Lx05guwuZNCW9J9I3TA5+A9JZ9E7oWXA="; |
| 92 | + }; |
| 93 | + |
| 94 | + patches = [ |
| 95 | + # `BUILD_CLAP` cmake flag |
| 96 | + (fetchpatch { |
| 97 | + url = "https://github.com/midilab/jc303/commit/837d3fc5cf4e993375403a45d7e23df1b4e3cf7f.diff"; |
| 98 | + hash = "sha256-WvLIcSHrLiXj1VEV+IxS05YSWEq7oz57qIbNsqRySaY="; |
| 99 | + }) |
| 100 | + ]; |
| 101 | + |
| 102 | + postPatch = '' |
| 103 | + substituteInPlace CMakeLists.txt \ |
| 104 | + --replace-fail "set(PLUGIN_FORMATS AU VST3 LV2)" "set(PLUGIN_FORMATS ${formats})" \ |
| 105 | + ''; |
| 106 | + |
| 107 | + nativeBuildInputs = [ |
| 108 | + cmake |
| 109 | + pkg-config |
| 110 | + writableTmpDirAsHomeHook |
| 111 | + ]; |
| 112 | + |
| 113 | + buildInputs = [ |
| 114 | + libx11 |
| 115 | + libxrandr |
| 116 | + libxext |
| 117 | + libxcursor |
| 118 | + libxinerama |
| 119 | + freetype |
| 120 | + fontconfig |
| 121 | + alsa-lib |
| 122 | + ]; |
| 123 | + |
| 124 | + cmakeFlags = [ |
| 125 | + # CMakeLists.txt |
| 126 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_JUCE" "${juce.src}") |
| 127 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_JUCE-CLAP-EXTENSIONS" "${juce-clap-extensions}") |
| 128 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CHOWDSP_UTILS" "${chowdsp_utils}") |
| 129 | + |
| 130 | + # src/dsp/guitarml-byod/CMakeLists.txt |
| 131 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_RTNEURAL" "${rtneural}") |
| 132 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_MATH_APPROX" "${math_approx}") |
| 133 | + (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_EA_VARIANT" "${ea_variant}") |
| 134 | + |
| 135 | + (lib.cmakeBool "BUILD_CLAP" buildCLAP) |
| 136 | + ]; |
| 137 | + |
| 138 | + # Fontconfig error: Cannot load default config file: No such file: (null) |
| 139 | + env.FONTCONFIG_FILE = "${fontconfig.out}/etc/fonts/fonts.conf"; |
| 140 | + |
| 141 | + enableParallelBuilding = true; |
| 142 | + |
| 143 | + env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isLinux (toString [ |
| 144 | + # juce, compiled in this build as part of a Git submodule, uses `-flto` as |
| 145 | + # a Link Time Optimization flag, and instructs the plugin compiled here to |
| 146 | + # use this flag to. This breaks the build for us. Using _fat_ LTO allows |
| 147 | + # successful linking while still providing LTO benefits. If our build of |
| 148 | + # `juce` was used as a dependency, we could have patched that `-flto` line |
| 149 | + # in our juce's source, but that is not possible because it is used as a |
| 150 | + # Git Submodule. |
| 151 | + "-ffat-lto-objects" |
| 152 | + ]); |
| 153 | + |
| 154 | + installPhase = '' |
| 155 | + runHook preInstall |
| 156 | +
|
| 157 | + pushd JC303_artefacts/Release |
| 158 | + ${lib.optionalString buildVST3 '' |
| 159 | + mkdir -p $out/lib/vst3 |
| 160 | + cp -r VST3/JC303.vst3 $out/lib/vst3 |
| 161 | + ''} |
| 162 | +
|
| 163 | + ${lib.optionalString buildCLAP '' |
| 164 | + mkdir -p $out/lib/clap |
| 165 | + cp -r CLAP/JC303.clap $out/lib/clap |
| 166 | + ''} |
| 167 | +
|
| 168 | + ${lib.optionalString buildLV2 '' |
| 169 | + mkdir -p $out/lib/lv2 |
| 170 | + cp -r LV2/JC303.lv2 $out/lib/lv2 |
| 171 | + ''} |
| 172 | + popd |
| 173 | +
|
| 174 | + runHook postInstall |
| 175 | + ''; |
| 176 | + |
| 177 | + passthru.updateScript = nix-update-script { }; |
| 178 | + |
| 179 | + meta = { |
| 180 | + description = "Roland TB-303 clone plugin"; |
| 181 | + homepage = "https://github.com/midilab/jc303"; |
| 182 | + platforms = lib.platforms.linux; |
| 183 | + license = lib.licenses.gpl3Plus; |
| 184 | + maintainers = [ lib.maintainers.mrtnvgr ]; |
| 185 | + }; |
| 186 | +}) |
0 commit comments