Start moving emacs configuration to nix.

This commit is contained in:
Kevin Baensch 2019-11-11 18:41:30 +01:00
parent 0d9fa5b37e
commit 986ca7f5cd
11 changed files with 841 additions and 67 deletions

View file

@ -1,62 +1,165 @@
{ config, pkgs, ... }:
{ config, lib, pkgs, ... }:
with lib;
let
gitpkgs = import /nixpkgs {};
in {
config.machine.pkgsets.emacs.pkgwrap = [ (gitpkgs.emacsWithPackages (epkgs: with epkgs; config.machine.pkgsets.emacs.pkgs)) ];
config.machine.pkgsets.emacs.pkgs = with pkgs; with pkgs.emacsPackages; [
/* Theming */
solarized-theme color-theme-sanityinc-tomorrow moe-theme powerline moody minions
/*General Stuff */
rainbow-delimiters # color parenthesis by indentation
color-identifiers-mode
/* Python */
company-jedi pylint elpy flycheck-mypy
/* Git support */
magit
emms # multimedia support
wsd-mode
plantuml-mode
/* Other Stuff, not yet sorted */
mu4e-alert
google-translate
tramp
transmission
org-plus-contrib orgit ox-gfm ox-rst
easy-jekyll markdown-mode impatient-mode simple-httpd htmlize
eclim
auto-complete
pkgs.aspell pkgs.aspellDicts.en pkgs.aspellDicts.de
use-package diminish bind-key
smartparens
evil-surround evil-indent-textobject evil-cleverparens avy undo-tree
cdlatex # for math expressions
helm
/* LaTeX */ auctex helm-bibtex cdlatex
markdown-mode
flycheck
pkgs.ledger
yaml-mode
company
# Irony is currently broken.
/* C/C++ */ irony company-irony company-irony-c-headers flycheck-irony clang-format pkgs.clang-tools
/* Haskell */ haskell-mode flycheck-haskell
/* Org */ org org-ref pdf-tools org-bullets org-caldav
/* Rust */ rust-mode flycheck-rust racer
/* mail */ messages-are-flowing
/* Nix */ nix-buffer nix-mode nixos-options company-nixos-options nix-sandbox
paganini-theme
json-navigator
spaceline # modeline beautification
winum eyebrowse # window management
auto-compile
/* Maxima */ pkgs.maxima
visual-fill-column
web-mode
melpaStablePackages.idris-mode helm-idris
/* Java */
# projectile yasnippet lsp-mode hydra company-lsp lsp-ui lsp-java dap-mode
cl-lib meghanada autodisass-java-bytecode google-c-style realgud
weechat
modefiles = lists.forEach
(attrNames
(filterAttrs (n: v: v == "regular")
(builtins.readDir ./emacs)))
(v: "./emacs/${v}");
in rec {
nixpkgs.overlays = [
(import (builtins.fetchTarball {
url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
}))
];
imports = [
../../options/emacs-init.nix
# modefiles
];
programs.emacs.init = {
enable = true;
recommendedGcSettings = true;
prelude = ''
;; Disable UI Clutter
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(tooltip-mode -1)
(blink-cursor-mode -1)
(setq ring-bell-function 'ignore)
(setq inhibit-startup-buffer-menu t)
(setq use-dialog-box nil)
(setq inhibit-startup-message t)
(setq inhibit-splash-screen t)
(setq initial-scratch-message nil)
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default show-trailing-whitespace t)
;; Save and Backup behaviour
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(setq create-lockfiles nil)
(setq backup-directory-alist `(("." . "~/.emacs_saves")))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
;; Tabs vs Spaces... I like Spaces
(setq-default indent-tabs-mode nil
tab-width 4
c-basic-offset 4)
;; General Functions I want
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
;; Global UI related Modes
(global-display-line-numbers-mode)
(setq display-line-numbers-width-start t)
(setq display-line-numbers-grow-only t)
(column-number-mode t)
(global-hl-line-mode t)
(size-indication-mode t)
(show-paren-mode t)
;; Font Config
(defun set-fonts (frame)
(interactive)
"Adjust the font settings of FRAME so Emacs can display emoji and chinese properly."
(set-fontset-font t 'ascii (font-spec :family "DejaVu Sans Mono") frame 'preprend)
(set-fontset-font t 'big5 (font-spec :family "AR PL UMing TW") frame)
(set-fontset-font t 'chinese-gbk (font-spec :family "AR PL UMing CN") frame)
(set-fontset-font t 'symbol (font-spec :family "Symbola") frame 'prepend))
;; For when Emacs is started in GUI mode:
(set-fonts nil)
;; Hook for when a frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions 'set-fonts)
'';
};
# machine.pkgsets.emacs.pkgwrap = [(gitpkgs.pkgs.emacsWithPackages (ps: with ps; config.machine.pkgsets.emacs.pkgs))];
#[
# (pkgs.emacsWithPackagesFromUsePackage {
# # config = (concatStringsSep "\n" machine.pkgsets.emacs.config);
# config = ''
# # (package-initialize)
# # (org-babel-load-file "~/.emacs.d/configuration.org")
# '';
# package = pkgs.emacsGit;
# extraEmacsPackages = (ep: with ep; config.machine.pkgsets.emacs.pkgs);
# })
# ];
# machine.pkgsets.emacs.pkgs = with pkgs; with pkgs.emacsPackages; [
# /* Theming */
# solarized-theme color-theme-sanityinc-tomorrow moe-theme powerline moody minions
# /*General Stuff */
# rainbow-delimiters # color parenthesis by indentation
# color-identifiers-mode
# /* Python */
# company-jedi pylint elpy flycheck-mypy
# /* Git support */
# magit
# emms # multimedia support
# wsd-mode
# plantuml-mode
# /* Other Stuff, not yet sorted */
# mu4e-alert
# google-translate
# tramp
# transmission
# org-plus-contrib orgit ox-gfm ox-rst
# easy-jekyll markdown-mode impatient-mode simple-httpd htmlize
# eclim
# auto-complete
# pkgs.aspell pkgs.aspellDicts.en pkgs.aspellDicts.de
# use-package diminish bind-key
# smartparens
# evil-surround evil-indent-textobject evil-cleverparens avy undo-tree
# cdlatex # for math expressions
# helm
# /* LaTeX */ auctex helm-bibtex cdlatex
# markdown-mode
# flycheck
# pkgs.ledger
# yaml-mode
# company
# # Irony is currently broken.
# /* C/C++ */ irony company-irony company-irony-c-headers flycheck-irony clang-format pkgs.clang-tools
# /* Haskell */ haskell-mode flycheck-haskell
# /* Org */ org org-ref pdf-tools org-bullets org-caldav
# /* Rust */ rust-mode flycheck-rust racer
# /* mail */ messages-are-flowing
# /* Nix */ nix-buffer nix-mode nixos-options company-nixos-options nix-sandbox
# paganini-theme
# json-navigator
# spaceline # modeline beautification
# winum eyebrowse # window management
# auto-compile
# /* Maxima */ pkgs.maxima
# visual-fill-column
# web-mode
# melpaStablePackages.idris-mode helm-idris
# /* Java */
# # projectile yasnippet lsp-mode hydra company-lsp lsp-ui lsp-java dap-mode
# cl-lib meghanada autodisass-java-bytecode google-c-style realgud
# weechat
# ];
}

View file

@ -0,0 +1,19 @@
{ config, ... }:
mkIf (elem "emacs-company" config.machine.pkgs) {
programs.emacs.init.usePackage.company = {
enable = true;
diminish = [ "company-mode" ];
hook = [ "(after-init . global-company-mode)" ];
bind = { "\t" = "'company-complete-common"; };
config = ''
(setq company-idle-delay 0.3
company-show-numbers t)
'';
extraConfig = ''
:bind (:map company-mode-map
([remap completion-at-point] . company-complete-common)
([remap complete-symbol] . company-complete-common))
'';
};
}

View file

@ -0,0 +1,28 @@
{ config, ... }:
mkIf (elem "emacs-flyspell" config.machine.pkgs) {
programs.emacs.init.usePackage.flyspell = {
enable = true;
diminish = [ "flyspell-mode" ];
command = [ "flyspell-mode" "flyspell-prog-mode" ];
hook = [];
bind = {
"C-M-<tab>" = "flyspell-switch-dictionary";
"C-c f" = "ispell-word";
};
config = ''
;; Make flyspell less verbose and disable annoying keybind
(setq flyspell-issue-message-flag nil
flyspell-issue-welcome-flag nil
flyspell-use-meta-tab nil)
(defun flyspell-switch-dictionary ()
(interactive)
(let* ((dic ispell-current-dictionary)
(change (if (string= dic "deutsch8") "english" "deutsch8")))
(ispell-change-dictionary change)
(message "Dictionary switched to %s" change)
))
'';
};
}

100
pkgs/pkgsets/emacs/mu4e.nix Normal file
View file

@ -0,0 +1,100 @@
{ config, lib, pkgs, ... }:
with lib;
mkIf (elem "emacs-mu4e" config.machine.pkgs) {
programs.emacs.init.usePackage.mu4e = {
enable = true;
package = epkgs: null;
command = [ "mu4e" ];
diminish = [ "mu4e-mode" ];
hook = [
"('mu4e-view-mode-hook #'visual-line-mode)"
"('mu4e-compose-mode-hook 'flyspell-mode)"
];
bind = { "\t" = "'company-complete-common"; };
config = ''
(setq mail-user-agent 'mu4e-user-agent)
(setq org-mu4e-link-query-in-headers-mode t)
(setq mu4e-maildir "~/.mail/Mail")
(setq mu4e-get-mail-command "${pkgs.isync}/bin/mbsync -a")
(setq mu4e-context-policy 'pick-first)
(setq mu4e-change-filenames-when-moving t)
(setq starttls-use-gnutls t)
(setq message-send-mail-function 'smtpmail-send-it)
(setq mu4e-update-interval 300)
(setq mu4e-use-fancy-chars t)
(setq mu4e-view-show-addresses t)
(setq mu4e-headers-show-threads t)
(setq mu4e-headers-skip-duplicates t)
(setq mail-user-agent 'mu4e-user-agent)
(defvaralias 'mu4e-compose-signature 'message-signature)
(setq-default mu4e-save-multiple-attachments-without-asking t)
(setq-default mu4e-view-show-addresses t)
(setq-default mu4e-confirm-quit nil)
(setq-default mu4e-hide-index-messages t)
(setq-default mu4e-index-update-in-background t)
(setq mu4e-compose-in-new-frame nil)
;;rename files when moving
;;NEEDED FOR MBSYNC
(setq mu4e-change-filenames-when-moving t)
(setq mu4e-html2text-command "iconv -c -t utf-8 | ${pkgs.pandoc}/bin/pandoc -f html -t plain")
(setq mu4e-view-show-images t)
(when (fboundp 'imagemagick-register-types)
(imagemagick-register-types))
(setq message-kill-buffer-on-exit t)
(setq mu4e-contexts
`(${map
(rec { name, fullName, address, sServer, sPort, sUser ? address }: ''
,(make-mu4e-context
:name ${name}
:vars '((user-mail-address . ${address} )
(user-full-name . ${fullName} )
(mu4e-sent-folder . "/Sent")
(mu4e-drafts-folder . "/Drafts")
(mu4e-trash-folder . "/Deleted")
(mu4e-refile-folder . "/Archiv")
(smtpmail-smtp-user . ${sUser} )
(smtpmail-auth-credentials . (expand-file-name "~/mail/secret/.authinfo.gpg"))
(smtpmail-default-smtp-server . ${sServer} )
(smtpmail-smtp-server . ${sServer} )
(smtpmail-stream-type . starttls)
(smtpmail-smtp-service . ${sPort} )
)
)
'';
)
(import "${config.machine.secretPath}/secrets.nix").mu4e}
))
(defun my-browse-url-firefox-privately (url &optional new-window)
"Make firefox open URL in private-browsing window."
(interactive (browse-url-interactive-arg "URL: "))
(let ((process-environment (browse-url-process-environment)))
(apply 'start-process
(concat "firefox " url)
nil
browse-url-firefox-program
(list "-private-window" url))))
(setq browse-url-browser-function 'my-browse-url-firefox-privately)
(add-to-list 'mu4e-view-actions
'("ViewInBrowser" . mu4e-action-view-in-browser) t)
'';
extraConfig = ''
:load-path ${pkgs.mu4e}/share/emacs/site-lisp/mu4e
'';
};
programs.emacs.init.usePackage.mu4e-alert = {
enable = true;
hook = [ "'after-init-hook" = "#'mu4e-alert-enable-mode-line-display" ];
};
environment.systemPackages = [
mu4e
isync
];
}

View file

@ -0,0 +1,14 @@
{ config, ... }:
mkIf (elem "emacs-poerline" config.machine.pkgs) {
programs.emacs.init.usePackage.solarized-theme = {
enable = true;
config = ''
;; color palette from https://github.com/kuanyui/moe-theme.el/blob/master/moe-theme.el#L283
(set-face-attribute 'mode-line nil :background "#afd7ff" :foreground "#005f87")
(set-face-attribute 'mode-line-buffer-id nil :background "#afd7ff" :foreground "#080808")
(set-face-attribute 'minibuffer-prompt nil :foreground "#5fafd7" :background "#3a3a3a")
(powerline-default-theme)
'';
};
}

View file

@ -0,0 +1,8 @@
{ config, ... }:
mkIf (elem "emacs-solarized-theme" config.machine.pkgs) {
programs.emacs.init.usePackage.solarized-theme = {
enable = true;
config = "(load-theme 'solarized-dark t)";
};
}