Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emacs: add currently compiling package dirs to load-path #107777

Merged
merged 1 commit into from Feb 19, 2021

Conversation

collares
Copy link
Member

@collares collares commented Dec 28, 2020

Motivation for this change

See item 1 in nix-community/emacs-overlay#74 (comment). The "emacsHookDone=1" part is admittedly very hacky, suggestions are appreciated. (Edit: No longer hacky, see below)

Things done
  • Built on platform(s)
    • NixOS

@collares
Copy link
Member Author

collares commented Jan 6, 2021

@adisbladis @alyssais @tadfisher I noticed that ofborg didn't add a reviewer for this, so I am tagging people that worked on this recently to get the ball rolling. Feel free to ignore this if you don't have time or just don't want to do it :)

If you want to test this locally, please use an updated gccemacs version since I was hitting a bug was fixed upstream today. The current version on emacs-overlay is fine.

@tadfisher
Copy link
Contributor

The "emacsHookDone=1" part is admittedly very hacky, suggestions are appreciated.

You could split addToEmacsLoadPath, addToEmacsNativeLoadPath, and addEmacsVars into a separate file (e.g. emacs-funcs.sh) and source it from both setupHook and postInstall.

{
  setupHook = ''
    source ${./emacs-funcs.sh}

    if [[ ! -v emacsHookDone ]]; then
      emacsHookDone=1

      # If this is for a wrapper derivation, emacs and the dependencies are all
      # run-time dependencies. If this is for precompiling packages into bytecode,
      # emacs is a compile-time dependency of the package.
      addEnvHooks "$hostOffset" addEmacsVars
      addEnvHooks "$targetOffset" addEmacsVars
    fi
  '';

  postInstall = ''
    # Make sure the current package's elisp files are in load-path, otherwise
    # (require 'file-b) from file-a.el in the same package will fail.
    source ${./emacs-funcs.sh}
    addEmacsVars "$out"

    # ...
  '';
}

So basically rename setup-hook.sh so maintainers don't get confused and move the hook install into setupHook in the derivation.

@tadfisher
Copy link
Contributor

Can you also try removing the --eval=\"(add-to-list 'comp-eln-load-path \\\"$out/share/emacs/native-lisp/\\\")\" stanza from the native compile command and compare the output?

@collares
Copy link
Member Author

collares commented Jan 6, 2021

Thanks for the great refactoring idea! Since setupHook expects a file name and not the file's contents, I had to sprinkle writeText in a few places. Let me know if this is a bad idea :) Even then, I believe the refactored approach is much cleaner.

I get a bunch of (error "Cannot find suitable directory for output in `comp...") errors when removing the --eval stanza. I believe this happens because addToEmacsNativeLoadPath tests if $nativeDir is a directory before it gets created by the native compilation process. I went ahead and created the directory manually, but I can revert that if you prefer.

As a data point, here's the number of compiled files in my configuration before and after this patch:

$ ls /nix/store/cjjg220sg767052s39z4967f16divazw-emacs-packages-deps/share/emacs/native-lisp/28.0.50-x86_64-pc-linux-gnu-98ea6c3cd3377ce4e7a0782a2e12f0e9/*.eln | wc -l
526

$ ls /nix/store/2r28p285qad5s43n0pp85rmjfz0xxv40-emacs-packages-deps/share/emacs/native-lisp/28.0.50-x86_64-pc-linux-gnu-98ea6c3cd3377ce4e7a0782a2e12f0e9/*.eln | wc -l
1158

@tadfisher
Copy link
Contributor

@adisbladis Can you take a look at this?

@collares
Copy link
Member Author

There were some merge conflicts, but I've now rebased my commit. @adisbladis, sorry for pinging you again :)

Co-authored-by: Tad Fisher <tadfisher@gmail.com>
@adisbladis adisbladis merged commit 44864cd into NixOS:master Feb 19, 2021
@collares collares deleted the native-load-path branch February 19, 2021 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants