How to properly config clang on macOS?

I am not sure how to config clang on macOS, I seem to always have problems when exporting libraries to clang. This is my first time trying Nix on my Mac, everything else seems to be going OK (I think).

When I run clang -Xlinker -v, I get:

@(#)PROGRAM:ld  PROJECT:ld64-530
BUILD 15:32:20 Feb  5 2022
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
	/nix/store/7i2vs7a2wphiq7xa5i84sc23rcxadq5b-libcxx-11.1.0/lib
	/nix/store/nzq2nk6h535p2lbgbdgf563swm6l5z24-libcxxabi-11.1.0/lib
	/nix/store/g9jhj4m3wi0pagmvzzb78xhxp4fa1wbl-compiler-rt-libc-11.1.0/lib
	/nix/store/7i2vs7a2wphiq7xa5i84sc23rcxadq5b-libcxx-11.1.0/lib
	/nix/store/nzq2nk6h535p2lbgbdgf563swm6l5z24-libcxxabi-11.1.0/lib
	/nix/store/g9jhj4m3wi0pagmvzzb78xhxp4fa1wbl-compiler-rt-libc-11.1.0/lib
	/nix/store/c5jrszdq2hy3hj9rpyx3hk9gba60wd1d-Libsystem-1238.60.2/lib
	/nix/store/9742y574liw347wp9vdvwpaa8jlv63fd-clang-11.1.0-lib/lib
	/nix/store/7i2vs7a2wphiq7xa5i84sc23rcxadq5b-libcxx-11.1.0/lib
Framework search paths:
	/nix/store/xl2s63shkj95wnrv992hyf19g2r7i740-swift-corefoundation-unstable-2018-09-14/Library/Frameworks
	/nix/store/xl2s63shkj95wnrv992hyf19g2r7i740-swift-corefoundation-unstable-2018-09-14/Library/Frameworks
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

I also have similar problems when trying to install an iHaskell notebook, I get the following error:

[1 of 1] Compiling Main             ( Setup.hs, /private/tmp/nix-build-Only-0.1.drv-0/Main.o )
Linking Setup ...
ld: file not found: /usr/lib/system/libcache.dylib for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
`cc' failed in phase `Linker'. (Exit code: 1)
error: builder for '/nix/store/r9j3flxi1y9llfgsv6ils8sayjkn0pzc-Only-0.1.drv' failed with exit code 1;
       last 10 log lines:
       > setting SOURCE_DATE_EPOCH to timestamp 1497299420 of file Only-0.1/src/Data/Tuple/Only.hs
       > patching sources
       > Replace Cabal file with edited version from mirror://hackage/Only-0.1/revision/1.cabal.
       > compileBuildDriverPhase
       > setupCompileFlags: -package-db=/private/tmp/nix-build-Only-0.1.drv-0/setup-package.conf.d -j12 -threaded -rtsopts
       > [1 of 1] Compiling Main             ( Setup.hs, /private/tmp/nix-build-Only-0.1.drv-0/Main.o )
       > Linking Setup ...
       > ld: file not found: /usr/lib/system/libcache.dylib for architecture x86_64
       > clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
       > `cc' failed in phase `Linker'. (Exit code: 1)
       For full logs, run 'nix log /nix/store/r9j3flxi1y9llfgsv6ils8sayjkn0pzc-Only-0.1.drv'.
error: 1 dependencies of derivation '/nix/store/1q13l93422xpiymm5n87cvnr5vlvin37-cassava-0.5.2.0.drv' failed to build
building '/nix/store/y57jamdz86j4s4bb2q7wzrk3h52qcg7b-abstract-deque-0.3.drv'...
error: 1 dependencies of derivation '/nix/store/rc1xw73sna71y08lnjcgm7x98wqkbkhn-criterion-1.5.6.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/r6l7f4mgix6mljfj8rzjlyk0wf3qcbxc-network-uri-2.6.3.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cwxfgnpbspxygzfkhnsnmy6d8kjd9sqp-ghc-8.6.5-with-packages.drv' failed to build
error: 1 dependencies of derivation '/nix/store/k0z24680kg2qj5mwa193m3m1hgdpka5f-http-client-0.6.4.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/h6sd21hs063sv00wmyz7w11xxhdndi3s-http-client-tls-0.3.5.3.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3gnxa57lyp4gqa4lgzymlcjplg01mff6-ghc-monad-bayes.drv' failed to build
error: build of '/nix/store/3gnxa57lyp4gqa4lgzymlcjplg01mff6-ghc-monad-bayes.drv', '/nix/store/5idgz87djmxa79yxg89mhpzx1x7sqjap-ihaskell-kernel.drv', '/nix/store/rpqm9294gn4jka9bx1l6zmxklafl20xg-python3.7-jupyterlab-2.1.0.drv', '/nix/store/wgydxmadwjglg43h5sx3b6lkcgn6bz7g-ghci-monad-bayes.drv' failed

Similarly, I get a related error when trying to install KiCS2:

==> Building Curry frontend
make[1]: Entering directory '/Users/cyberglot/workspace/kics2/frontend'
stack install --local-bin-path /Users/cyberglot/workspace/kics2/frontend/bin
Linking /Users/cyberglot/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 ...
ld: library not found for -liconv
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)

--  While building simple Setup.hs (scroll up to its section to see the error) using:
      /Users/cyberglot/.stack/programs/x86_64-osx/ghc-8.10.7/bin/ghc-8.10.7 -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.2.1.0 /Users/cyberglot/.stack/setup-exe-src/setup-mPHDZzAJ.hs /Users/cyberglot/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -o /Users/cyberglot/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7
    Process exited with code: ExitFailure 1
make[1]: *** [Makefile:15: frontend] Error 1
make[1]: Leaving directory '/Users/cyberglot/workspace/kics2/frontend'
make: *** [mk/bin.mk:58: /Users/cyberglot/workspace/kics2/bin/kics2-frontend] Error 2