NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.4k stars 13.62k forks source link

Document embedding Emacs configuration inside of an emacsWithPackages #24243

Closed grahamc closed 7 years ago

grahamc commented 7 years ago

Issue description

I spent a long time trying to figure out how to make an emacsWithPackages that contained my personal configuration. I wanted to avoid having an ~/.emacs.d/init.el`. I don't know where else to put this sort of knowledge, and it may not be idiomatic emacs, but I think it is worth documenting:

{ pkgs ? import <nixpkgs> {} }:
let
  stdenv = pkgs.stdenv;

  emacsEcosystem = pkgs.emacsPackagesNg;
  trivialBuild = pkgs.callPackage <nixpkgs/pkgs/build-support/emacs/trivial.nix> {
    emacs = pkgs.emacs;
  };

  my-mode = emacsEcosystem.trivialBuild {
    pname = "my-mode";
    version = "1970-01-01";
    src = pkgs.writeText "default.el" ''
      ;; You can put global config here, especially things that don't
      ;; symbols from plugins to be defined
      (global-set-key (kbd "<end>") 'end-of-line)
      (global-set-key (kbd "<home>") 'beginning-of-line)
      (add-hook 'before-save-hook 'delete-trailing-whitespace)
      (setq graphviz-dot-dot-program "${pkgs.graphviz}/bin/dot")
      (setq graphviz-dot-view-edit-command nil)

      (defun my-moode-delayed-load ()
            (editorconfig-mode 1)
      )
      (add-hook 'after-init-hook #'my-mode-delayed-load)
    '';
  };
in
(emacsEcosystem.emacsWithPackages (epkgs: with epkgs.melpaPackages; [
  editorconfig
  graphviz-dot-mode
] ++ [my-mode]))
rlupton20 commented 7 years ago

Agree - I have a completely different way to do this, which I'm not sure is particularly nice. I chuck my .emacs into site-start.el...

Could probably write a nice wrapper for this kind of thing to make it cleaner.

matthewbauer commented 7 years ago

Similar issue: #19956

rlupton20 commented 7 years ago

@matthewbauer looks like you solved this similarly to me (except properly). Lets chase up the pull request rejection, and see what we can do.