`LSOpenURLsWithRole()` error opening Nix-installed application (Emacs native-comp)on macOS

I am trying to get emacsGcc built on macOS using this Nixpkgs patchset and the nix-community/emacs-overlay. This is what I have in my overlays folder:

# emacs-native.nix
import (builtins.fetchTarball {
  url = https://github.com/nix-community/emacs-overlay/archive/aa69bf3bdc4e63c3a1a3d0f1a8273a9755d8ae4c.tar.gz;
})
# emacs.nix
self: super: {
  personal = {
    emacsPackagesNg =
      let
        pkgs = import (fetchGit {
          url = "https://github.com/NixOS/nixpkgs.git";
          # nixpkgs-unstable revision at time of writing
          rev = "72b9660dc18ba347f7cd41a9504fc181a6d87dc3";
        }) { };

        # Testing patchset found at
        # https://github.com/twlz0ne/nix-gccemacs-darwin/commit/0ce1bd5d6ee2424a251ded9efb85bd7de4ec4a28
        # Without this I get the error mentioned in that patchset
        emacsGcc = self.emacsGcc.overrideAttrs (oldAttrs: {
          postInstall = (oldAttrs.postInstall or "") + ''
            ln -snf $out/lib/emacs/28.0.50/native-lisp $out/native-lisp
            ln -snf $out/lib/emacs/28.0.50/native-lisp $out/Applications/Emacs.app/Contents/native-lisp
            cat <<EOF> $out/bin/run-emacs.sh
            #!/usr/bin/env bash
            set -e
            exec $out/bin/emacs-28.0.50 "\$@"
            EOF
            chmod a+x $out/bin/run-emacs.sh
            ln -snf ./run-emacs.sh $out/bin/emacs
          '';
        });

      in
        pkgs.emacsPackagesNgGen emacsGcc;
...

This builds fine but when I try to run emacs to open the application I get:

$ emacs
LSOpenURLsWithRole() failed for the application /Users/adelbertc/.nix-profile/Applications/Emacs.app with error -10810.

Any help would be appreciated.

Hi, the nix community bot pung me about this thread, nice feature (-:

I don’t know what concrete error you’re getting (you can check that by running /Users/adelbertc/.nix-profile/Applications/Emacs.app/Contents/MacOS/Emacs - it looks like your emacs is a wrapper script that opens the app bundle?), but I’ll make a guess because I have the same problem:

I believe this is due to .eln files getting moved from where they were built, and the relative directories (which is how the emacs pdump logic keeps track of their paths otherwise) being different from the paths that are present in the Emacs.app. The only way I know of to run the gccemacs under macOS in nix is to invoke the commandline emacs binary that’s installed by the nix closure next to the app bundle. The app bundle sadly doesn’t work.

There’s a GNU BTS thread here with a patch that I tried making but haven’t gotten to work: #43137 - 28.0.50; [feature/native-comp] .eln path fixup confused using relative paths - GNU bug report logs

1 Like

Oooo yes that’s it! I just remembered a while ago I alias’ed the emacs command in my shell:

if [[ "${OSTYPE}" == "darwin"* ]]; then
  alias emacs="open -a ~/.nix-profile/Applications/Emacs.app --args"
fi

If I run the emacs binary directly I get a different error, need to dig into that next.

$ ~/.nix-profile/bin/emacs
(setf seq-elt) is already defined as something else than a generic function

I have this error occasionally on nixOS with gccEmacs. Deleting ~/.emacs.d/eln-cache usually helps with that.

I just tried locally, apparently the ~/.nix-profile/Applications/Emacs.app/Contents miss a link.

I fixed the use by doing:

cd ~/.nix-profile/Applications/Emacs.app/Contents
sudo ln -s /nix/store/*-emacs-gcc-20200930.0/lib/emacs/28.0.50/native-lisp native-lisp