anchor.diff:  , withCsrc ? true
   , srcRepo ? false, autoconf ? null, automake ? null, texinfo ? null
   , siteStart ? ./site-start.el
  +, nativeComp ? false
   , toolkit ? (
     if withGTK2 then "gtk2"
     else if withGTK3 then "gtk3"
  
positive.code:   postInstall = ''
      mkdir -p $out/share/emacs/site-lisp
      cp ${siteStart} $out/share/emacs/site-lisp/site-start.el
      $out/bin/emacs --batch -f batch-byte-compile $out/share/emacs/site-lisp/site-start.el
  
      rm -rf $out/var
  
negative.code:     })
    ];
  
    postPatch = lib.concatStringsSep "\n" [
      (lib.optionalString srcRepo ''
        rm -fr .git
      '')
  
      # Make native compilation work both inside and outside of nix build
      (lib.optionalString nativeComp (let
        libPath = lib.concatStringsSep ":" [
          "${lib.getLib libgccjit}/lib/gcc/${targetPlatform.config}/${libgccjit.version}"
          "${lib.getLib stdenv.cc.cc}/lib"
          "${lib.getLib stdenv.glibc}/lib"
        ];
      in ''
        substituteInPlace lisp/emacs-lisp/comp.el --replace \
          "(defcustom comp-async-env-modifier-form nil" \
          "(defcustom comp-async-env-modifier-form '((setenv \"LIBRARY_PATH\" (string-join (seq-filter (lambda (v) (null (eq v nil))) (list (getenv \"LIBRARY_PATH\") \"${libPath}\")) \":\")))"
  
      ''))
  
      ""
    ];
  
    CFLAGS = "-DMAC_OS_X_VERSION_MAX_ALLOWED=101200";
  
    LIBRARY_PATH = if nativeComp then "${lib.getLib stdenv.cc.libc}/lib" else "";
  
    nativeBuildInputs = [ pkgconfig makeWrapper ]
      ++ lib.optionals srcRepo [ autoconf automake texinfo ]
      ++ lib.optional (withX && (withGTK3 || withXwidgets)) wrapGAppsHook;
  
    buildInputs =
      [ ncurses gconf libxml2 gnutls alsaLib acl gpm gettext jansson harfbuzz.dev ]
      ++ lib.optionals stdenv.isLinux [ dbus libselinux systemd ]
      ++ lib.optionals withX
  