From 736c6277951428fa0d9f4343fcb0c2da20ead074 Mon Sep 17 00:00:00 2001 From: Julien Malka Date: Fri, 10 Dec 2021 14:54:42 +0100 Subject: [PATCH] Added newton config --- config/home/nvim/nvim.nix | 5 - configuration.nix | 2 +- home-manager-modules/mails/afewconfig | 90 ++++++++ home-manager-modules/mails/default.nix | 73 +++++++ home-manager-modules/mails/neomuttrc | 83 +++++++ home-manager-modules/neovim/default.nix | 72 +++++++ .../neovim/lua/galaxyline.lua | 204 ++++++++++++++++++ home-manager-modules/neovim/lua/lsp.lua | 76 +++++++ home-manager-modules/neovim/lua/nvim-tree.lua | 60 ++++++ home-manager-modules/neovim/lua/settings.lua | 96 +++++++++ machines/newton.nix | 169 +++++++++++++++ modules/zfs-mails/default.nix | 106 +++++++++ utils.nix | 2 - 13 files changed, 1030 insertions(+), 8 deletions(-) create mode 100644 home-manager-modules/mails/afewconfig create mode 100644 home-manager-modules/mails/default.nix create mode 100644 home-manager-modules/mails/neomuttrc create mode 100644 home-manager-modules/neovim/default.nix create mode 100755 home-manager-modules/neovim/lua/galaxyline.lua create mode 100755 home-manager-modules/neovim/lua/lsp.lua create mode 100755 home-manager-modules/neovim/lua/nvim-tree.lua create mode 100644 home-manager-modules/neovim/lua/settings.lua create mode 100644 machines/newton.nix create mode 100644 modules/zfs-mails/default.nix diff --git a/config/home/nvim/nvim.nix b/config/home/nvim/nvim.nix index 7cf138b..df5ea1c 100755 --- a/config/home/nvim/nvim.nix +++ b/config/home/nvim/nvim.nix @@ -1,8 +1,3 @@ -# This is my configuration file for neovim. -# I've written it in nix for ease of use with home-manager, -# but there are several vimscript and lua files imported as well. -# If you want more help understanding or modifying these configurations, -# please submit an issue on Github or contact me on Discord 'notusknot#5622' { pkgs, config, ... }: let dusk-vim = pkgs.vimUtils.buildVimPlugin { diff --git a/configuration.nix b/configuration.nix index 0ee5693..97c5c70 100644 --- a/configuration.nix +++ b/configuration.nix @@ -29,7 +29,7 @@ shell = pkgs.fish; }; - boot.kernelPackages = pkgs.linuxPackages_latest; + #boot.kernelPackages = pkgs.linuxPackages_latest; services.openssh.enable = true; diff --git a/home-manager-modules/mails/afewconfig b/home-manager-modules/mails/afewconfig new file mode 100644 index 0000000..80b737a --- /dev/null +++ b/home-manager-modules/mails/afewconfig @@ -0,0 +1,90 @@ + + +[Filter.1] +query = subject:"Formulaire d'externement" +tags = +externement +message = Externement + + +[Filter.2] +query = subject:/\[DG\]/ +tags = +dg +message = Mail pour la DG + +[Filter.3] +query = subject:"Demande de malle" +tags = +malle +message = Malle + +[Filter.4] +query = subject:"Demande d'inscription de" +tags = +thurnage +message = Thurnage + +[Filter.5] +query = subject:"Formulaire situation de" +tags = +situation +message = Situation + +[Filter.6] +query = subject:"Inscription au thurnage général de" +tags = +thurnage +message = TG + +[Filter.7] +query = subject:"Prévision d'externement de" +tags = +externement +message = previsionext + +[Filter.8] +query = subject:"Demande d'accès" +tags = +malle +message = acces + +[Filter.9] +query = subject:"Rendu de malle" +tags = +malle +message = rendu + +[Filter.10] +query = subject:"Prolongation de la malle" +tags = +malle +message = prolong + +[Filter.11] +query = subject:"Fermeture de l'internat" +tags = +fermeture +message = fermeture + +[Filter.12] +query = subject:/\[COF\]/ +tags = +cof +message = COF + +[Filter.13] +query = subject:"Modification inscription TG" +tags= +thurnage + +[Filter.14] +query = subject:/\[Pouët-Pouêt\]/ +tags = +fanfare +message = fanfare + +[Filter.15] +query = subject:/\[K-Fêt\]/ +tags = +kfet +message = kfet + +[Filter.16] +query = subject:/\[Chef.fe.s\]/ +tags = +chefs +message = chefs + + +[InboxFilter] + +[MailMover] +folders = ens/INBOX ens/DG +rename = True +ens/INBOX = 'tag:dg':ens/DG 'tag:COF':ens/COF 'tag:fanfare':ens/Fanfare 'tag:kfet':ens/K-Fet 'tag:chefs':ens/K-Fet/Chefs +ens/DG = 'tag:externement':ens/DG/Externements 'tag:malle':ens/DG/Malles 'tag:thurnage':ens/DG/Thurnages 'tag:situation':ens/DG/Situations 'tag:fermeture':ens/DG/Fermeture diff --git a/home-manager-modules/mails/default.nix b/home-manager-modules/mails/default.nix new file mode 100644 index 0000000..d60f5f9 --- /dev/null +++ b/home-manager-modules/mails/default.nix @@ -0,0 +1,73 @@ +{ pkgs, config, lib, ... }: +let + cfg = config.luj.emails; +in +with lib; +{ + options.luj.emails = { + enable = mkEnableOption "enable mail management"; + backend.enable = mkEnableOption "enable filtering backend"; + }; + + + config = mkMerge [ + (mkIf cfg.enable { + programs.mbsync.enable = true; + programs.neomutt.enable = true; + programs.msmtp.enable = true; + accounts.email = { + accounts.ens = { + address = "julien.malka@ens.fr"; + imap.host = "clipper.ens.fr"; + mbsync = { + enable = true; + create = "maildir"; + extraConfig.channel = { + "CopyArrivalDate" = "yes"; + }; + }; + msmtp.enable = true; + primary = true; + realName = "Julien Malka"; + passwordCommand = "${pkgs.gnupg}/bin/gpg -q --batch --passphrase-file /home/julien/email-passphrase -d ${./ens.pass.gpg}"; + smtp = { + host = "clipper.ens.fr"; + }; + userName = "jmalka"; + }; + }; + services.mbsync = { + enable = true; + frequency = "*-*-* *:*:00"; + verbose = false; + }; + xdg.configFile = { + "neomutt/neomuttrc".source = lib.mkForce ./neomuttrc; + }; + + + }) + + (mkIf (cfg.enable && cfg.backend.enable) { + programs.afew.enable = true; + accounts.email.accounts.ens.notmuch.enable = true; + services.mbsync.postExec = "${pkgs.notmuch}/bin/notmuch new"; + programs.notmuch = { + enable = true; + new.tags = [ "new" ]; + hooks.postNew = '' + ${pkgs.afew}/bin/afew --tag --new + ${pkgs.afew}/bin/afew --move-mails + ''; + }; + xdg.configFile = { + "afew/config".source = lib.mkForce ./afewconfig; + }; + + + }) + + + ]; + +} diff --git a/home-manager-modules/mails/neomuttrc b/home-manager-modules/mails/neomuttrc new file mode 100644 index 0000000..1957994 --- /dev/null +++ b/home-manager-modules/mails/neomuttrc @@ -0,0 +1,83 @@ +set from = "julien.malka@ens.fr" + +# Nom complet de l'expéditeur +set realname = "Julien Malka" + +# Génération du champs from +set use_from = yes + +set edit_headers=yes +set reverse_name +set mark_old=no +set editor = "nvim -c 'set tw=72' -c 'set wrap'" +#set editor="vim +':set textwidth=0' +':set wrapmargin=0' +':set wrap'" +#set wrap="72" +set folder = ~/Maildir/ens + +set mbox_type=Maildir +set virtual_spoolfile=yes +set header_cache=~/.cache/mutt +set sidebar_visible = yes +set record = "+Sent\ Messages" +#mailboxes =Inbox =DG =DG/Malles =DG/Externements =DG/Thurnages =DG/Situations =DG/Fermeture =Sent\ Messages +#named-mailboxes "Malles" =DG/Malles +#named-mailboxes "Externements" =DG/Externements +#named-mailboxes "Thurnages" =DG/Thurnages +#named-mailboxes "Situations" =DG/Situations +#named-mailboxes "Fermeture" =DG/Fermeture +#named-mailboxes "Sent" =Sent\ Messages +set nm_unread_tag = unread +set mail_check_stats=yes +set sidebar_short_path = yes + + +set timeout=10 +set mail_check=10 +virtual-mailboxes "Inbox" "notmuch://?query=tag:inbox and NOT tag:dg and NOT tag:cof and NOT tag:fanfare and NOT tag:kfet and NOT tag:chefs" +virtual-mailboxes "K-Fêt" "notmuch://?query=tag:kfet" +virtual-mailboxes "Chefs" "notmuch://?query=tag:chefs" +virtual-mailboxes "DG" "notmuch://?query=tag:dg and NOT tag:externement and NOT tag:fermeture and NOT tag:malle and NOT tag:situation and NOT tag:thurnage" +virtual-mailboxes "Externements" "notmuch://?query=tag:externement" +virtual-mailboxes "Fermeture" "notmuch://?query=tag:fermeture" +virtual-mailboxes "Malles" "notmuch://?query=tag:malle" +virtual-mailboxes "Situations" "notmuch://?query=tag:situation" +virtual-mailboxes "Thurnages" "notmuch://?query=tag:thurnage" +virtual-mailboxes "Fanfare" "notmuch://?query=tag:fanfare" + +set sidebar_width=15 +set sidebar_divider_char='|' +# color of folders with new mail +# ctrl-n, ctrl-p to select next, prev folder# ctrl-o to open selected folder +bind index \CP sidebar-prev +bind index \CN sidebar-next +bind index \CO sidebar-open +bind pager \CP sidebar-prev +bind pager \CN sidebar-next +bind pager \CO sidebar-open +bind pager previous-line +set nm_default_url = "notmuch:///home/julien/Maildir" + +macro index \\ "" +set metoo=yes + +set text_flowed + +set collapse_unread = no +set collapse_all = yes + +bind index - collapse-thread + + + +set sort = threads +set sort_aux = reverse-last-date-received + +folder-hook . 'source /home/julien/dotfiles/profile.default' +folder-hook "DG" 'source /home/julien/dotfiles/profile.dg' +folder-hook "K-Fêt" 'source /home/julien/dotfiles/profile.kfet' +folder-hook "Chefs" 'source /home/julien/dotfiles/profile.chefs' +set sidebar_format = '%D%* %?N?(%N)?%*' +color sidebar_unread yellow default + +source ~/dotfiles/dracula.muttrc +set sendmail = "msmtp" diff --git a/home-manager-modules/neovim/default.nix b/home-manager-modules/neovim/default.nix new file mode 100644 index 0000000..212bc77 --- /dev/null +++ b/home-manager-modules/neovim/default.nix @@ -0,0 +1,72 @@ +{ pkgs, lib, config, ... }: +let + cfg = config.luj.programs.neovim; + dusk-vim = pkgs.vimUtils.buildVimPlugin { + name = "dusk-vim"; + src = pkgs.fetchFromGitHub { + owner = "notusknot"; + repo = "dusk-vim"; + rev = "8eb71f092ebfa173a6568befbe522a56e8382756"; + sha256 = "09l4hda5jnyigc2hhlirv1rc8hsnsc4zgcv4sa4br8fryi73nf4g"; + }; + }; + +in +with lib; +{ + options.luj.programs.neovim = { + enable = mkEnableOption "activate neovim program"; + }; + + config = mkIf cfg.enable{ + programs.neovim = { + enable = true; + package = pkgs.neovim-unwrapped; + plugins = with pkgs.vimPlugins; [ + # File tree + nvim-web-devicons + nvim-tree-lua + # LSP + nvim-lspconfig + # Languages + vim-nix + + # Eyecandy + nvim-treesitter + bufferline-nvim + galaxyline-nvim + nvim-colorizer-lua + pears-nvim + dusk-vim + + # Lsp and completion + nvim-lspconfig + nvim-compe + + # Telescope + telescope-nvim + + # Indent lines + indent-blankline-nvim + ]; + extraPackages = with pkgs; [ + gcc + rnix-lsp + tree-sitter + sumneko-lua-language-server + ]; + extraConfig = '' + luafile ${./lua}/lsp.lua + luafile ${./lua}/nvim-tree.lua + luafile ${./lua}/galaxyline.lua + luafile ${./lua}/settings.lua + ''; + }; +}; + +} + + + + + diff --git a/home-manager-modules/neovim/lua/galaxyline.lua b/home-manager-modules/neovim/lua/galaxyline.lua new file mode 100755 index 0000000..06f6eb0 --- /dev/null +++ b/home-manager-modules/neovim/lua/galaxyline.lua @@ -0,0 +1,204 @@ + -- This file configures galaxyline, a fast and small statusline for nvim. + -- The configuration was taken from github.com/siduck76/neovim-dotfiles/ + -- All I did was change the colors. Full credit goes to siduck76 + +local gl = require("galaxyline") +local gls = gl.section + +gl.short_line_list = {" "} -- keeping this table { } as empty will show inactive statuslines + +local colors = { + bg = "#2e303e", + line_bg = "#2e303e", + fg = "#e3e6ee", + green = "#29d398", + orange = "#efb993", + red = "#e95678", + lightbg = "#2e303e", + lightbasdfg = "#393b4d", + nord = "#9699b7", + greenYel = "#efb993" +} + +gls.left[1] = { + leftRounded = { + provider = function() + return " " + end, + highlight = {colors.nord, colors.bg} + } +} + +gls.left[2] = { + statusIcon = { + provider = function() + return "  " + end, + highlight = {colors.fg, colors.bg}, + separator = " ", + separator_highlight = {colors.lightbg, colors.lightbg} + } +} + +gls.left[3] = { + FileIcon = { + provider = "FileIcon", + condition = buffer_not_empty, + highlight = {require("galaxyline.provider_fileinfo").get_file_icon_color, colors.lightbg} + } +} + +gls.left[4] = { + FileName = { + provider = {"FileName", "FileSize"}, + condition = buffer_not_empty, + highlight = {colors.fg, colors.lightbg} + } +} + +gls.left[5] = { + teech = { + provider = function() + return " " + end, + separator = " ", + highlight = {colors.lightbg, colors.bg} + } +} + +local checkwidth = function() + local squeeze_width = vim.fn.winwidth(0) / 2 + if squeeze_width > 40 then + return true + end + return false +end + +gls.left[6] = { + DiffAdd = { + provider = "DiffAdd", + condition = checkwidth, + icon = "  ", + highlight = {colors.greenYel, colors.line_bg} + } +} + +gls.left[7] = { + DiffModified = { + provider = "DiffModified", + condition = checkwidth, + icon = " ", + highlight = {colors.orange, colors.line_bg} + } +} + +gls.left[8] = { + DiffRemove = { + provider = "DiffRemove", + condition = checkwidth, + icon = " ", + highlight = {colors.lightbg, colors.line_bg} + } +} + +gls.left[9] = { + LeftEnd = { + provider = function() + return " " + end, + separator = " ", + separator_highlight = {colors.line_bg, colors.line_bg}, + highlight = {colors.line_bg, colors.line_bg} + } +} + +gls.left[10] = { + DiagnosticError = { + provider = "DiagnosticError", + icon = "  ", + highlight = {colors.red, colors.bg} + } +} + +gls.left[11] = { + Space = { + provider = function() + return " " + end, + highlight = {colors.line_bg, colors.line_bg} + } +} + +gls.left[12] = { + DiagnosticWarn = { + provider = "DiagnosticWarn", + icon = "  ", + highlight = {colors.red, colors.bg} + } +} + +gls.right[1] = { + GitIcon = { + provider = function() + return "  " + end, + condition = require("galaxyline.provider_vcs").check_git_workspace, + highlight = {colors.green, colors.line_bg} + } +} + +gls.right[2] = { + GitBranch = { + provider = "GitBranch", + condition = require("galaxyline.provider_vcs").check_git_workspace, + highlight = {colors.green, colors.line_bg} + } +} + +gls.right[3] = { + right_LeftRounded = { + provider = function() + return " " + end, + separator = " ", + separator_highlight = {colors.bg, colors.bg}, + highlight = {colors.lightbg, colors.bg} + } +} + +gls.right[4] = { + ViMode = { + provider = function() + local alias = { + n = "NORMAL", + i = "INSERT", + c = "COMMAND", + V = "VISUAL", + [""] = "VISUAL", + v = "VISUAL", + R = "REPLACE" + } + return alias[vim.fn.mode()] + end, + highlight = {colors.fg, colors.lightbg} + } +} + +gls.right[5] = { + PerCent = { + provider = "LinePercent", + separator = " ", + separator_highlight = {colors.lightbg, colors.lightbg}, + highlight = {colors.fg, colors.lightbg} + } +} + +gls.right[6] = { + rightRounded = { + provider = function() + return " " + end, + highlight = {colors.lightbg, colors.bg} + } +} + diff --git a/home-manager-modules/neovim/lua/lsp.lua b/home-manager-modules/neovim/lua/lsp.lua new file mode 100755 index 0000000..5978580 --- /dev/null +++ b/home-manager-modules/neovim/lua/lsp.lua @@ -0,0 +1,76 @@ +-- This file sets up autocompletion for neovim's native lsp + +-- This enables all the language servers I want on my system +-- Change these to whatever languages you use + +require'lspconfig'.rnix.setup{} +require'lspconfig'.sumneko_lua.setup{} +vim.o.completeopt = "menuone,noselect" + +-- Autocompletion setup +require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = false; + source = { + path = true; + buffer = true; + nvim_lsp = true; + treesitter = true; + }; +} + +-- Set tab to accept the autocompletion +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end +_G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + else + return t "" + end +end + +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) + + +-- set the path to the sumneko installation; if you previously installed via the now deprecated :LspInstall, use +local sumneko_root_path = vim.fn.stdpath('cache')..'/lspconfig/sumneko_lua/lua-language-server' +local sumneko_binary = "lua-language-server" + +local runtime_path = vim.split(package.path, ';') +table.insert(runtime_path, "lua/?.lua") +table.insert(runtime_path, "lua/?/init.lua") + +require'lspconfig'.sumneko_lua.setup { + cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}; + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + path = runtime_path, + }, + diagnostics = { + globals = {'vim'}, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + preloadFileSize = 120 + }, + telemetry = { + enable = false, + }, + }, + }, +} diff --git a/home-manager-modules/neovim/lua/nvim-tree.lua b/home-manager-modules/neovim/lua/nvim-tree.lua new file mode 100755 index 0000000..6cb44f0 --- /dev/null +++ b/home-manager-modules/neovim/lua/nvim-tree.lua @@ -0,0 +1,60 @@ +-- following options are the default +-- each of these are documented in `:help nvim-tree.OPTION_NAME` +require'nvim-tree'.setup { + disable_netrw = true, + hijack_netrw = true, + open_on_setup = false, + ignore_ft_on_setup = {}, + auto_close = false, + open_on_tab = false, + hijack_cursor = false, + update_cwd = false, + update_to_buf_dir = { + enable = true, + auto_open = true, + }, + diagnostics = { + enable = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + } + }, + update_focused_file = { + enable = false, + update_cwd = false, + ignore_list = {} + }, + system_open = { + cmd = nil, + args = {} + }, + filters = { + dotfiles = false, + custom = {} + }, + git = { + enable = true, + ignore = true, + timeout = 500, + }, + view = { + width = 30, + height = 30, + hide_root_folder = false, + side = 'left', + auto_resize = false, + mappings = { + custom_only = false, + list = {} + }, + number = false, + relativenumber = false + }, + trash = { + cmd = "trash", + require_confirm = true + } +} diff --git a/home-manager-modules/neovim/lua/settings.lua b/home-manager-modules/neovim/lua/settings.lua new file mode 100644 index 0000000..45b2a56 --- /dev/null +++ b/home-manager-modules/neovim/lua/settings.lua @@ -0,0 +1,96 @@ +-- Lazy load everything! +-- +-- +--dofile("lsp.lua") +--dofile("galaxyline.lua") +--dofile("nvim-tree.lua") +local opt = vim.opt +local g = vim.g + + +vim.cmd [[ + set nowrap + set nobackup + set nowritebackup + set noerrorbells + set noswapfile + + colorscheme dusk + function! Preserve(command) + let w = winsaveview() + execute a:command + call winrestview(w) + endfunction + autocmd FileType nix map u :call Preserve("%!update-nix-fetchgit --location=" . line(".") . ":" . col(".")) + autocmd BufWinEnter NvimTree setlocal nonumber + map ; : + highlight IndentBlanklineChar guifg = #393b4d + +]] + +-- Enable plugins +require('bufferline').setup{} +require('pears').setup() +require('colorizer').setup() + +-- Treesitter settings +require'nvim-treesitter.configs'.setup { + ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages + highlight = { + enable = true + }, +} + +local map = vim.api.nvim_set_keymap +options = { noremap = true } +map('n', '', ':NvimTreeToggle ', options) +map('n', '', ':Telescope find_files ', options) +map('n', '', ':Telescope live_grep ', options) +map('n', '', ':noh ', options) +map('n', '', ':!xclip -sel c -o | pygmentize -f html | xclip -sel c ', options) +vim.api.nvim_set_keymap('n', '0', "getline('.')[0 : col('.') - 2] =~# '^\\s\\+$' ? '0' : '^'", {silent = true, noremap = true, expr = true}) +g.mapleader = ' ' + +-- Indent line +g.indent_blankline_char = '▏' + +-- Performance +opt.lazyredraw = true; +opt.shell = "zsh" +opt.shadafile = "NONE" + +-- Colors +opt.termguicolors = true + +-- Undo files +opt.undofile = true + +-- Indentation +opt.smartindent = true +opt.tabstop = 4 +opt.shiftwidth = 4 +opt.shiftround = true +opt.expandtab = true +opt.scrolloff = 3 + +-- Set clipboard to use system clipboard +opt.clipboard = "unnamedplus" + +-- Use mouse +opt.mouse = "a" + +-- Nicer UI settings +opt.cursorline = true +opt.relativenumber = true +opt.number = true + +-- Get rid of annoying viminfo file +opt.viminfo = "" +opt.viminfofile = "NONE" + +-- Miscellaneous quality of life +opt.ignorecase = true +opt.ttimeoutlen = 5 +opt.compatible = false +opt.hidden = true +opt.shortmess = "atI" diff --git a/machines/newton.nix b/machines/newton.nix new file mode 100644 index 0000000..cd3894a --- /dev/null +++ b/machines/newton.nix @@ -0,0 +1,169 @@ +{ config, pkgs, lib, modulesPath, ... }: +let + hostName = "newton"; +in + { + + #programs.home-manager.enable = true; + home-manager.users.julien = { + home.username = "julien"; + home.homeDirectory = "/home/julien"; + home.stateVersion = "21.11"; + imports = [../home-manager-modules/mails/default.nix ../home-manager-modules/neovim/default.nix]; + luj.emails = { + enable = true; + backend.enable = true; + }; + + luj.programs.neovim.enable = true; + + }; + boot.loader.grub.enable = true; + boot.loader.grub.version = 2; + boot.supportedFilesystems = [ "zfs" ]; + boot.zfs.requestEncryptionCredentials = true; + boot.loader.grub.copyKernels = true; + boot.loader.grub.efiSupport = false; + boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; + + boot.loader.grub.mirroredBoots = [ + { path = "/boot-1"; devices = [ "/dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4M1TVUVJV" ]; } + { path = "/boot-2"; devices = [ "/dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WCC4M7UDRLSK" ]; } + ]; + + programs.gnupg.agent.enable = true; + networking.hostName = hostName; # Define your hostname. + networking.hostId = "f7cdfbc9"; + + time.timeZone = "Europe/Paris"; + + networking.useDHCP = false; + networking.interfaces.enp2s0f0.useDHCP = true; + networking.interfaces.enp2s0f1.useDHCP = true; + + services.zfs.autoSnapshot.enable = true; + services.zfs.autoScrub.enable = true; + boot.initrd.network = { + # This will use udhcp to get an ip address. + # Make sure you have added the kernel module for your network driver to `boot.initrd.availableKernelModules`, + # so your initrd can load it! + # Static ip addresses might be configured using the ip argument in kernel command line: + # https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt + enable = true; + ssh = { + enable = true; + port = 2222; + # To prevent ssh clients from freaking out because a different host key is used, + # a different port for ssh is useful (assuming the same host has also a regular sshd running) + # hostKeys paths must be unquoted strings, otherwise you'll run into issues with boot.initrd.secrets + # the keys are copied to initrd from the path specified; multiple keys can be set + # you can generate any number of host keys using + # `ssh-keygen -t ed25519 -N "" -f /path/to/ssh_host_ed25519_key` + hostKeys = [ /boot-1/initrd-ssh-key /boot-2/initrd-ssh-key ]; + # public ssh key used for login + }; + # this will automatically load the zfs password prompt on login + # and kill the other prompt so boot can continue + postCommands = '' + zpool import zroot + echo "zfs load-key -a; killall zfs" >> /root/.profile + ''; + }; + + + + programs.mosh.enable = true; + + programs.fish.enable = true; + users.defaultUserShell = pkgs.fish; + + + + + + + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.julien = { + isNormalUser = true; + extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. + }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + ]; + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + services.openssh.enable = true; + + users.users.root.openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM/5+xJDYw1+qFnse+RfEnk1YbtEkpkVNzapWKPmpFIh julien@macintosh" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM9Uzb7szWlux7HuxLZej9cBR5MhLz/vaAPPfSoozt2k julien@enigma.local" ]; + services.openssh.authorizedKeysFiles = [ "/home/julien/.ssh/authorized_keys" ]; + + # Open ports in the firewall. + networking.firewall.allowedTCPPorts = [ 22 80 443 ]; + networking.firewall.allowedUDPPorts = [ 22 80 443 ]; + networking.firewall.allowedUDPPortRanges = [{ from = 60000; to = 61000; }]; + # Or disable the firewall altogether. + networking.firewall.enable = true; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "21.05"; # Did you read the comment? + + + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "tg3" "xhci_pci" "ahci" "ehci_pci" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-amd" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "zroot/root"; + fsType = "zfs"; + options = [ "nofail" ]; + }; + + fileSystems."/boot-1" = + { device = "/dev/disk/by-uuid/15AF-22DB"; + fsType = "vfat"; + options = [ "nofail" ]; + }; + + fileSystems."/boot-2" = + { device = "/dev/disk/by-uuid/15EC-BC00"; + fsType = "vfat"; + options = [ "nofail" ]; + }; + + swapDevices = [ ]; + + + luj = { + filerun.enable = true; + zfs-mails.enable = true; + }; + + + + + + +} diff --git a/modules/zfs-mails/default.nix b/modules/zfs-mails/default.nix new file mode 100644 index 0000000..37b0dbc --- /dev/null +++ b/modules/zfs-mails/default.nix @@ -0,0 +1,106 @@ +{ pkgs, config, lib, ... }: +let + cfg = config.luj.zfs-mails; + emailTo = "julien.malka@me.com"; + emailFrom = "newton@newton.fr"; + msmtpAccount = { + auth = "plain"; + host = "smtp-relay.sendinblue.com"; + port = "587"; + user = "julien.malka@me.com"; + passwordeval = "${pkgs.gnupg}/bin/gpg -q --batch --passphrase-file /home/julien/email-passphrase -d ${./sendinblue.pass.gpg}"; + from = emailFrom; + }; + + + + customizeZfs = zfs: + (zfs.override { enableMail = true; }).overrideAttrs (oldAttrs: { + patches = oldAttrs.patches ++ + [ + (pkgs.fetchpatch { + name = "notify-on-unavail-events.patch"; + url = "https://github.com/openzfs/zfs/commit/f74604f2f0d76ee55b59f7ed332409fb128ec7e5.patch"; + sha256 = "1v25ydkxxx704j0gdxzrxvw07gfhi7865grcm8b0zgz9kq0w8i8i"; + }) + ]; + }); + + hostName = "newton"; + sendEmailEvent = { event }: '' + printf "Subject: ${hostName} ${event} ''$(${pkgs.coreutils}/bin/date --iso-8601=seconds)\n\nzpool status:\n\n''$(${pkgs.zfs}/bin/zpool status)" | ${pkgs.msmtp}/bin/msmtp -a default ${emailTo} + ''; + +in +with lib; +{ + options.luj.zfs-mails = { + enable = mkEnableOption "enable zfs status mails"; + }; + + + config = mkIf cfg.enable { + + nixpkgs.config.packageOverrides = pkgs: { + zfsStable = customizeZfs pkgs.zfsStable; + }; + + + programs.msmtp = { + enable = true; + setSendmail = true; + defaults = { + aliases = builtins.toFile "aliases" '' + default: ${emailTo} + ''; + }; + accounts.default = msmtpAccount; + }; + + services.zfs.zed.enableMail = true; + services.zfs.zed.settings = { + ZED_EMAIL_ADDR = [ emailTo ]; + ZED_EMAIL_OPTS = "-a 'FROM:${emailFrom}' -s '@SUBJECT@' @ADDRESS@"; + ZED_NOTIFY_VERBOSE = true; + }; + services.smartd.enable = true; + services.smartd.notifications.mail.enable = true; + services.smartd.notifications.mail.sender = emailFrom; + services.smartd.notifications.mail.recipient = emailTo; + + systemd.services."boot-mail-alert" = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" "network-online.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = sendEmailEvent { event = "just booted"; }; + }; + systemd.services."shutdown-mail-alert" = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" "network-online.target" ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = "true"; + preStop = sendEmailEvent { event = "is shutting down"; }; + }; + systemd.services."weekly-mail-alert" = { + serviceConfig.Type = "oneshot"; + script = sendEmailEvent { event = "is still alive"; }; + }; + systemd.timers."weekly-mail-alert" = { + wantedBy = [ "timers.target" ]; + partOf = [ "weekly-mail-alert.service" ]; + timerConfig.OnCalendar = "weekly"; + }; + + + + }; + +} + + diff --git a/utils.nix b/utils.nix index 2d583c5..5610eb1 100644 --- a/utils.nix +++ b/utils.nix @@ -16,9 +16,7 @@ in host-config home-manager.nixosModules.home-manager { - home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.julien = import ./config/home/home-lisa.nix; nixpkgs.overlays = [ inputs.neovim-nightly-overlay.overlay ];