How to write a electron app wrap function?

Nix newbie here, first time posting.
How can I write a lambda which invoke symlinkJoin function and create a package ?
I use hyprland, my scenario is I have multiple electron apps, so I have to wrap every single of them to enable wayland support ( like fcitx5 support ). That brings a lot of duplicated code like:

environment.systemPackage = with pkgs; [
    (symlinkJoin {
      name = "obsidian";
      paths = [ obsidian ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = ''
        wrapProgram $out/bin/obsidian \
          --add-flags "--ozone-platform-hint=auto" \
          --add-flags "--enable-webrtc-pipewire-capturer" \
          --add-flags "--enable-features=WaylandWindowDecorations" \
          --add-flags "--enable-wayland-ime"
      '';
    })
]

So I want to write a lambda which can invoke symlinkJoin and create package.

My thought is like this, but it just throws an error. So what’s the proper way to do this?

{ lib, pkgs, ... }:
let
  wrap = { appName, appPkg }:
    pkgs.symlinkJoin {
      name = appName;
      paths = [ appPkg ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = lib.strings.concatStrings [
        "wrapProgram $out/bin/"
        appName
        " --add-flags \"--ozone-platform-hint=auto\""
        " --add-flags \"--enable-webrtc-pipewire-capturer\""
        " --add-flags \"--enable-features=WaylandWindowDecorations\""
        " --add-flags \"--enable-wayland-ime\""
      ];
    };
in
{
  environment.systemPackages = [
    wrap { appName = "ferdium"; appPkg = pkgs.ferdium; }
  ];
}
       … while calling anonymous lambda

         at /nix/store/lwyjz70qh12nq6cb7fixl85vryzxqm3c-source/lib/types.nix:538:14:

          537|       merge = loc: defs:
          538|         map (x: x.value) (filter (x: x ? value) (concatLists (imap1 (n: def:
             |              ^
          539|           imap1 (m: def':

       error: A definition for option `environment.systemPackages."[definition 2-entry 1]"' is not of type `package'. Definition values:
       - In `/nix/store/xinn8195gqw5h9fa5zlhbyrn2p0ah32d-source/nixos/module/electron.nix': <function, args: {appName, appPkg}>

Not native English speaker, I hope I have expressed myself clearly.

Figure out how to do it now. Not pretty sure why, it seems previous way the function is not invoked cause nix is “lazy”.

{ lib, pkgs, ... }:
let

  wrap = { appName } :
    pkgs.symlinkJoin {
      name = appName;
      paths = [ pkgs.${appName} ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = lib.strings.concatStrings [
        "wrapProgram $out/bin/"
        appName
        " --add-flags \"--ozone-platform-hint=auto\""
        " --add-flags \"--enable-webrtc-pipewire-capturer\""
        " --add-flags \"--enable-features=WaylandWindowDecorations\""
        " --add-flags \"--enable-wayland-ime\""
      ];
    };

    ferdium = wrap { appName = "ferdium"; };
    obsidian = wrap { appName = "obsidian"; };

in
{

  environment.systemPackages = [
    ferdium
    obsidian
  ];

}