Building portmidi for nixpkgs Darwin: cmake woes

I’m trying to build portmidi on Darwin (MacoS catalina, if that makes a difference) and running into problems with error messages from cmake that I don’t understand. Anyone who’s been down this path before?

Here’s my derivation, which overrides the nixpkgs 20.09 one:

$ cat portmidi.nix
with import <nixpkgs> {};
let pm = portmidi.overrideAttrs(o:
      let frameworks = with darwin.apple_sdk.frameworks; [
            AudioUnit
            AudioToolbox
            CoreAudio CoreServices Carbon CoreMIDI
          ];
      in {
        cmakeFlags = [
          # "-DCMAKE_OSX_SYSROOT=macos"
          # "-DNATIVE_ARCH_ACTUAL=x86_64"
          #   # "-DCMAKE_SYSTEM_PROCESSOR=i386"
          # "-DCMAKE_OSX_ARCHITECTURES=i386"
          # "-DCMAKE_OSX_ARCHITECTURES=x86_64"
          # "-DCMAKE_SYSTEM_PROCESSOR=x86_64"
          # "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11"
        ] ++ o.cmakeFlags;
        nativeBuildInputs = [ coreutils cmake ];
        propagatedBuildInputs = stdenv.lib.optionals stdenv.isDarwin frameworks;
        meta = o.meta // { platforms = stdenv.lib.platforms.all; };
      });
in pm.override {alsaLib = null; }

When I build this I get

$ nix-build portmidi.nix
[...]
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/share/doc/portmidi -DCMAKE_INSTALL_INFODIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/include -DCMAKE_INSTALL_SBINDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/qmxmk9l5ldy8zp50qaxmyv2r1sdfw7az-cctools-binutils-darwin-927.0.2/bin/strip -DCMAKE_RANLIB=/nix/store/qmxmk9l5ldy8zp50qaxmyv2r1sdfw7az-cctools-binutils-darwin-927.0.2/bin/ranlib -DCMAKE_AR=/nix/store/qmxmk9l5ldy8zp50qaxmyv2r1sdfw7az-cctools-binutils-darwin-927.0.2/bin/ar -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=/nix/store/33ij0729p0g7rrfgrgwih1p77vk7fxq4-portmidi-217 -DPORTMIDI_ENABLE_JAVA=0 -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=Release -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=Release
CMake Error at /nix/store/azf66mnhbd23dvkfp7j2njwssv7vl3v6-cmake-3.18.2/share/cmake-3.18/Modules/Platform/Darwin-Initialize.cmake:234 (string):
  string sub-command REPLACE requires at least four arguments.
Call Stack (most recent call first):
  /nix/store/azf66mnhbd23dvkfp7j2njwssv7vl3v6-cmake-3.18.2/share/cmake-3.18/Modules/Platform/Darwin-Initialize.cmake:278 (_apple_resolve_multi_arch_sysroots)
  /nix/store/azf66mnhbd23dvkfp7j2njwssv7vl3v6-cmake-3.18.2/share/cmake-3.18/Modules/CMakeSystemSpecificInitialize.cmake:21 (include)
  CMakeLists.txt:41 (PROJECT)

The “REPLACE requires at least four arguments” error seems to be caused by the CMAKE_OSX_SYSROOT variable being empty - but as far as I understand it (not very far) it’s supposed to be empty?

You can see some of the things I’ve tried without success in the form of the commented-out cmakeFlags in the derivation.

(For the avoidance of doubt, I am the same person as telent but this is my work machine and doesn’t have my personal github credentials available)

I think this is simply an issue with their cmake scripts since the project is so old - note that they also try to build for powerpc on macOS, haha. I’ve seen other derivations set the sysroot to a dummy dir such as /var/empty. If you do that here the cmake seems to proceed past that error.