diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix index 2244179..bc771e4 100644 --- a/hosts/desktop/default.nix +++ b/hosts/desktop/default.nix @@ -33,7 +33,7 @@ nixpkgs.lib.nixosSystem { ../../modules/graphical ../../modules/gaming ../../modules/applications - ../../modules/mail/himalaya.nix + ../../modules/mail/default.nix ../../modules/repositories/notes.nix ../../modules/services/keybase.nix ../../modules/services/gnupg.nix diff --git a/modules/mail/aerc.nix b/modules/mail/aerc.nix new file mode 100644 index 0000000..348fe75 --- /dev/null +++ b/modules/mail/aerc.nix @@ -0,0 +1,186 @@ +{ config, pkgs, ... }: { + + config = { + + home-manager.users.${config.user} = { + + home.packages = with pkgs; [ + w3m # Render HTML + dante # Socksify for rendering HTML + ]; + + programs.aerc = { + enable = true; + extraBinds = { + # Binds are of the form = + # To use '=' in a key sequence, substitute it with "Eq": "" + # If you wish to bind #, you can wrap the key sequence in quotes: "#" = quit + global = { + "" = ":prev-tab"; + "" = ":next-tab "; + "" = ":term"; + "?" = ":help keys"; + }; + + messages = { + q = ":quit"; + + j = ":next "; + "" = ":next"; + "" = ":next 50%"; + "" = ":next 100%"; + "" = ":next 100%"; + + k = ":prev "; + "" = ":prev"; + "" = ":prev 50%"; + "" = ":prev 100%"; + "" = ":prev 100%"; + g = ":select 0 "; + G = ":select -1"; + + J = ":next-folder "; + K = ":prev-folder"; + H = ":collapse-folder"; + L = ":expand-folder"; + + v = ":mark -t"; + V = ":mark -v"; + + T = ":toggle-threads"; + + "" = ":view"; + d = ":prompt 'Really delete this message?' 'delete-message'"; + D = ":delete"; + A = ":archive flat"; + + C = ":compose"; + + rr = ":reply -a"; + rq = ":reply -aq"; + Rr = ":reply"; + Rq = ":reply -q"; + + c = ":cf"; + "$" = ":term"; + "!" = ":term"; + "|" = ":pipe"; + + "/" = ":search"; + "\\" = ":filter "; + n = ":next-result"; + N = ":prev-result"; + "" = ":clear"; + }; + + "messages:folder=Drafts" = { "" = ":recall"; }; + + view = { + "/" = ":toggle-key-passthrough /"; + q = ":close"; + O = ":open"; + S = ":save"; + "|" = ":pipe"; + D = ":delete"; + A = ":archive flat"; + + "" = ":open-link "; + + f = ":forward "; + rr = ":reply -a"; + rq = ":reply -aq"; + Rr = ":reply"; + Rq = ":reply -q"; + + H = ":toggle-headers"; + "" = ":prev-part"; + "" = ":next-part"; + J = ":next "; + K = ":prev"; + }; + + "view::passthrough" = { + "$noinherit" = "true"; + "$ex" = ""; + "" = ":toggle-key-passthrough"; + }; + + compose = { + # Keybindings used when the embedded terminal is not selected in the compose + # view + "$noinherit" = "true"; + "$ex" = ""; + "" = ":prev-field"; + "" = ":next-field"; + "" = ":switch-account -p"; + "" = ":switch-account -n"; + "" = ":next-field"; + "" = ":prev-tab"; + "" = ":next-tab"; + }; + + "compose::editor" = { + # Keybindings used when the embedded terminal is selected in the compose view + "$noinherit" = "true"; + "$ex" = ""; + "" = ":prev-field"; + "" = ":next-field"; + "" = ":prev-tab"; + "" = ":next-tab"; + }; + + "compose::review" = { + # Keybindings used when reviewing a message to be sent + y = ":send "; + n = ":abort"; + p = ":postpone"; + q = ":choose -o d discard abort -o p postpone postpone"; + e = ":edit"; + a = ":attach"; + d = ":detach"; + }; + + terminal = { + "$noinherit" = "true"; + "$ex" = ""; + "" = ":prev-tab"; + "" = ":next-tab"; + }; + + }; + extraConfig = { + general.unsafe-accounts-conf = true; + viewer = { pager = "${pkgs.less}/bin/less -R"; }; + filters = { + "text/plain" = + "${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize"; + "text/calendar" = + "${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/calendar"; + "text/html" = + "${pkgs.aerc}/share/aerc/filters/html"; # Requires w3m, dante + # "text/html" = + # "${pkgs.aerc}/share/aerc/filters/html | ${pkgs.aerc}/share/aerc/filters/colorize"; + # "text/*" = + # ''${pkgs.bat}/bin/bat -fP --file-name="$AERC_FILENAME "''; + "message/delivery-status" = + "${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize"; + "message/rfc822" = + "${pkgs.gawk}/bin/awk -f ${pkgs.aerc}/share/aerc/filters/colorize"; + "application/x-sh" = "${pkgs.bat}/bin/bat -fP -l sh"; + }; + }; + }; + accounts.email.accounts.home.aerc = { + enable = true; + extraAccounts = { + check-mail = "1m"; + check-mail-cmd = "${pkgs.isync}/bin/mbsync -a"; + }; + }; + + programs.fish.shellAbbrs = { ae = "aerc"; }; + + }; + + }; +} diff --git a/modules/mail/default.nix b/modules/mail/default.nix new file mode 100644 index 0000000..61a7117 --- /dev/null +++ b/modules/mail/default.nix @@ -0,0 +1,83 @@ +{ config, pkgs, lib, ... }: { + + imports = [ ./himalaya.nix ./aerc.nix ]; + + options = { + mailUser = lib.mkOption { + type = lib.types.str; + description = "User name for the email address."; + default = config.user; + }; + mailServer = lib.mkOption { + type = lib.types.str; + description = "Server name for the email address."; + }; + }; + + config = { + + home-manager.users.${config.user} = { + programs.mbsync = { enable = true; }; + services.mbsync = lib.mkIf pkgs.stdenv.isLinux { + enable = true; + frequency = "*:0/5"; + }; + accounts.email = { + maildirBasePath = "${config.homePath}/mail"; + accounts = { + home = let address = "${config.mailUser}@${config.mailServer}"; + in { + userName = address; + realName = config.fullName; + primary = true; + inherit address; + aliases = map (mailUser: "${mailUser}@${config.mailServer}") [ + "me" + "hey" + "admin" + ]; + alot = { }; + flavor = "plain"; + folders = { }; + getmail = { }; + imap = { + host = "imap.purelymail.com"; + port = 993; + tls.enable = true; + }; + imapnotify = { + enable = false; + boxes = [ ]; + onNotify = ""; + onNotifyPost = ""; + }; + maildir = { path = "main"; }; + mbsync = { + enable = true; + create = "maildir"; + expunge = "none"; + remove = "none"; + patterns = [ "*" ]; + extraConfig.channel = { + CopyArrivalDate = "yes"; # Sync time of original message + }; + }; + mu.enable = false; + notmuch.enable = false; + passwordCommand = + "${pkgs.age}/bin/age --decrypt --identity ${config.identityFile} ${ + builtins.toString ../../private/mailpass.age + }"; + smtp = { + host = "smtp.purelymail.com"; + port = 465; + tls.enable = true; + }; + }; + }; + }; + + }; + + }; +} diff --git a/modules/mail/himalaya.nix b/modules/mail/himalaya.nix index 90dc298..12748d3 100644 --- a/modules/mail/himalaya.nix +++ b/modules/mail/himalaya.nix @@ -1,87 +1,17 @@ -{ config, pkgs, lib, ... }: { - - options = { - mailUser = lib.mkOption { - type = lib.types.str; - description = "User name for the email address."; - default = config.user; - }; - mailServer = lib.mkOption { - type = lib.types.str; - description = "Server name for the email address."; - }; - }; +{ config, ... }: { config = { home-manager.users.${config.user} = { programs.himalaya = { enable = true; }; - programs.mbsync = { enable = true; }; - services.mbsync = lib.mkIf pkgs.stdenv.isLinux { + accounts.email.accounts.home.himalaya = { enable = true; - frequency = "*:0/5"; - }; - - accounts.email = { - maildirBasePath = "${config.homePath}/mail"; - accounts = { - home = let address = "${config.mailUser}@${config.mailServer}"; - in { - userName = address; - realName = config.fullName; - primary = true; - inherit address; - aliases = map (mailUser: "${mailUser}@${config.mailServer}") [ - "me" - "hey" - "admin" - ]; - alot = { }; - flavor = "plain"; - folders = { }; - getmail = { }; - himalaya = { - enable = true; - settings = { - downloads-dir = config.userDirs.download; - smtp-insecure = true; - }; - }; - imap = { - host = "imap.purelymail.com"; - port = 993; - tls.enable = true; - }; - imapnotify = { - enable = false; - boxes = [ ]; - onNotify = ""; - onNotifyPost = ""; - }; - maildir = { path = "main"; }; - mbsync = { - enable = true; - create = "maildir"; - expunge = "none"; - remove = "none"; - patterns = [ "*" ]; - extraConfig.channel = { - CopyArrivalDate = "yes"; # Sync time of original message - }; - }; - mu.enable = false; - notmuch.enable = false; - passwordCommand = - "${pkgs.age}/bin/age --decrypt --identity ${config.identityFile} ${ - builtins.toString ../../private/mailpass.age - }"; - smtp = { - host = "smtp.purelymail.com"; - port = 465; - tls.enable = true; - }; - }; + settings = { + backend = "imap"; + sender = "smtp"; + downloads-dir = config.userDirs.download; + smtp-insecure = true; }; }; diff --git a/modules/neovim/lua/packer/lsp.lua b/modules/neovim/lua/packer/lsp.lua index 74ae245..1a4ccc2 100644 --- a/modules/neovim/lua/packer/lsp.lua +++ b/modules/neovim/lua/packer/lsp.lua @@ -79,6 +79,7 @@ M.packer = function(use) return vim.fn.executable(program) == 1 end + local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) require("null-ls").setup({ sources = { require("null-ls").builtins.formatting.stylua.with({ @@ -132,15 +133,15 @@ M.packer = function(use) -- require("null-ls").builtins.diagnostics.pylint, }, -- Format on save - on_attach = function(client) - if client.server_capabilities.document_formatting then - local id = vim.api.nvim_create_augroup("LspFormatting", { - clear = true, - }) + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) vim.api.nvim_create_autocmd("BufWritePre", { - group = id, - pattern = "*", - callback = vim.lsp.buf.format, + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, }) end end, diff --git a/modules/neovim/lua/packer/misc.lua b/modules/neovim/lua/packer/misc.lua index 014f839..017fef1 100644 --- a/modules/neovim/lua/packer/misc.lua +++ b/modules/neovim/lua/packer/misc.lua @@ -53,10 +53,12 @@ M.packer = function(use) symbols = { " ", "-", "x" }, }, }) - -- Save when moving to new buffer vim.api.nvim_create_autocmd("FileType", { pattern = "markdown", - command = "set autowriteall", + callback = function() + vim.o.autowriteall = true -- Save in new buffer + vim.o.wrapmargin = 79 -- Wrap text automatically + end, }) end, }) diff --git a/modules/neovim/lua/packer/speed.lua b/modules/neovim/lua/packer/speed.lua index 414715e..57222e2 100644 --- a/modules/neovim/lua/packer/speed.lua +++ b/modules/neovim/lua/packer/speed.lua @@ -8,49 +8,6 @@ M.packer = function(use) require("impatient") end, }) - - -- Improve speed and filetype detection - use({ - "nathom/filetype.nvim", - config = function() - -- Filetype for .env files - local envfiletype = function() - vim.bo.filetype = "text" - vim.bo.syntax = "sh" - end - -- Force filetype patterns that Vim doesn't know about - require("filetype").setup({ - overrides = { - extensions = { - Brewfile = "brewfile", - muttrc = "muttrc", - tfvars = "terraform", - tf = "terraform", - }, - literal = { - Caskfile = "brewfile", - [".gitignore"] = "gitignore", - config = "config", - }, - complex = { - [".*git/config"] = "gitconfig", - ["tmux.conf%..*link"] = "tmux", - ["gitconfig%..*link"] = "gitconfig", - [".*ignore%..*link"] = "gitignore", - [".*%.toml%..*link"] = "toml", - }, - function_extensions = {}, - function_literal = { - [".envrc"] = envfiletype, - [".env"] = envfiletype, - [".env.dev"] = envfiletype, - [".env.prod"] = envfiletype, - [".env.example"] = envfiletype, - }, - }, - }) - end, - }) end return M diff --git a/modules/neovim/lua/settings.lua b/modules/neovim/lua/settings.lua index 130d8e2..ef2cec6 100644 --- a/modules/neovim/lua/settings.lua +++ b/modules/neovim/lua/settings.lua @@ -32,8 +32,6 @@ vim.opt.completeopt = { "menuone", "noselect", } --- Required until 0.6.0: do not source the default filetype.vim -vim.g.did_load_filetypes = 1 -- Remember last position when reopening file vim.api.nvim_exec( @@ -77,6 +75,13 @@ vim.api.nvim_exec( false ) +vim.api.nvim_create_autocmd("FileType", { + pattern = "*.eml", + callback = function() + vim.o.wrapmargin = 79 -- Wrap text automatically + end, +}) + -- Netrw vim.g.netrw_liststyle = 3 -- Change style to 'tree' view vim.g.netrw_banner = 0 -- Remove useless banner