base: Finally, some emacs on darwin (and some other stuff I guess)

This commit is contained in:
Charlotte Van Petegem 2024-07-19 11:03:21 +02:00
parent 5467282626
commit 15586a8f7c
81 changed files with 469 additions and 417 deletions

View file

@ -5,6 +5,7 @@ let
in
{
imports = [
./emacs
./nix
];

View file

@ -0,0 +1,21 @@
{ config, pkgs, ... }:
let
username = config.chvp.username;
in
{
chvp.base.emacs.basePackage = pkgs.emacs;
services.emacs = {
enable = true;
package = config.chvp.base.emacs.package;
};
home-manager.users.${username} = {
home.packages = [
(pkgs.writeShellScriptBin "restart-emacs" ''
launchctl unload ~/Library/LaunchAgents/org.nixos.emacs.plist
launchctl load ~/Library/LaunchAgents/org.nixos.emacs.plist
launchctl start ~/Library/LaunchAgents/org.nixos.emacs.plist
'')
];
};
}

View file

@ -7,7 +7,6 @@
./mail
./network
./nix
./phone-push
./smartd
./ssh
./sshd

View file

@ -1,57 +1,18 @@
{ config, lib, pkgs, ... }:
let
username = config.chvp.username;
in
{
options.chvp.base.emacs = {
fullConfig = lib.mkOption {
readOnly = true;
default = builtins.readFile ./base-init.el + (lib.concatStringsSep "\n" config.chvp.base.emacs.extraConfig) + ''
(provide 'init)
;;; init.el ends here
'';
};
extraConfig = lib.mkOption {
default = [ ];
};
package = lib.mkOption {
readOnly = true;
default = pkgs.emacsWithPackagesFromUsePackage {
config = config.chvp.base.emacs.fullConfig;
package = pkgs.emacs-pgtk;
alwaysEnsure = true;
extraEmacsPackages = epkgs: lib.optional config.chvp.graphical.mail.enable epkgs.mu4e;
};
};
chvp.base.emacs = {
basePackage = pkgs.emacs-pgtk;
};
config = {
chvp.base.zfs.homeLinks = [
{ path = ".cache/emacs"; type = "cache"; }
];
services.languagetool = {
home-manager.users.${username} = { ... }: {
services.emacs = {
enable = true;
port = 15151;
settings.cacheSize = 10000;
};
home-manager.users.charlotte = { ... }: {
services.emacs = {
enable = true;
client.enable = true;
socketActivation.enable = true;
package = config.chvp.base.emacs.package;
};
home = {
packages = [
(pkgs.writeShellScriptBin "emacs" ''${config.chvp.base.emacs.package}/bin/emacsclient -c "$@"'')
(pkgs.writeShellScriptBin "emacsclient" ''${config.chvp.base.emacs.package}/bin/emacsclient "$@"'')
];
sessionVariables = { EDITOR = "emacs"; };
};
xdg.configFile = {
"emacs/init.el".text = config.chvp.base.emacs.fullConfig;
"emacs/early-init.el".source = ./early-init.el;
};
client.enable = true;
socketActivation.enable = true;
package = config.chvp.base.emacs.package;
};
};
}

View file

@ -0,0 +1,21 @@
(use-package emacs-on-linux
:ensure nil ;; Not a real package, but a place to collect global settings for linux
:demand t
:config
;; Font configuration
(defun font-settings ()
"Setup font settings."
(when window-system (set-frame-font "Hack 9"))
(set-fontset-font t 'symbol "Noto Color Emoji")
(set-fontset-font t 'symbol "Symbola" nil 'append))
;; Make sure DISPLAY is set correctly in env.
(defun display-env-hack ()
"Hack DISPLAY env variable back into env."
(setenv "DISPLAY" ":0")
)
(if (daemonp)
(progn
(add-hook 'server-after-make-frame-hook #'font-settings)
(add-hook 'server-after-make-frame-hook #'display-env-hack))
(font-settings))
)

View file

@ -1,20 +1,5 @@
{ config, lib, pkgs, ... }:
{
chvp.base = {
emacs.extraConfig = [
''
;; Nix syntax support
(use-package nix-mode
:mode "\\.nix\\'"
)
''
] ++ lib.optional config.chvp.base.nix.enableDirenv ''
;; Direnv integration in emacs.
(use-package direnv
:config (direnv-mode)
)
'';
};
nix.gc.dates = if config.chvp.base.nix.slowGc then "daily" else "hourly";
programs.command-not-found.enable = false;
}

View file

@ -1,22 +1,5 @@
{ ... }:
let
base = {
programs.tmux = {
enable = true;
clock24 = true;
extraConfig = ''
bind q kill-session
bind v run-shell "tmux setw main-pane-width $(($(tmux display -p '#{window_width}') * 70 / 100)); tmux select-layout main-vertical"
bind h run-shell "tmux setw main-pane-height $(($(tmux display -p '#{window_height}') * 70 / 100)); tmux select-layout main-horizontal"
set -g default-terminal "screen-256color"
set -sg escape-time 10
'';
keyMode = "vi";
};
};
in
{
home-manager.users.charlotte = { ... }: base;
home-manager.users.root = { ... }: base;
chvp.base.tmux.usersToConfigure = [ "charlotte" "root" ];
}

View file

@ -93,120 +93,123 @@ in
];
chvp = {
base = {
emacs.extraConfig =
let
mkAccountConfig = account: ''
(make-mu4e-context
:name "${account.name}"
:match-func (lambda (msg) (when msg (string-prefix-p "/${account.maildir.path}/" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "${account.address}")
(user-full-name . "${account.realName}")
(mu4e-drafts-folder . "/${account.maildir.path}/${account.folders.drafts}")
(mu4e-sent-folder . "/${account.maildir.path}/${account.folders.sent}")
(mu4e-refile-folder . "/${account.maildir.path}/${account.folders.trash}")
(mu4e-trash-folder . "/${account.maildir.path}/${account.folders.trash}")
(message-sendmail-extra-arguments . ("--read-envelope-from" "--account" "${account.name}"))
)
)
'';
hmConfig = config.home-manager.users.charlotte;
in
[
''
(use-package mu4e
;; Use mu4e included in the mu package, see emacs/default.nix
:ensure nil
:demand t
:after (vertico)
:hook
(mu4e-view-mode . display-line-numbers-mode)
(mu4e-view-mode . visual-line-mode)
(mu4e-compose-mode . chvp--mu4e-auto-dodona-cc-reply-to)
(mu4e-compose-mode . visual-line-mode)
(mu4e-compose-mode . (lambda () (setq use-hard-newlines nil)))
:custom
(mu4e-read-option-use-builtin nil "Don't use builtin autocomplete in mu4e")
(mu4e-completing-read-function 'completing-read "Use default completing read function")
(mu4e-maildir-initial-input "" "Don't have initial input when completing a maildir")
(mu4e-change-filenames-when-moving t "Avoid sync issues with mbsync")
(mu4e-maildir "${hmConfig.accounts.email.maildirBasePath}" "Root of the maildir hierarchy")
(mu4e-context-policy 'pick-first "Use the first mail context in the list")
(mu4e-attachment-dir "/home/charlotte/downloads/" "Save attachments to downloads folder")
(mu4e-compose-dont-reply-to-self t "Don't reply to myself on reply to all")
(mu4e-compose-format-flowed t "Send format=flowed mails when use-hard-newlines gets enabled")
(fill-flowed-display-column 1000000000000 "Dont fill when decoding flowed messages, let visual-line-mode handle it")
(gnus-treat-fill-long-lines nil "Let visual-line-mode handle filling")
(mu4e-confirm-quit nil "Don't confirm when quitting")
(mu4e-headers-include-related nil "Don't show related messages by default")
(mu4e-headers-skip-duplicates nil "Show duplicate emails")
(message-kill-buffer-on-exit t "Close buffer when finished with email")
(mm-verify-option 'known "Always verify PGP signatures (known protocols)")
(mm-discouraged-alternatives '("text/html" "text/richtext") "Discourage showing HTML views")
(gnus-buttonized-mime-types '("multipart/signed") "Make sure signature verification is always shown")
(mml-secure-openpgp-sign-with-sender t "Sign mails with the sender")
(sendmail-program "msmtp" "Use msmtp to send email")
(message-sendmail-f-is-evil t "Remove username from the emacs message")
(message-send-mail-function 'message-send-mail-with-sendmail "Use sendmail to send mail instead internal smtp")
(message-cite-reply-position 'below "Bottom posting is the correct way to reply to email")
:config
;; mu4e should just open in the currently focused window instead of taking up the whole frame
(add-to-list 'display-buffer-alist
`(,(regexp-quote mu4e-main-buffer-name)
display-buffer-same-window))
(setq mu4e-contexts (list ${lib.concatStringsSep "\n" (map mkAccountConfig (lib.attrValues hmConfig.accounts.email.accounts))}))
(add-to-list
'mu4e-bookmarks
'(:name "Combined inbox" :query "maildir:/personal/INBOX or maildir:/posteo/INBOX or maildir:/rodekruis-eerstehulp/INBOX" :key ?i :favorite t)
emacs = {
extraPackages = [ (epkgs: epkgs.mu4e) ];
extraConfig =
let
mkAccountConfig = account: ''
(make-mu4e-context
:name "${account.name}"
:match-func (lambda (msg) (when msg (string-prefix-p "/${account.maildir.path}/" (mu4e-message-field msg :maildir))))
:vars '(
(user-mail-address . "${account.address}")
(user-full-name . "${account.realName}")
(mu4e-drafts-folder . "/${account.maildir.path}/${account.folders.drafts}")
(mu4e-sent-folder . "/${account.maildir.path}/${account.folders.sent}")
(mu4e-refile-folder . "/${account.maildir.path}/${account.folders.trash}")
(mu4e-trash-folder . "/${account.maildir.path}/${account.folders.trash}")
(message-sendmail-extra-arguments . ("--read-envelope-from" "--account" "${account.name}"))
)
)
(defun chvp--mu4e-dodona-cc-reply-to ()
"Add dodona@ugent.be in cc and reply-to headers."
(interactive)
(save-excursion (message-add-header "Cc: dodona@ugent.be\nReply-To: dodona@ugent.be\n"))
)
(defun chvp--mu4e-auto-dodona-cc-reply-to ()
"Set dodona@ugent.be in CC and Reply-To headers when message was directed to dodona@ugent.be"
(let ((msg mu4e-compose-parent-message))
(when (and msg (mu4e-message-contact-field-matches msg :to "dodona@ugent.be")) (chvp--mu4e-dodona-cc-reply-to))
'';
hmConfig = config.home-manager.users.charlotte;
in
[
''
(use-package mu4e
;; Use mu4e included in the mu package, see emacs/default.nix
:ensure nil
:demand t
:after (vertico)
:hook
(mu4e-view-mode . display-line-numbers-mode)
(mu4e-view-mode . visual-line-mode)
(mu4e-compose-mode . chvp--mu4e-auto-dodona-cc-reply-to)
(mu4e-compose-mode . visual-line-mode)
(mu4e-compose-mode . (lambda () (setq use-hard-newlines nil)))
:custom
(mu4e-read-option-use-builtin nil "Don't use builtin autocomplete in mu4e")
(mu4e-completing-read-function 'completing-read "Use default completing read function")
(mu4e-maildir-initial-input "" "Don't have initial input when completing a maildir")
(mu4e-change-filenames-when-moving t "Avoid sync issues with mbsync")
(mu4e-maildir "${hmConfig.accounts.email.maildirBasePath}" "Root of the maildir hierarchy")
(mu4e-context-policy 'pick-first "Use the first mail context in the list")
(mu4e-attachment-dir "/home/charlotte/downloads/" "Save attachments to downloads folder")
(mu4e-compose-dont-reply-to-self t "Don't reply to myself on reply to all")
(mu4e-compose-format-flowed t "Send format=flowed mails when use-hard-newlines gets enabled")
(fill-flowed-display-column 1000000000000 "Dont fill when decoding flowed messages, let visual-line-mode handle it")
(gnus-treat-fill-long-lines nil "Let visual-line-mode handle filling")
(mu4e-confirm-quit nil "Don't confirm when quitting")
(mu4e-headers-include-related nil "Don't show related messages by default")
(mu4e-headers-skip-duplicates nil "Show duplicate emails")
(message-kill-buffer-on-exit t "Close buffer when finished with email")
(mm-verify-option 'known "Always verify PGP signatures (known protocols)")
(mm-discouraged-alternatives '("text/html" "text/richtext") "Discourage showing HTML views")
(gnus-buttonized-mime-types '("multipart/signed") "Make sure signature verification is always shown")
(mml-secure-openpgp-sign-with-sender t "Sign mails with the sender")
(sendmail-program "msmtp" "Use msmtp to send email")
(message-sendmail-f-is-evil t "Remove username from the emacs message")
(message-send-mail-function 'message-send-mail-with-sendmail "Use sendmail to send mail instead internal smtp")
(message-cite-reply-position 'below "Bottom posting is the correct way to reply to email")
:config
;; mu4e should just open in the currently focused window instead of taking up the whole frame
(add-to-list 'display-buffer-alist
`(,(regexp-quote mu4e-main-buffer-name)
display-buffer-same-window))
(setq mu4e-contexts (list ${lib.concatStringsSep "\n" (map mkAccountConfig (lib.attrValues hmConfig.accounts.email.accounts))}))
(add-to-list
'mu4e-bookmarks
'(:name "Combined inbox" :query "maildir:/personal/INBOX or maildir:/posteo/INBOX or maildir:/rodekruis-eerstehulp/INBOX" :key ?i :favorite t)
)
(defun chvp--mu4e-dodona-cc-reply-to ()
"Add dodona@ugent.be in cc and reply-to headers."
(interactive)
(save-excursion (message-add-header "Cc: dodona@ugent.be\nReply-To: dodona@ugent.be\n"))
)
(defun chvp--mu4e-auto-dodona-cc-reply-to ()
"Set dodona@ugent.be in CC and Reply-To headers when message was directed to dodona@ugent.be"
(let ((msg mu4e-compose-parent-message))
(when (and msg (mu4e-message-contact-field-matches msg :to "dodona@ugent.be")) (chvp--mu4e-dodona-cc-reply-to))
)
)
;; Never actually quit mu4e, just close the current buffer (making sure the modeline is still visible)
(defalias 'mu4e-quit 'chvp--kill-current-buffer)
(define-advice mu4e--context-ask-user
(:around (orig-fun &rest args) mu4e--context-ask-user-completing-read)
"Replace `mu4e-read-option` by general-purpose completing-read"
(cl-letf (((symbol-function 'mu4e-read-option)
(lambda (prompt options)
(let* ((prompt (mu4e-format "%s" prompt))
(choice (completing-read prompt (cl-mapcar #'car options) nil t))
(chosen-el (cl-find-if (lambda (option) (equal choice (car option))) options)))
(if chosen-el
(cdr chosen-el)
(mu4e-warn "Unknown option: '%s'" choice))))))
(apply orig-fun args)))
(mu4e 'background)
:general
(lmap "m" '(mu4e :which-key "mail"))
;; Unmap SPC in the mail view so we can still use the leader.
(lmap mu4e-view-mode-map "" nil)
(lmap mu4e-compose-mode-map
"SPC s" '(mml-secure-message-sign-pgpmime :which-key "Sign")
"SPC c" '(mml-secure-message-encrypt-pgpmime :which-key "Encrypt")
"SPC d" '(chvp--mu4e-dodona-cc-reply-to :which-key "Dodona support headers")
"SPC f" '(mu4e-toggle-use-hard-newlines :which-key "Toggle format=flowed/hard newlines")
)
)
;; Never actually quit mu4e, just close the current buffer (making sure the modeline is still visible)
(defalias 'mu4e-quit 'chvp--kill-current-buffer)
(define-advice mu4e--context-ask-user
(:around (orig-fun &rest args) mu4e--context-ask-user-completing-read)
"Replace `mu4e-read-option` by general-purpose completing-read"
(cl-letf (((symbol-function 'mu4e-read-option)
(lambda (prompt options)
(let* ((prompt (mu4e-format "%s" prompt))
(choice (completing-read prompt (cl-mapcar #'car options) nil t))
(chosen-el (cl-find-if (lambda (option) (equal choice (car option))) options)))
(if chosen-el
(cdr chosen-el)
(mu4e-warn "Unknown option: '%s'" choice))))))
(apply orig-fun args)))
(mu4e 'background)
:general
(lmap "m" '(mu4e :which-key "mail"))
;; Unmap SPC in the mail view so we can still use the leader.
(lmap mu4e-view-mode-map "" nil)
(lmap mu4e-compose-mode-map
"SPC s" '(mml-secure-message-sign-pgpmime :which-key "Sign")
"SPC c" '(mml-secure-message-encrypt-pgpmime :which-key "Encrypt")
"SPC d" '(chvp--mu4e-dodona-cc-reply-to :which-key "Dodona support headers")
"SPC f" '(mu4e-toggle-use-hard-newlines :which-key "Toggle format=flowed/hard newlines")
)
(use-package visual-fill-column
:custom (visual-fill-column-enable-sensible-window-split t "Sensibly split windows in visual-fill-column-mode")
:hook (visual-line-mode . visual-fill-column-mode)
)
(use-package visual-fill-column
:custom (visual-fill-column-enable-sensible-window-split t "Sensibly split windows in visual-fill-column-mode")
:hook (visual-line-mode . visual-fill-column-mode)
)
(use-package adaptive-wrap
:hook (visual-fill-column-mode . adaptive-wrap-prefix-mode)
)
''
];
(use-package adaptive-wrap
:hook (visual-fill-column-mode . adaptive-wrap-prefix-mode)
)
''
];
};
zfs.homeLinks = [
{ path = "mail"; type = "data"; }
{ path = ".cache/mu"; type = "cache"; }

View file

@ -2,7 +2,10 @@
{
imports = [
./emacs
./nix
./phone-push
./tmux
./zfs
./zsh
];

View file

@ -180,23 +180,6 @@
(project-vc-merge-submodules nil "Don't consider submodules as the same project")
:config
;; Font configuration
(defun font-settings ()
"Setup font settings."
(when window-system (set-frame-font "Hack 9"))
(set-fontset-font t 'symbol "Noto Color Emoji")
(set-fontset-font t 'symbol "Symbola" nil 'append))
;; Make sure DISPLAY is set correctly in env.
(defun display-env-hack ()
"Hack DISPLAY env variable back into env."
(setenv "DISPLAY" ":0")
)
(if (daemonp)
(progn
(add-hook 'server-after-make-frame-hook #'font-settings)
(add-hook 'server-after-make-frame-hook #'display-env-hack))
(font-settings))
;; Always display column number in mode line
(column-number-mode)
)
@ -208,12 +191,6 @@
:diminish (flycheck-mode)
)
(use-package flycheck-languagetool
:hook (text-mode . flycheck-languagetool-setup)
:custom
(flycheck-languagetool-url "http://localhost:15151")
)
;; Annotations in selection interface
(use-package marginalia
:after (vertico)
@ -291,9 +268,6 @@
)
)
;; Citations with citeproc in org
(use-package citeproc)
;; Sorting when filtering
(use-package prescient
:custom
@ -321,7 +295,7 @@
:demand t
:after cape
;; This is not very nice, but let's just assume that development machines have my nixos-config checked out
:custom (tempel-path "/home/charlotte/repos/nixos-config/modules/base/emacs/snippets/*.eld")
:custom (tempel-path "~/repos/nixos-config/modules/shared/base/emacs/snippets/*.eld")
:general
(lmap
"t i" '(tempel-insert :which-key "Insert template")

View file

@ -0,0 +1,54 @@
{ config, lib, pkgs, ... }:
let
username = config.chvp.username;
in
{
options.chvp.base.emacs = {
basePackage = lib.mkOption {
example = pkgs.emacs.pgtk;
};
extraConfig = lib.mkOption {
default = [ ];
};
extraPackages = lib.mkOption {
default = [ ];
};
fullConfig = lib.mkOption {
readOnly = true;
default = builtins.readFile ./base-init.el + (lib.concatStringsSep "\n" config.chvp.base.emacs.extraConfig) + ''
(provide 'init)
;;; init.el ends here
'';
};
package = lib.mkOption {
readOnly = true;
default = pkgs.emacsWithPackagesFromUsePackage {
config = config.chvp.base.emacs.fullConfig;
package = config.chvp.base.emacs.basePackage;
alwaysEnsure = true;
extraEmacsPackages = epkgs: builtins.foldl' (xs: ys: xs ++ ys) [ ] (builtins.map (fun: (fun epkgs)) config.chvp.base.emacs.extraPackages);
};
};
};
config = {
chvp.base.zfs.homeLinks = [
{ path = ".cache/emacs"; type = "cache"; }
];
home-manager.users.${username} = { ... }: {
home = {
file = {
".emacs.d/init.el".text = config.chvp.base.emacs.fullConfig;
".emacs.d/early-init.el".source = ./early-init.el;
};
packages = [
(pkgs.writeShellScriptBin "emacs" ''${config.chvp.base.emacs.package}/bin/emacsclient -c "$@"'')
(pkgs.writeShellScriptBin "emacsclient" ''${config.chvp.base.emacs.package}/bin/emacsclient "$@"'')
];
sessionVariables = { EDITOR = "emacs"; };
};
};
};
}

View file

@ -36,7 +36,22 @@ in
};
config = {
chvp.base.zfs.homeLinks = (lib.optional config.chvp.base.nix.enableDirenv { path = ".local/share/direnv"; type = "cache"; });
chvp.base = {
emacs.extraConfig = [
''
;; Nix syntax support
(use-package nix-mode
:mode "\\.nix\\'"
)
''
] ++ lib.optional config.chvp.base.nix.enableDirenv ''
;; Direnv integration in emacs.
(use-package direnv
:config (direnv-mode)
)
'';
zfs.homeLinks = (lib.optional config.chvp.base.nix.enableDirenv { path = ".local/share/direnv"; type = "cache"; });
};
nix = {
gc = {
automatic = true;

View file

@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
let
username = config.chvp.username;
phone-push = pkgs.writeShellScriptBin "phone-push" ''
curl $(cat ${config.age.secrets."files/services/phone-push-url".path}) -d "$(hostname): $@"
'';
@ -10,6 +11,6 @@ in
age.secrets."files/services/phone-push-url" = {
file = ../../../../secrets/files/services/phone-push-url.age;
owner = "charlotte";
owner = username;
};
}

View file

@ -0,0 +1,29 @@
{ config, lib, ... }:
let
username = config.chvp.username;
base = {
programs.tmux = {
enable = true;
clock24 = true;
extraConfig = ''
bind q kill-session
bind v run-shell "tmux setw main-pane-width $(($(tmux display -p '#{window_width}') * 70 / 100)); tmux select-layout main-vertical"
bind h run-shell "tmux setw main-pane-height $(($(tmux display -p '#{window_height}') * 70 / 100)); tmux select-layout main-horizontal"
set -g default-terminal "screen-256color"
set -sg escape-time 10
'';
keyMode = "vi";
};
};
in
{
options.chvp.base.tmux.usersToConfigure = lib.mkOption {
default = [ username ];
};
config.home-manager.users = builtins.foldl' (a: b: a // b) { } (
builtins.map (name: { "${name}" = base; }) config.chvp.base.tmux.usersToConfigure
);
}