Emacs --with-xwidgets not detecting webkitgtk

{ config, pkgs, ... }:

let
  RELOAD = "export PATH=${pkgs.emacs}/bin:$PATH && export PATH=${pkgs.git}/bin:$PATH && /home/safri/.nix/home/emacs/doom.sh";
in

{

  home.packages = with pkgs; [
    # DOOM Emacs dependencies
    binutils
    (ripgrep.override { withPCRE2 = true; })
    gnutls
    fd
    imagemagick
    zstd
    nodePackages.javascript-typescript-langserver
    sqlite
    editorconfig-core-c
    emacs-all-the-icons-fonts
  ];

  home.file = {

    "${config.xdg.configHome}/doom" = {
      source = ./doom;
      recursive = true;
      onChange = ''${RELOAD}'';
    };

  };

  services.emacs = {
    enable = true;
    client.enable = true;
    defaultEditor = true;
  };

  programs.emacs = {
    enable = true;
    # https://www.reddit.com/r/NixOS/comments/14sdrw6/help_with_setting_up_with_emacs_build/
    package = pkgs.emacs.overrideAttrs (oldAttrs: {
      nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ pkgs.pkg-config ];
      buildInputs = with pkgs; (oldAttrs.buildInputs or []) ++ [ gtk3 webkitgtk_4_1 ];
      configureFlags = oldAttrs.configureFlags ++ [
        "--without-x"
        "--without-ns"
        "--with-pgtk"
        "--with-xwidgets"
        "--with-png"
        "--with-jpeg"
        "--with-sound"
        "--with-file-notifications=yes"
      ];
    });
  };

}

error:

error: 1 dependencies of derivation '/nix/store/b5sd6yjylb4rnvp5j5nzxkmlirkafhy1-emacs-with-packages-30.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/53lsmkgw4c9jydr38qidf8qlq9ic9bm5-emacs.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/wvazwsx4x8i8iyxqkipnklh849ql3g34-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ijhlfsbcb979msf1dhjfjy3wm1sxy92z-home-manager-generation.drv' failed to build
┏━ 1 Errors: 
┃ error: builder for '/nix/store/absyd2xhcm6n76hkbi2c9v4n5q028lbx-emacs-30.1.drv' failed with exit code 1;
┃        last 25 log lines:
┃        >        closing open displays.  This is no problem if you just use
┃        >        one display, but if you use more than one and close one of them
┃        >        Emacs may crash.
┃        >        See https://gitlab.gnome.org/GNOME/gtk/issues/221
┃        > checking for malloc_trim... yes
┃        > checking for dbus-1 >= 1.0... yes
┃        > checking for dbus_watch_get_unix_fd... yes
┃        > checking for dbus_type_is_valid... yes
┃        > checking for dbus_validate_bus_name... yes
┃        > checking for dbus_validate_path... yes
┃        > checking for dbus_validate_interface... yes
┃        > checking for dbus_validate_member... yes
┃        > checking for gio-2.0 >= 2.26... yes
┃        > checking whether GSettings is in gio... yes
┃        > checking for gobject-2.0 >= 2.0... yes
┃        > checking for lgetfilecon in -lselinux... yes
┃        > checking for gnutls >= 2.12.2... yes
┃        > checking for libsystemd >= 222... yes
┃        > checking for tree-sitter >= 0.20.2... yes
┃        > checking for sys/inotify.h... yes
┃        > checking for inotify_init... yes
┃        > checking for inotify_init1... yes
┃        > checking for webkit2gtk-4.1 >= 2.12 webkit2gtk-4.1 < 2.41.92... no
┃        > checking for webkit2gtk-4.0 >= 2.12 webkit2gtk-4.0 < 2.41.92... no
┃        > configure: error: xwidgets requested but WebKitGTK+ or WebKit framework not found.
┃        For full logs, run:
┃          nix log /nix/store/absyd2xhcm6n76hkbi2c9v4n5q028lbx-emacs-30.1.drv

I believe the issue is that emacs isn’t detecting webkit during the build process but I have no idea how to fix that.

Any help would be appreciated.

The upstream derivation has a flag for that: nixpkgs/pkgs/applications/editors/emacs/make-emacs.nix at 4792576cb003c994bd7cc1edada3129def20b27d · NixOS/nixpkgs · GitHub

You should be able to just do this to force it:

programs.emacs.package = pkgs.emacs.override { withXwidgets = true; };

That said, the defaults look to be set correctly to work around bugs. I’d suggest simply using emacs-pgtk, it’s built with xwidget support according to the default values.

  programs.emacs = {
    package = pkgs.emacs-pgtk.override { withXwidgets = true; withGTK3 = true; };
    enable = true;
  };

It didn’t build without gtk

┃        > checking for webkit2gtk-4.1 >= 2.12 webkit2gtk-4.1 < 2.41.92... no
┃        > checking for webkit2gtk-4.0 >= 2.12 webkit2gtk-4.0 < 2.41.92... no
┃        > configure: error: xwidgets requested but WebKitGTK+ or WebKit framework not found.

Same error

Are you on MacOS? If so, you cannot do this. At least I assume you are, since emacs-pgtk does not need those overrides for xwidget support.

No, I’m on NixOS

safri@nixos:~/ > nixos-version
25.05.20250531.a59eb78 (Warbler)

Huh, that’s very surprising, it shouldn’t even be rebuilding. Have you tried just emacs-pgtk without the override?

Yes, that builds but not with xwidget support.

Ah, sorry, I misread the condition. Emacs v>30 cannot be built with xwidgets: nixpkgs/pkgs/applications/editors/emacs/make-emacs.nix at b4656359c085638a10f66be6f86b978be17dcded · NixOS/nixpkgs · GitHub

This leaves you with only vulnerable versions of either webkit or emacs until that is fixed upstream, and neither is packaged in NixOS, for obvious reasons.

unfortunate, thank you for the help though!