summaryrefslogtreecommitdiff
path: root/pkgs/by-name/fi/fire/package.nix
blob: f76222308dbd650a2d78fb5145c0f5b448c621c3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{
  stdenv,
  lib,
  fetchurl,
  fetchFromGitHub,
  runCommand,
  unstableGitUpdater,
  catch2_3,
  cmake,
  fontconfig,
  pkg-config,
  libX11,
  libXrandr,
  libXinerama,
  libXext,
  libXcursor,
  freetype,
  alsa-lib,

  # Only able to test this myself in Linux
  withStandalone ? stdenv.hostPlatform.isLinux,
}:

let
  # Required version, base URL and expected location specified in cmake/CPM.cmake
  cpmDownloadVersion = "0.40.2";
  cpmSrc = fetchurl {
    url = "https://github.com/cpm-cmake/CPM.cmake/releases/download/v${cpmDownloadVersion}/CPM.cmake";
    hash = "sha256-yM3DLAOBZTjOInge1ylk3IZLKjSjENO3EEgSpcotg10=";
  };
  cpmSourceCache = runCommand "cpm-source-cache" { } ''
    mkdir -p $out/cpm
    ln -s ${cpmSrc} $out/cpm/CPM_${cpmDownloadVersion}.cmake
  '';

  pathMappings = [
    {
      from = "LV2";
      to = "${placeholder "out"}/${
        if stdenv.hostPlatform.isDarwin then "Library/Audio/Plug-Ins/LV2" else "lib/lv2"
      }";
    }
    {
      from = "VST3";
      to = "${placeholder "out"}/${
        if stdenv.hostPlatform.isDarwin then "Library/Audio/Plug-Ins/VST3" else "lib/vst3"
      }";
    }
    # this one's a guess, don't know where ppl have agreed to put them yet
    {
      from = "CLAP";
      to = "${placeholder "out"}/${
        if stdenv.hostPlatform.isDarwin then "Library/Audio/Plug-Ins/CLAP" else "lib/clap"
      }";
    }
  ]
  ++ lib.optionals withStandalone [
    {
      from = "Standalone";
      to = "${placeholder "out"}/bin";
    }
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [
    # Audio Unit is a macOS-specific thing
    {
      from = "AU";
      to = "${placeholder "out"}/Library/Audio/Plug-Ins/Components";
    }
  ];

  x11Libs = [
    libX11
    libXrandr
    libXinerama
    libXext
    libXcursor
  ];
in
stdenv.mkDerivation (finalAttrs: {
  pname = "fire";
  version = "1.0.2-unstable-2025-07-05";

  src = fetchFromGitHub {
    owner = "jerryuhoo";
    repo = "Fire";
    rev = "a0553c6fcced4919871771da3add390e931e29de";
    fetchSubmodules = true;
    hash = "sha256-bHqWP3EZQg42OBi44Z1RvkIB2Ou0dDxgBLcidgxaMU8=";
  };

  postPatch =
    let
      formatsListing = lib.strings.concatMapStringsSep " " (entry: entry.from) pathMappings;
    in
    ''
      # Allow all the formats we can handle
      # Set LV2URI again for LV2 build
      # Disable automatic copying of built plugins during buildPhase, it defaults
      # into user home and we want to have building & installing separated.
      substituteInPlace CMakeLists.txt \
        --replace-fail 'set(FORMATS' 'set(FORMATS ${formatsListing}) #' \
        --replace-fail 'BUNDLE_ID "''${BUNDLE_ID}"' 'BUNDLE_ID "''${BUNDLE_ID}" LV2URI "https://www.bluewingsmusic.com/Fire/"' \
        --replace-fail 'COPY_PLUGIN_AFTER_BUILD TRUE' 'COPY_PLUGIN_AFTER_BUILD FALSE'
    ''
    + lib.optionalString stdenv.hostPlatform.isLinux ''
      # Remove hardcoded LTO flags: needs extra setup on Linux
      substituteInPlace CMakeLists.txt \
        --replace-fail 'juce::juce_recommended_lto_flags' '# Not forcing LTO'
    ''
    + lib.optionalString (!finalAttrs.finalPackage.doCheck) ''
      substituteInPlace CMakeLists.txt \
        --replace-fail 'include(Tests)' '# Not building tests' \
        --replace-fail 'include(Benchmarks)' '# Not building benchmark test'
    '';

  strictDeps = true;

  nativeBuildInputs = [
    cmake
    pkg-config
  ];

  buildInputs = [
    catch2_3
    fontconfig
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux (
    x11Libs
    ++ [
      freetype
      alsa-lib
    ]
  );

  cmakeFlags = [
    (lib.cmakeFeature "CPM_SOURCE_CACHE" "${cpmSourceCache}")
    (lib.cmakeBool "CPM_LOCAL_PACKAGES_ONLY" true)
    (lib.cmakeFeature "Catch2_SOURCE_DIR" "${catch2_3.src}")
  ];

  installPhase = ''
    runHook preInstall

  ''
  + lib.strings.concatMapStringsSep "\n" (entry: ''
    mkdir -p ${entry.to}
    # Exact path of the build artefact depends on used CMAKE_BUILD_TYPE
    cp -r -t ${entry.to} Fire_artefacts/${finalAttrs.cmakeBuildType or "Release"}/${entry.from}/*
  '') pathMappings
  + ''

    runHook postInstall
  '';

  doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;

  # Standalone dlopen's X11 libraries
  postFixup = lib.strings.optionalString (withStandalone && stdenv.hostPlatform.isLinux) ''
    patchelf --add-rpath ${lib.makeLibraryPath x11Libs} $out/bin/Fire
  '';

  passthru.updateScript = unstableGitUpdater { tagPrefix = "v"; };

  meta = {
    description = "Multi-band distortion plugin by Wings";
    homepage = "https://www.bluewingsmusic.com/Fire";
    license = lib.licenses.agpl3Only; # Not clarified if Only or Plus
    platforms = lib.platforms.unix;
    maintainers = with lib.maintainers; [ OPNA2608 ];
  }
  // lib.optionalAttrs withStandalone {
    mainProgram = "Fire";
  };
})