-
-
Save Xe/b1bbb3e0b7bf75510f70fbf4d9888794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo nixos-rebuild switch | |
building Nix... | |
building the system configuration... | |
these derivations will be built: | |
/nix/store/ra8468x25a70q28blpr3jf68r87xfcv9-emacs-hm-init-0.drv | |
/nix/store/kh6dv6l3fj8dxi5fvpcyckypfk783gvz-emacs-packages-deps.drv | |
/nix/store/vynljzkwgwly22is13rh9qgld5hhdw37-emacs-with-packages-26.3.drv | |
/nix/store/p5m64haws4zqk7ffh9xh45hhjk8n1maz-home-manager-path.drv | |
/nix/store/cx0nrxz1zy18v8qnd55illkzlxfpac16-activation-script.drv | |
/nix/store/32zqmka8sxjk96nf84d372ilnbskyh38-emacs.service.drv | |
/nix/store/f28x8mxgq3d5zmfzrzmm6dq3x19yq55v-emacs-with-packages-26.3-fish-completions.drv | |
/nix/store/arfc13psvapdg0mkskb4afzaz9r7s75p-cadey-fish-completions.drv | |
/nix/store/k974kr9whls5skr3k6sx2zsr2vqdc3p4-home-manager-files.drv | |
/nix/store/arhyn103nscrp739y1mzhbjyzi5wjw46-home-manager-generation.drv | |
/nix/store/w5ag62sx0vrfzxavvq6mwcc9mn1vmdng-activate-cadey.drv | |
/nix/store/1bf7k0ic2q7mw6jf6dndlh0n2pry1b5n-unit-home-manager-cadey.service.drv | |
/nix/store/04v1sdg28251p3r1pskfmq628xbjf1fs-system-units.drv | |
/nix/store/mmh6y46j756vx5k2z636ij3h7pkrhpa8-etc.drv | |
/nix/store/55aqnwwspfn083b6zw6f2mhir87p9h7r-nixos-system-shachi-20.03.1596.2faa76db27c.drv | |
building '/nix/store/ra8468x25a70q28blpr3jf68r87xfcv9-emacs-hm-init-0.drv'... | |
unpacking sources | |
unpacking source archive /nix/store/2837is78qf7s3wc0vvwcnylv3bh1m3jh-hm-init.el | |
/nix/store/vilh5ays3ymz3xkwk0fri2a70lha7pfc-stdenv-linux/setup: line 84: /nix/store/bgvd279hrb53i3ah2mi0nf8jp6g6g6g9-coreutils-8.31/bin/basename: Argument list too long | |
/nix/store/vilh5ays3ymz3xkwk0fri2a70lha7pfc-stdenv-linux/setup: line 86: /nix/store/bgvd279hrb53i3ah2mi0nf8jp6g6g6g9-coreutils-8.31/bin/cp: Argument list too long | |
/nix/store/vilh5ays3ymz3xkwk0fri2a70lha7pfc-stdenv-linux/setup: line 87: /nix/store/bgvd279hrb53i3ah2mi0nf8jp6g6g6g9-coreutils-8.31/bin/chmod: Argument list too long | |
source root is . | |
/nix/store/vilh5ays3ymz3xkwk0fri2a70lha7pfc-stdenv-linux/setup: line 923: /nix/store/bgvd279hrb53i3ah2mi0nf8jp6g6g6g9-coreutils-8.31/bin/chmod: Argument list too long | |
builder for '/nix/store/ra8468x25a70q28blpr3jf68r87xfcv9-emacs-hm-init-0.drv' failed with exit code 126 | |
cannot build derivation '/nix/store/vynljzkwgwly22is13rh9qgld5hhdw37-emacs-with-packages-26.3.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/f28x8mxgq3d5zmfzrzmm6dq3x19yq55v-emacs-with-packages-26.3-fish-completions.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/32zqmka8sxjk96nf84d372ilnbskyh38-emacs.service.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/p5m64haws4zqk7ffh9xh45hhjk8n1maz-home-manager-path.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/arhyn103nscrp739y1mzhbjyzi5wjw46-home-manager-generation.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/w5ag62sx0vrfzxavvq6mwcc9mn1vmdng-activate-cadey.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/1bf7k0ic2q7mw6jf6dndlh0n2pry1b5n-unit-home-manager-cadey.service.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/04v1sdg28251p3r1pskfmq628xbjf1fs-system-units.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/mmh6y46j756vx5k2z636ij3h7pkrhpa8-etc.drv': 1 dependencies couldn't be built | |
cannot build derivation '/nix/store/55aqnwwspfn083b6zw6f2mhir87p9h7r-nixos-system-shachi-20.03.1596.2faa76db27c.drv': 1 dependencies couldn't be built | |
error: build of '/nix/store/55aqnwwspfn083b6zw6f2mhir87p9h7r-nixos-system-shachi-20.03.1596.2faa76db27c.drv' failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, ... }: | |
{ | |
imports = [ ./emacs-init.nix ]; | |
home.file."bin/e" = { | |
text = '' | |
#!/bin/sh | |
emacsclient -a "" -nc $@ | |
''; | |
executable = true; | |
}; | |
services.emacs.enable = true; | |
programs.emacs = { | |
enable = true; | |
init = { | |
enable = true; | |
recommendedGcSettings = true; | |
prelude = let | |
fontSize = if pkgs.stdenv.isDarwin then "15" else "14"; | |
emacsFont = '' | |
(when window-system | |
(set-frame-font "Hack ${fontSize}")) | |
''; | |
in emacsFont + '' | |
(require 'bind-key) | |
(setq inhibit-startup-screen t) | |
(when window-system | |
(dolist (mode | |
'(tool-bar-mode | |
tooltip-mode | |
scroll-bar-mode | |
menu-bar-mode | |
blink-cursor-mode)) | |
(funcall mode 0))) | |
(add-hook 'text-mode-hook 'auto-fill-mode) | |
(setq delete-old-versions -1 ) ; delete excess backup versions silently | |
(setq version-control t ) ; use version control | |
(setq vc-make-backup-files t ) ; make backups file even when in version controlled dir | |
(setq backup-directory-alist `(("." . "~/.emacs.d/backups")) ) ; which directory to put backups file | |
(setq vc-follow-symlinks t ) ; don't ask for confirmation when opening symlinked file | |
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)) ) ;transform backups file name | |
(setq inhibit-startup-screen t ) ; inhibit useless and old-school startup screen | |
(setq ring-bell-function 'ignore ) ; silent bell when you make a mistake | |
(setq coding-system-for-read 'utf-8 ) ; use utf-8 by default | |
(setq coding-system-for-write 'utf-8 ) | |
(setq sentence-end-double-space nil) ; sentence SHOULD end with only a point. | |
(setq default-fill-column 80) ; toggle wrapping text at the 80th character | |
(setq initial-scratch-message "coi") ; print a default message in the empty scratch buffer opened at startup | |
(defun chomp (str) | |
"Chomp leading and tailing whitespace from STR." | |
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" | |
str) | |
(setq str (replace-match "" t t str))) | |
str) | |
(setq gofmt-command "goimports") | |
(defun eshell/e (arg) | |
"opens a given file in emacs from eshell" | |
(find-file arg)) | |
(defun eshell/eh (arg) | |
"opens a file in emacs from shell horizontally" | |
(split-window-vertically) | |
(other-window 1) | |
(find-file arg)) | |
(defun eshell/ev (arg) | |
"opens a file in emacs from shell vertically" | |
(split-window-horizontally) | |
(other-window 1) | |
(find-file arg)) | |
''; | |
usePackageVerbose = true; | |
usePackage = { | |
company = { | |
enable = true; | |
diminish = [ "company-mode" ]; | |
config = '' | |
(company-mode) | |
''; | |
}; | |
counsel = { | |
enable = true; | |
bindStar = { | |
"M-x" = "counsel-M-x"; | |
"C-x C-f" = "counsel-find-file"; | |
"C-x C-r" = "counsel-recentf"; | |
"C-c f" = "counsel-git"; | |
"C-c s" = "counsel-git-grep"; | |
"C-c /" = "counsel-rg"; | |
"C-c l" = "counsel-locate"; | |
"M-y" = "counsel-yank-pop"; | |
}; | |
general = '' | |
(general-nmap | |
:prefix "SPC" | |
"SPC" '(counsel-M-x :which-key "M-x") | |
"ff" '(counsel-find-file :which-key "find file") | |
"s" '(:ignore t :which-key "search") | |
"sc" '(counsel-unicode-char :which-key "find character")) | |
''; | |
}; | |
cython-mode = { enable = true; }; | |
direnv = { | |
enable = true; | |
config = '' | |
(direnv-mode) | |
''; | |
}; | |
evil = { | |
enable = true; | |
init = '' | |
(setq evil-want-C-i-jump nil) | |
''; | |
config = '' | |
(evil-mode 1) | |
''; | |
}; | |
evil-magit = { | |
enable = true; | |
after = [ "magit" ]; | |
}; | |
flycheck = { | |
enable = true; | |
diminish = [ "flycheck-mode" ]; | |
config = '' | |
(global-flycheck-mode) | |
''; | |
}; | |
go-mode = { enable = true; }; | |
lsp-mode = { | |
enable = true; | |
command = [ "lsp" ]; | |
hook = [ | |
"(rust-mode . lsp)" | |
"(lsp-mode . lsp-enable-which-key-integration)" | |
]; | |
config = '' | |
(setq lsp-rust-server 'rust-analyzer) | |
''; | |
}; | |
lsp-ui = { | |
enable = true; | |
after = [ "lsp" ]; | |
command = [ "lsp-ui-mode" ]; | |
}; | |
lsp-ivy = { | |
enable = true; | |
after = [ "lsp" "ivy" ]; | |
command = [ "lsp-ivy-workspace-symbol" ]; | |
}; | |
nlinum-relative = { | |
enable = true; | |
after = [ "evil" ]; | |
config = '' | |
(nlinum-relative-setup-evil) | |
(add-hook 'prog-mode-hook 'nlinum-relative-mode) | |
(add-hook 'org-mode-hook 'nlinum-relative-mode) | |
''; | |
}; | |
general = { | |
enable = true; | |
after = [ "evil" "which-key" ]; | |
config = '' | |
(general-evil-setup) | |
(general-mmap | |
";" 'evil-ex | |
":" 'evil-repeat-find-char) | |
(general-create-definer my-leader-def | |
:prefix "SPC") | |
(general-create-definer my-local-leader-def | |
:prefix "SPC m") | |
(general-nmap | |
:prefix "SPC" | |
"b" '(:ignore t :which-key "buffer") | |
"bd" '(kill-this-buffer :which-key "kill buffer") | |
"f" '(:ignore t :which-key "file") | |
"ff" '(find-file :which-key "find") | |
"fs" '(save-buffer :which-key "save") | |
"m" '(:ignore t :which-key "mode") | |
"t" '(:ignore t :which-key "toggle") | |
"tf" '(toggle-frame-fullscreen :which-key "fullscreen") | |
"wv" '(split-window-horizontally :which-key "split vertical") | |
"ws" '(split-window-vertically :which-key "split horizontal") | |
"wk" '(evil-window-up :which-key "up") | |
"wj" '(evil-window-down :which-key "down") | |
"wh" '(evil-window-left :which-key "left") | |
"wl" '(evil-window-right :which-key "right") | |
"wd" '(delete-window :which-key "delete") | |
"q" '(:ignore t :which-key "quit") | |
"qq" '(save-buffers-kill-emacs :which-key "quit")) | |
''; | |
}; | |
ivy = { | |
enable = true; | |
demand = true; | |
diminish = [ "ivy-mode" ]; | |
config = '' | |
(ivy-mode 1) | |
(setq ivy-use-virtual-buffers t | |
ivy-hight 20 | |
ivy-count-format "(%d/%d) " | |
ivy-initial-inputs-alist nil) | |
''; | |
general = '' | |
(general-nmap | |
:prefix "SPC" | |
"bb" '(ivy-switch-buffer :which-key "switch buffer") | |
"fr" '(ivy-recentf :which-key "recent file")) | |
''; | |
}; | |
magit = { | |
enable = true; | |
general = '' | |
(general-nmap | |
:prefix "SPC" | |
"g" '(:ignore t :which-key "Git") | |
"gs" 'magit-status) | |
''; | |
}; | |
markdown-mode = { | |
enable = true; | |
command = [ "markdown-mode" "gfm-mode" ]; | |
mode = [ | |
''("README\\.md\\'" . gfm-mode)'' | |
''("\\.md\\'" . markdown-mode)'' | |
''("\\.markdown\\'" . markdown-mode)'' | |
]; | |
}; | |
nix = { enable = true; }; | |
nix-mode = { | |
enable = true; | |
mode = [ ''"\\.nix\\'"'' ]; | |
bindLocal = { nix-mode-map = { "C-i" = "nix-indent-line"; }; }; | |
}; | |
nix-prettify-mode = { | |
enable = true; | |
config = '' | |
(nix-prettify-global-mode) | |
''; | |
}; | |
nix-drv-mode = { | |
enable = true; | |
mode = [ ''"\\.drv\\'"'' ]; | |
}; | |
projectile = { | |
enable = true; | |
after = [ "ivy" ]; | |
diminish = [ "projectile-mode" ]; | |
config = '' | |
(projectile-mode 1) | |
(progn | |
(setq projectile-enable-caching t) | |
(setq projectile-require-project-root nil) | |
(setq projectile-completion-system 'ivy) | |
(add-to-list 'projectile-globally-ignored-files ".DS_Store")) | |
''; | |
general = '' | |
(general-nmap | |
:prefix "SPC" | |
"p" '(:ignore t :which-key "Project") | |
"pf" '(projectile-find-file :which-key "Find in project") | |
"pl" '(projectile-switch-project :which-key "Switch project")) | |
''; | |
}; | |
protobuf-mode = { enable = true; }; | |
swiper = { | |
enable = true; | |
bindStar = { "C-s" = "swiper"; }; | |
general = '' | |
(general-nmap | |
:prefix "SPC" | |
"ss" '(swiper :which-key "swiper")) | |
''; | |
}; | |
which-key = { | |
enable = true; | |
diminish = [ "which-key-mode" ]; | |
config = '' | |
(which-key-mode) | |
(which-key-setup-side-window-right-bottom) | |
(setq which-key-sort-order 'which-key-key-order-alpha | |
which-key-side-window-max-width 0.33 | |
which-key-idle-delay 0.05) | |
''; | |
}; | |
gruvbox-theme = { | |
enable = true; | |
config = '' | |
(load-theme 'gruvbox-dark-hard t) | |
''; | |
}; | |
dhall-mode = { | |
enable = true; | |
mode = [ ''"\\.dhall\\'"'' ]; | |
}; | |
moonscript = { | |
enable = true; | |
mode = [ ''"\\.moon\\'"'' ]; | |
}; | |
rust-mode = { | |
enable = true; | |
mode = [ ''"\\.rs\\'"'' ]; | |
}; | |
toml-mode.enable = true; | |
}; | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2019 Robert Helgesson | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# | |
# Vendored from: https://gitlab.com/rycee/nur-expressions/blob/master/hm-modules/emacs-init.nix | |
{ config, lib, pkgs, ... }: | |
with lib; | |
let | |
cfg = config.programs.emacs.init; | |
packageFunctionType = mkOptionType { | |
name = "packageFunction"; | |
description = "function from epkgs to package"; | |
check = isFunction; | |
merge = mergeOneOption; | |
}; | |
usePackageType = types.submodule ({ name, config, ... }: { | |
options = { | |
enable = mkEnableOption "Emacs package ${name}"; | |
package = mkOption { | |
type = | |
types.either | |
(types.str // { description = "name of package"; }) | |
packageFunctionType; | |
default = name; | |
description = '' | |
The package to use for this module. Either the package name | |
within the Emacs package set or a function taking the Emacs | |
package set and returning a package. | |
''; | |
}; | |
defer = mkOption { | |
type = types.either types.bool types.ints.positive; | |
default = false; | |
description = '' | |
The <option>:defer</option> setting. | |
''; | |
}; | |
demand = mkOption { | |
type = types.bool; | |
default = false; | |
description = '' | |
The <option>:demand</option> setting. | |
''; | |
}; | |
diminish = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
The entries to use for <option>:diminish</option>. | |
''; | |
}; | |
chords = mkOption { | |
type = types.attrsOf types.str; | |
default = {}; | |
example = { "jj" = "ace-jump-char-mode"; "jk" = "ace-jump-word-mode"; }; | |
description = '' | |
The entries to use for <option>:chords</option>. | |
''; | |
}; | |
mode = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
The entries to use for <option>:mode</option>. | |
''; | |
}; | |
after = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
The entries to use for <option>:after</option>. | |
''; | |
}; | |
bind = mkOption { | |
type = types.attrsOf types.str; | |
default = {}; | |
example = { "M-<up>" = "drag-stuff-up"; "M-<down>" = "drag-stuff-down"; }; | |
description = '' | |
The entries to use for <option>:bind</option>. | |
''; | |
}; | |
bindLocal = mkOption { | |
type = types.attrsOf (types.attrsOf types.str); | |
default = {}; | |
example = { helm-command-map = { "C-c h" = "helm-execute-persistent-action"; }; }; | |
description = '' | |
The entries to use for local keymaps in <option>:bind</option>. | |
''; | |
}; | |
bindStar = mkOption { | |
type = types.attrsOf types.str; | |
default = {}; | |
example = { "M-<up>" = "drag-stuff-up"; "M-<down>" = "drag-stuff-down"; }; | |
description = '' | |
The entries to use for <option>:bind*</option>. | |
''; | |
}; | |
bindKeyMap = mkOption { | |
type = types.attrsOf types.str; | |
default = {}; | |
example = { "C-c p" = "projectile-command-map"; }; | |
description = '' | |
The entries to use for <option>:bind-keymap</option>. | |
''; | |
}; | |
command = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
The entries to use for <option>:commands</option>. | |
''; | |
}; | |
config = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
Code to place in the <option>:config</option> section. | |
''; | |
}; | |
extraConfig = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
Additional lines to place in the use-package configuration. | |
''; | |
}; | |
general = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
Code to place in the <option>:general</option> section. | |
''; | |
}; | |
hook = mkOption { | |
type = types.listOf types.str; | |
default = []; | |
description = '' | |
The entries to use for <option>:hook</option>. | |
''; | |
}; | |
init = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
The entries to use for <option>:init</option>. | |
''; | |
}; | |
assembly = mkOption { | |
type = types.lines; | |
readOnly = true; | |
internal = true; | |
description = "The final use-package code."; | |
}; | |
}; | |
config = mkIf config.enable { | |
assembly = | |
let | |
quoted = v: ''"${escape ["\""] v}"''; | |
mkBindHelper = cmd: prefix: bs: | |
optionals (bs != {}) ( | |
[ ":${cmd} (${prefix}" ] | |
++ mapAttrsToList (n: v: " (${quoted n} . ${v})") bs | |
++ [ ")" ] | |
); | |
mkAfter = vs: optional (vs != []) ":after (${toString vs})"; | |
mkCommand = vs: optional (vs != []) ":commands (${toString vs})"; | |
mkDiminish = vs: optional (vs != []) ":diminish (${toString vs})"; | |
mkMode = map (v: ":mode ${v}"); | |
mkBind = mkBindHelper "bind" ""; | |
mkBindStar = mkBindHelper "bind*" ""; | |
mkBindLocal = bs: | |
let | |
mkMap = n: v: mkBindHelper "bind" ":map ${n}" v; | |
in | |
flatten (mapAttrsToList mkMap bs); | |
mkBindKeyMap = mkBindHelper "bind-keymap" ""; | |
mkChords = mkBindHelper "chords" ""; | |
mkHook = map (v: ":hook ${v}"); | |
mkDefer = v: | |
if isBool v then optional v ":defer t" | |
else [ ":defer ${toString v}" ]; | |
mkDemand = v: optional v ":demand t"; | |
extraAfter = optional (config.general != "") "general"; | |
in | |
concatStringsSep "\n " ( | |
[ "(use-package ${name}" ] | |
++ mkAfter (config.after ++ extraAfter) | |
++ mkBind config.bind | |
++ mkBindStar config.bindStar | |
++ mkBindKeyMap config.bindKeyMap | |
++ mkBindLocal config.bindLocal | |
++ mkChords config.chords | |
++ mkCommand config.command | |
++ mkDefer config.defer | |
++ mkDemand config.demand | |
++ mkDiminish config.diminish | |
++ mkHook config.hook | |
++ mkMode config.mode | |
++ optionals (config.init != "") [ ":init" config.init ] | |
++ optionals (config.config != "") [ ":config" config.config ] | |
++ optionals (config.general != "") [ ":general" config.general ] | |
++ optional (config.extraConfig != "") config.extraConfig | |
) + ")"; | |
}; | |
}); | |
usePackageStr = name: pkgConfStr: '' | |
(use-package ${name} | |
${pkgConfStr}) | |
''; | |
mkRecommendedOption = type: extraDescription: mkOption { | |
type = types.bool; | |
default = false; | |
example = true; | |
description = '' | |
Whether to enable recommended ${type} settings. | |
'' + optionalString (extraDescription != "") '' | |
</para><para> | |
${extraDescription} | |
''; | |
}; | |
# Recommended GC settings. | |
gcSettings = '' | |
(defun hm/reduce-gc () | |
"Reduce the frequency of garbage collection." | |
(setq gc-cons-threshold 402653184 | |
gc-cons-percentage 0.6)) | |
(defun hm/restore-gc () | |
"Restore the frequency of garbage collection." | |
(setq gc-cons-threshold 16777216 | |
gc-cons-percentage 0.1)) | |
;; Make GC more rare during init and while minibuffer is active. | |
(eval-and-compile #'hm/reduce-gc) | |
(add-hook 'minibuffer-setup-hook #'hm/reduce-gc) | |
;; But make it more regular after startup and after closing minibuffer. | |
(add-hook 'emacs-startup-hook #'hm/restore-gc) | |
(add-hook 'minibuffer-exit-hook #'hm/restore-gc) | |
;; Avoid unnecessary regexp matching while loading .el files. | |
(defvar hm/file-name-handler-alist file-name-handler-alist) | |
(setq file-name-handler-alist nil) | |
(defun hm/restore-file-name-handler-alist () | |
"Restores the file-name-handler-alist variable." | |
(setq file-name-handler-alist hm/file-name-handler-alist) | |
(makunbound 'hm/file-name-handler-alist)) | |
(add-hook 'emacs-startup-hook #'hm/restore-file-name-handler-alist) | |
''; | |
# Whether the configuration makes use of `:diminish`. | |
hasDiminish = any (p: p.diminish != []) (attrValues cfg.usePackage); | |
# Whether the configuration makes use of `:bind`. | |
hasBind = any (p: p.bind != {} || p.bindStar != {}) (attrValues cfg.usePackage); | |
# Whether the configuration makes use of `:chords`. | |
hasChords = any ( p: p.chords != {}) (attrValues cfg.usePackage); | |
# Whether the configuration makes use of `:diminish`. | |
hasGeneral = any (p: p.general != "") (attrValues cfg.usePackage); | |
usePackageSetup = | |
'' | |
(eval-when-compile | |
(require 'package) | |
(setq package-archives nil | |
package-enable-at-startup nil | |
package--init-file-ensured t) | |
(require 'use-package) | |
;; To help fixing issues during startup. | |
(setq use-package-verbose ${ | |
if cfg.usePackageVerbose then "t" else "nil" | |
})) | |
'' | |
+ optionalString hasDiminish '' | |
;; For :diminish in (use-package). | |
(require 'diminish) | |
'' | |
+ optionalString hasBind '' | |
;; For :bind in (use-package). | |
(require 'bind-key) | |
'' | |
+ optionalString hasChords '' | |
;; For :chords in (use-package). | |
(use-package use-package-chords | |
:config (key-chord-mode 1)) | |
'' | |
+ optionalString hasGeneral '' | |
;; For :general in (use-package). | |
(use-package general | |
:config | |
(general-evil-setup)) | |
''; | |
initFile = '' | |
;;; hm-init.el --- Emacs configuration à la Home Manager. | |
;; | |
;; -*- lexical-binding: t; -*- | |
;; | |
;;; Commentary: | |
;; | |
;; A configuration generated from a Nix based configuration by | |
;; Home Manager. | |
;; | |
;;; Code: | |
${optionalString cfg.startupTimer '' | |
;; Remember when configuration started. See bottom for rest of this. | |
;; Idea taken from http://writequit.org/org/settings.html. | |
(defconst emacs-start-time (current-time)) | |
''} | |
${optionalString cfg.recommendedGcSettings gcSettings} | |
${cfg.prelude} | |
${usePackageSetup} | |
'' | |
+ concatStringsSep "\n\n" | |
(map (getAttr "assembly") | |
(filter (getAttr "enable") | |
(attrValues cfg.usePackage))) | |
+ '' | |
${cfg.postlude} | |
${optionalString cfg.startupTimer '' | |
;; Make a note of how long the configuration part of the start took. | |
(let ((elapsed (float-time (time-subtract (current-time) | |
emacs-start-time)))) | |
(message "Loading settings...done (%.3fs)" elapsed)) | |
''} | |
(provide 'hm-init) | |
;; hm-init.el ends here | |
''; | |
in | |
{ | |
options.programs.emacs.init = { | |
enable = mkEnableOption "Emacs configuration"; | |
recommendedGcSettings = mkRecommendedOption "garbage collection" '' | |
This will reduce garbage collection frequency during startup and | |
while the minibuffer is active. | |
''; | |
startupTimer = mkEnableOption "Emacs startup duration timer"; | |
prelude = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
Configuration lines to add in the beginning of | |
<filename>init.el</filename>. | |
''; | |
}; | |
postlude = mkOption { | |
type = types.lines; | |
default = ""; | |
description = '' | |
Configuration lines to add in the end of | |
<filename>init.el</filename>. | |
''; | |
}; | |
usePackageVerbose = mkEnableOption "verbose use-package mode"; | |
usePackage = mkOption { | |
type = types.attrsOf usePackageType; | |
default = {}; | |
example = literalExample '' | |
{ | |
dhall-mode = { | |
mode = [ '''"\\.dhall\\'"''' ]; | |
}; | |
} | |
''; | |
description = '' | |
Attribute set of use-package configurations. | |
''; | |
}; | |
}; | |
config = mkIf (config.programs.emacs.enable && cfg.enable) { | |
programs.emacs.extraPackages = epkgs: | |
let | |
getPkg = v: | |
if isFunction v | |
then [ (v epkgs) ] | |
else optional (isString v && hasAttr v epkgs) epkgs.${v}; | |
packages = | |
concatMap (v: getPkg (v.package)) | |
(builtins.attrValues cfg.usePackage); | |
in | |
[ | |
((epkgs.trivialBuild { | |
pname = "hm-init"; | |
version = "0"; | |
src = pkgs.writeText "hm-init.el" initFile; | |
packageRequires = | |
[ epkgs.use-package ] | |
++ packages | |
++ optional hasBind epkgs.bind-key | |
++ optional hasDiminish epkgs.diminish | |
++ optional hasChords epkgs.use-package-chords | |
++ optional hasGeneral epkgs.general; | |
preferLocalBuild = true; | |
allowSubstitutes = false; | |
}).overrideAttrs (attr: { | |
buildPhase = '' | |
runHook preBuild | |
runHook postBuild | |
''; | |
})) | |
]; | |
home.file.".emacs.d/init.el".text = '' | |
(require 'hm-init) | |
(provide 'init) | |
''; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment