Can you define an array of anonymous derivations for a buildEnv?

I’m trying to define in my config.nix a myApps derivation like so:

myApps = pkgs.callPackage ./custom/apps {};

custom/apps/default.nix has this:

{
  fetchurl,
  pkgs,
  stdenv,
  undmg,
  unzip,
}:
with stdenv;

let
  installers = rec {
    macOS = rec {
      app =
        { name,
          appname ? name,
          version,
          src,
          description,
          homepage,
          postInstall ? "",
          sourceRoot ? ".",
          ...
        }:
        stdenv.mkDerivation {
          name = "${name}-${version}";
          version = "${version}";
          src = src;
          buildInputs = [ undmg unzip ];
          sourceRoot = sourceRoot;
          phases = [ "unpackPhase" "installPhase" ];
          installPhase = ''
            mkdir -p "$out/Applications/${appname}.app"
            cp -pR * "$out/Applications/${appname}.app"
          '' + postInstall;
          meta = with stdenv.lib; {
            description = description;
            homepage = homepage;
            maintainers = [ "ldeck <ldeck@example.com>" ];
            platforms = stdenv.lib.platforms.darwin;
            priority = -100;
          };
        };
     };
  };

  macosApps = with installers; [
    macOS.app rec {...}
    ...
  ];

in
pkgs.buildEnv {
  name = "my-apps";
  paths = [] ++ stdenv.lib.optionals stdenv.isDarwin macosApps;
  pathsToLink = [ "/Applications" ];
}

This fails with this kind of exception:

 % nix-env -iA nixpkgs.myApps --show-trace
installing 'my-apps'
trace: Warning: `stdenv.lib` is deprecated and will be removed in the next release. Please use `lib` instead. For more information see https://github.com/NixOS/nixpkgs/issues/108938
error: while evaluating the attribute 'passAsFile' of the derivation 'my-apps' at /nix/store/39lgkp36x5qqpbi6rjcwg85lrc791ymc-nixpkgs-21.05pre287067.0d337eb6b77/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:201:11:
while evaluating the attribute 'passAsFile' at /nix/store/39lgkp36x5qqpbi6rjcwg85lrc791ymc-nixpkgs-21.05pre287067.0d337eb6b77/nixpkgs/pkgs/build-support/buildenv/default.nix:77:5:
cannot convert a function to JSON

Which seems to indicate that anonymous functions aren’t expected (can’t be converted to a named JSON attribute). This is confirmed by firstly assigning an anonymous app to a named derivation outside the array and then using the name in the array.

Is there a way to satisfy the build-support for this (and keeping the derivation anonymous) by using it’s name attribute?

i.e.,

macOSApps = with installers; [
  macos.app rec {
      name = "Signal";
      version = "1.39.4";
      sourceRoot = "${name}.app";
      src = fetchurl {
        url = "https://updates.signal.org/desktop/signal-desktop-mac-${version}.dmg";
        sha256 = "0di73h6hf8py18l1xgzh35lq1hpvm17lnavb9pan9w5wp29x35w6";
      };
      description = "Cross-platform instant messaging application focusing on security";
      homepage = "https://signal.org/";
      appcast = "https://github.com/signalapp/Signal-Desktop/releases.atom";
    }
...
]

I think what you actually want is

  macosApps = with installers; [
    (macOS.app rec {...})
    ...
  ];

without brackets it will be recoginized as two elements: one is macOS.app, which is a function that cannot be converted to JSON, another one is a set which is intended to be the argument passed to macOS.app.