From 3f0e83cb4816e637d8c916fb77217e1c5824dbe5 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Thu, 3 Dec 2020 16:45:06 +0100 Subject: initial commit: most of previous configuration reworked --- common/commandline.nix | 108 +++++++++++++++++++ common/commandline/dircolors.nix | 74 +++++++++++++ common/commandline/git.nix | 58 ++++++++++ common/commandline/htop.nix | 44 ++++++++ common/commandline/tmux.nix | 79 ++++++++++++++ common/commandline/zsh.nix | 59 +++++++++++ common/default.nix | 11 ++ common/theme.nix | 223 +++++++++++++++++++++++++++++++++++++++ common/tinc.nix | 18 ++++ common/tinc/.keep | 0 common/vim.nix | 119 +++++++++++++++++++++ 11 files changed, 793 insertions(+) create mode 100644 common/commandline.nix create mode 100644 common/commandline/dircolors.nix create mode 100644 common/commandline/git.nix create mode 100644 common/commandline/htop.nix create mode 100644 common/commandline/tmux.nix create mode 100644 common/commandline/zsh.nix create mode 100644 common/default.nix create mode 100644 common/theme.nix create mode 100644 common/tinc.nix create mode 100644 common/tinc/.keep create mode 100644 common/vim.nix (limited to 'common') diff --git a/common/commandline.nix b/common/commandline.nix new file mode 100644 index 0000000..36fae26 --- /dev/null +++ b/common/commandline.nix @@ -0,0 +1,108 @@ +{ config, pkgs, lib, ... }: + +with import ../lib/theme.nix { inherit lib; }; +let + dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; + bgDominantEscapeCode = bgEscapeCode config.theme.colors.dominant; + backgroundEscapeCode = fgEscapeCode config.theme.colors.background; +in +{ + imports = [ + ./commandline/dircolors.nix + ./commandline/git.nix + ./commandline/htop.nix + ./commandline/tmux.nix + ./commandline/zsh.nix + ]; + + environment.shellAliases = { + ll = "ls -l"; + e = "\${EDITOR}"; + cpr = "${pkgs.rsync}/bin/rsync -ah --inplace --info=progress2"; + }; + + programs.bash = { + enableCompletion = true; + interactiveShellInit = '' + eval "$(${pkgs.starship}/bin/starship init bash)" + + PATH="${pkgs.pazi}/bin:$PATH" + eval "$(pazi init bash)" + ''; + }; + + programs.less = { + envVariables = { + LESS = "-W -z-4 -R -J"; + LESS_TERMCAP_mb = dominantEscapeCode; + LESS_TERMCAP_md = dominantEscapeCode; + LESS_TERMCAP_so = + bgDominantEscapeCode + backgroundEscapeCode + "$(tput bold)"; + }; + }; + + security.sudo.extraConfig = + let + lectureFile = builtins.toFile "sudoers.lecture" '' +  + ${dominantEscapeCode}"Bee" careful __ + ${dominantEscapeCode}with sudo! // \ + \\_/ // + '''-.._.-'''-.._.. -(||)(') + '''' + + ''; + in + '' + Defaults lecture = always + Defaults lecture_file = "${lectureFile}" + ''; + + home-manager.users.minijackson = { ... }: + { + # TODO + xdg.configFile."starship.toml".text = '' + [directory] + fish_style_pwd_dir_length = 2 + style = "bold blue" + + [git_branch] + symbol = "branch " + + [git_status] + ahead = "^" + behind = "v" + deleted = "x" + + [jobs] + symbol = "+ " + + [package] + symbol = "version " + style = "bold green" + disabled = true + + [rust] + symbol = "rust " + style = "bold dimmed yellow" + + [nix_shell] + style = "bold blue" + + [character] + symbol = ">" + ''; + + programs.bat = { + enable = true; + config = { + theme = "TwoDark"; + }; + }; + }; + + home-manager.users.root = { ... }: + { + programs.bat = config.home-manager.users.minijackson.programs.bat; + }; +} diff --git a/common/commandline/dircolors.nix b/common/commandline/dircolors.nix new file mode 100644 index 0000000..7ef3a4d --- /dev/null +++ b/common/commandline/dircolors.nix @@ -0,0 +1,74 @@ +{ config, ... }: + +{ + home-manager.users.minijackson = { ... }: + { + programs.dircolors = { + enable = true; + settings = { + # Enable on the alacritty terminal + TERM = "alacritty*"; + + DIR = "01;94"; + EXEC = "01;92"; + + FIFO = "93"; # pipe" + BLK = "93;01"; # block device driver" + CHR = "93;01"; # character device driver" + + # archives or compressed (yellow) + ".tar" = "01;33"; + ".tgz" = "01;33"; + ".arc" = "01;33"; + ".arj" = "01;33"; + ".taz" = "01;33"; + ".lha" = "01;33"; + ".lz4" = "01;33"; + ".lzh" = "01;33"; + ".lzma" = "01;33"; + ".tlz" = "01;33"; + ".txz" = "01;33"; + ".tzo" = "01;33"; + ".t7z" = "01;33"; + ".zip" = "01;33"; + ".z" = "01;33"; + ".dz" = "01;33"; + ".gz" = "01;33"; + ".lrz" = "01;33"; + ".lz" = "01;33"; + ".lzo" = "01;33"; + ".xz" = "01;33"; + ".zst" = "01;33"; + ".tzst" = "01;33"; + ".bz2" = "01;33"; + ".bz" = "01;33"; + ".tbz" = "01;33"; + ".tbz2" = "01;33"; + ".tz" = "01;33"; + ".deb" = "01;33"; + ".rpm" = "01;33"; + ".jar" = "01;33"; + ".war" = "01;33"; + ".ear" = "01;33"; + ".sar" = "01;33"; + ".rar" = "01;33"; + ".alz" = "01;33"; + ".ace" = "01;33"; + ".zoo" = "01;33"; + ".cpio" = "01;33"; + ".7z" = "01;33"; + ".rz" = "01;33"; + ".cab" = "01;33"; + ".wim" = "01;33"; + ".swm" = "01;33"; + ".dwm" = "01;33"; + ".esd" = "01;33"; + }; + }; + }; + + home-manager.users.root = { ... }: + { + programs.dircolors = config.home-manager.users.minijackson.programs.dircolors; + }; +} diff --git a/common/commandline/git.nix b/common/commandline/git.nix new file mode 100644 index 0000000..597ef64 --- /dev/null +++ b/common/commandline/git.nix @@ -0,0 +1,58 @@ +{ config, pkgs, ... }: + +{ + # TODO: add signing + home-manager.users.minijackson = { ... }: + { + programs.git = { + enable = true; + package = pkgs.gitAndTools.gitFull; + userEmail = "minijackson@riseup.net"; + userName = "Minijackson"; + + extraConfig = let + deltaCommand = "${pkgs.gitAndTools.delta}/bin/delta"; + in { + core = { + whitespace = "trailing-space,space-before-tab"; + pager = deltaCommand; + interactive.diffFilter = "${deltaCommand} --color-only"; + }; + merge = { tool = "nvimdiff"; }; + "mergetool \"nvimdiff\"" = { cmd = "nvim -d \"$LOCAL\" \"$MERGED\" \"$REMOTE\""; }; + + delta = with config.theme.colors; { + features = "line-numbers decorations"; + whitespace-error-style = "22 reverse"; + decorations = { + minus-style = "normal red"; + minus-non-emph-style = "normal red"; + minus-emph-style = "normal brightred"; + minus-empty-line-marker-style = "normal red"; + + plus-style = "reverse green"; + plus-non-emph-style = "reverse green"; + plus-emph-style = "reverse brightgreen"; + plus-empty-line-marker-style = "reverse green"; + + whitespace-error-style = "reverse green"; + + line-numbers-minus-style = "brightred"; + line-numbers-zero-style = "brightblack"; + line-numbers-plus-style = "brightgreen"; + + file-style = "bright${dominantName}"; + line-numbers-left-style = dominantName; + line-numbers-right-style = dominantName; + }; + }; + + }; + }; + }; + + home-manager.users.root = { ... }: + { + programs.git = config.home-manager.users.minijackson.programs.git; + }; +} diff --git a/common/commandline/htop.nix b/common/commandline/htop.nix new file mode 100644 index 0000000..f9732a6 --- /dev/null +++ b/common/commandline/htop.nix @@ -0,0 +1,44 @@ +{ config, ... }: + +{ + home-manager.users.minijackson = { ... }: + { + programs.htop = { + enable = true; + + fields = [ + "PID" "USER" + "PRIORITY" "NICE" + "STATE" + "IO_PRIORITY" "IO_READ_RATE" "IO_WRITE_RATE" + "PERCENT_CPU" "PERCENT_MEM" + "TIME" + "COMM" + ]; + + hideThreads = true; + hideUserlandThreads = true; + showThreadNames = true; + shadowOtherUsers = true; + + highlightBaseName = true; + + # On NixOS? NO. + showProgramPath = false; + + treeView = true; + + meters = { + left = [ "LeftCPUs2" "Memory" "Swap" "Blank" { kind = "Battery"; mode = 1; } ]; + right = [ "RightCPUs2" "Blank" "Tasks" "LoadAverage" "Uptime" ]; + }; + }; + }; + + home-manager.users.root = { ... }: + { + programs.htop = config.home-manager.users.minijackson.programs.htop // { + shadowOtherUsers = false; + }; + }; +} diff --git a/common/commandline/tmux.nix b/common/commandline/tmux.nix new file mode 100644 index 0000000..aa4de9c --- /dev/null +++ b/common/commandline/tmux.nix @@ -0,0 +1,79 @@ +{ config, pkgs, ... } : + +let + # Thanks: https://github.com/DanielFGray/dotfiles/blob/master/tmux.remote.conf + remoteConf = builtins.toFile "tmux.remote.conf" '' + unbind C-q + unbind q + set-option -g prefix C-s + bind s send-prefix + bind C-s last-window + set-option -g status-position top + ''; +in { + programs.tmux = { + enable = true; + shortcut = "q"; + escapeTime = 10; + keyMode = "vi"; + terminal = "tmux-256color"; + historyLimit = 50000; + + extraConfig = with config.theme; with pkgs.tmuxPlugins; + '' + # Plugins + run-shell '${copycat}/share/tmux-plugins/copycat/copycat.tmux' + run-shell '${sensible}/share/tmux-plugins/sensible/sensible.tmux' + run-shell '${urlview}/share/tmux-plugins/urlview/urlview.tmux' + + bind-key R run-shell ' \ + tmux source-file /etc/tmux.conf > /dev/null; \ + tmux display-message "sourced /etc/tmux.conf"' + + if -F "$SSH_CONNECTION" "source-file '${remoteConf}'" + + set-option -g status-right ' #{prefix_highlight} "#{=21:pane_title}" %H:%M %d-%b-%y' + set-option -g status-left-length 20 + set-option -g @prefix_highlight_fg '${colors.background}' + set-option -g @prefix_highlight_bg '${colors.dominant}' + run-shell '${prefix-highlight}/share/tmux-plugins/prefix-highlight/prefix_highlight.tmux' + + # Be faster switching windows + bind C-n next-window + bind C-p previous-window + + set-option -g set-titles on + + bind C-y run-shell ' \ + ${pkgs.tmux}/bin/tmux show-buffer > /dev/null 2>&1 \ + && ${pkgs.tmux}/bin/tmux show-buffer | ${pkgs.xsel}/bin/xsel -ib' + + # Force true colors + set-option -ga terminal-overrides ",*:Tc" + + set-option -g mouse on + set-option -g focus-events on + + # Stay in same directory when split + bind % split-window -h -c "#{pane_current_path}" + bind '"' split-window -v -c "#{pane_current_path}" + + # Colorscheme + set-option -g status-style 'fg=${colors.dimForeground}, bg=${colors.background}' + + set-option -g window-status-current-style 'fg=${colors.dominant}' + + set-option -g pane-border-style 'fg=${colors.background}' + set-option -g pane-active-border-style 'fg=${colors.dominant}' + + set-option -g message-style 'fg=${colors.background}, bg=${colors.dimForeground}' + + set-option -g mode-style 'fg=${colors.background}, bg=${colors.dominant}' + + set-option -g display-panes-active-colour '${colors.dominant}' + set-option -g display-panes-colour '${colors.dimForeground}' + + set-option -g clock-mode-colour '${colors.dominant}' + ''; + }; +} diff --git a/common/commandline/zsh.nix b/common/commandline/zsh.nix new file mode 100644 index 0000000..3376321 --- /dev/null +++ b/common/commandline/zsh.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, ... }: + +with import ../../lib/theme.nix { inherit lib; }; +let + dominantEscapeCode = fgEscapeCode config.theme.colors.dominant; +in +{ + programs.zsh = { + enable = true; + + interactiveShellInit = with lib; + '' + source "${pkgs.grml-zsh-config}/etc/zsh/zshrc" + is4 && xsource "${pkgs.grml-zsh-config}/etc/zsh/keephack" + + PATH="${pkgs.pazi}/bin:$PATH" + eval "$(pazi init zsh)" + + source "${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh" + + function () { + local dominant_escape_code="${dominantEscapeCode}" + local dim_fg_escape_code="${fgEscapeCode config.theme.colors.dimForeground}" + + ${builtins.readFile ../../dotfiles/zshrc} + } + + # Grml's ZSH config overrides less variables + export ${concatStringsSep " " + (mapAttrsToList + (variable: value: "${variable}=\"${value}\"") + config.programs.less.envVariables)} + + #eval "$(${pkgs.starship}/bin/starship init zsh)" + ''; + + # otherwise it'll override the grml prompt + promptInit = ""; + # Grml handles that, and supports cache (faster!!!) + enableGlobalCompInit = false; + + syntaxHighlighting = { + enable = true; + highlighters = [ "main" "brackets" "line" ]; + }; + + shellAliases = { + e = "\${(z)EDITOR}"; + }; + + setOptions = [ + "HIST_IGNORE_DUPS" "SHARE_HISTORY" "HIST_FCNTL_LOCK" + "NO_CLOBBER" + "NO_CASE_GLOB" + ]; + }; + + users.defaultUserShell = pkgs.zsh; +} diff --git a/common/default.nix b/common/default.nix new file mode 100644 index 0000000..fc9086b --- /dev/null +++ b/common/default.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + imports = [ + + ./commandline.nix + ./theme.nix + ./tinc.nix + ./vim.nix + ]; +} diff --git a/common/theme.nix b/common/theme.nix new file mode 100644 index 0000000..675bc33 --- /dev/null +++ b/common/theme.nix @@ -0,0 +1,223 @@ +# A facility centralizing theme / colorscheme + +# The default colors are based on the Gruvbox theme: +# +# - https://github.com/morhetz/gruvbox +# - https://github.com/morhetz/gruvbox-contrib + +{ config, lib, ... }: + +with lib; + +{ + options.theme.colors = { + + dominantName = mkOption { + type = types.str; + default = "green"; + description = '' + The dominant color name of the theme. + + This color should be different on different hosts. + ''; + }; + + dominant = mkOption { + type = types.str; + default = "#b8bb26"; + description = '' + The dominant color of the theme. + + This color should be different on different hosts. + ''; + }; + + dimDominant = mkOption { + type = types.str; + default = "#79740e"; + description = '' + The dominant color of the theme, but dimmed. + ''; + }; + + foreground = mkOption { + type = types.str; + default = "#ebdbb1"; + description = "The foreground (text) color"; + }; + + dimForeground = mkOption { + type = types.str; + default = "#928374"; + description = "Like the foreground color, but one which does not burn the eyes."; + }; + + background = mkOption { + type = types.str; + default = "#282828"; + description = "The background color"; + }; + + softBackground = mkOption { + type = types.str; + default = "#32302f"; + description = "Like the background color, but a little bit softer."; + }; + + lightBackground = mkOption { + type = types.str; + default = "#504945"; + description = "Like the background color, but one which burns the eyes a little bit more."; + }; + + background0 = mkOption { + type = types.str; + default = "#1d2021"; + description = "Background level 0"; + }; + + background1 = mkOption { + type = types.str; + default = "#282828"; + description = "Background level 1"; + }; + + background2 = mkOption { + type = types.str; + default = "#3c3836"; + description = "Background level 2"; + }; + + background3 = mkOption { + type = types.str; + default = "#504945"; + description = "Background level 3"; + }; + + background4 = mkOption { + type = types.str; + default = "#665c54"; + description = "Background level 4"; + }; + + background5 = mkOption { + type = types.str; + default = "#7c6f64"; + description = "Background level 5"; + }; + + background6 = mkOption { + type = types.str; + default = "#928374"; + description = "Background level 6"; + }; + + brightRed = mkOption { + type = types.str; + default = "#fb4934"; + }; + + brightGreen = mkOption { + type = types.str; + default = "#b8bb26"; + }; + + brightYellow = mkOption { + type = types.str; + default = "#fabd2f"; + }; + + brightBlue = mkOption { + type = types.str; + default = "#83a598"; + }; + + brightMagenta = mkOption { + type = types.str; + default = "#d3869b"; + }; + + brightCyan = mkOption { + type = types.str; + default = "#8ec07c"; + }; + + brightOrange = mkOption { + type = types.str; + default = "#fe8019"; + }; + + + neutralRed = mkOption { + type = types.str; + default = "#cc241d"; + }; + + neutralGreen = mkOption { + type = types.str; + default = "#98971a"; + }; + + neutralYellow = mkOption { + type = types.str; + default = "#d79921"; + }; + + neutralBlue = mkOption { + type = types.str; + default = "#458588"; + }; + + neutralMagenta = mkOption { + type = types.str; + default = "#b16286"; + }; + + neutralCyan = mkOption { + type = types.str; + default = "#689d6a"; + }; + + neutralOrange = mkOption { + type = types.str; + default = "#d65d0e"; + }; + + + fadedRed = mkOption { + type = types.str; + default = "#9d0006"; + }; + + fadedGreen = mkOption { + type = types.str; + default = "#79740e"; + }; + + fadedYellow = mkOption { + type = types.str; + default = "#b57614"; + }; + + fadedBlue = mkOption { + type = types.str; + default = "#076678"; + }; + + fadedMagenta = mkOption { + type = types.str; + default = "#8f3f71"; + }; + + fadedCyan = mkOption { + type = types.str; + default = "#427b58"; + }; + + fadedOrange = mkOption { + type = types.str; + default = "#af3a03"; + }; + + }; +} diff --git a/common/tinc.nix b/common/tinc.nix new file mode 100644 index 0000000..1016f42 --- /dev/null +++ b/common/tinc.nix @@ -0,0 +1,18 @@ +{ config, lib, ... }: + +with lib; +with builtins; +let + networks = attrNames (readDir ./tinc/private); +in { + imports = map (network: (./tinc/private + "/${network}")) networks; + + services.tinc.networks = genAttrs networks (network: { + name = config.networking.hostName; + + hosts = let + hosts = attrNames (readDir (./tinc/private + "/${network}/hosts")); + config = hostname: readFile (./tinc/private + "/${network}/hosts/${hostname}"); + in genAttrs hosts config; + }); +} diff --git a/common/tinc/.keep b/common/tinc/.keep new file mode 100644 index 0000000..e69de29 diff --git a/common/vim.nix b/common/vim.nix new file mode 100644 index 0000000..ddb901a --- /dev/null +++ b/common/vim.nix @@ -0,0 +1,119 @@ +{ config, pkgs, lib, ... }: + +let myNeovim = (pkgs.neovim.override { + configure = { + + inherit (config.vim) beforePlugins; + + customRC = with lib; + (concatStringsSep + "\n" + (mapAttrsToList + (variable: value: "let g:${variable} = ${value}") + config.vim.variables)) + + "\n" + + builtins.readFile ../dotfiles/vimrc.vim + config.vim.extraConfig; + + vam = with pkgs; { + pluginDictionaries = [ + # UI + { name = "undotree"; } + { name = "gruvbox-community"; } + { name = "gitgutter"; } + { name = "lightline-vim"; } + { name = "vim-dirvish"; } + + # Motions + { name = "camelcasemotion"; } + { name = "surround"; } + { name = "targets-vim"; } + + # Frameworks + { name = "deoplete-nvim"; } + { name = "neosnippet"; } + { name = "neosnippet-snippets"; } + { name = "neoformat"; } + { name = "ctrlp"; } + # Syntax generic completion for deoplete + { name = "neco-syntax"; } + + # Languages + { name = "vim-polyglot"; } + { name = "editorconfig-vim"; } + # Vim completion for deoplete + { name = "neco-vim"; } + { name = "deoplete-zsh"; } + { name = "vim-pandoc"; } + { name = "vim-pandoc-syntax"; } + + # Languages (but not programming languages) + { name = "vim-grammarous"; } + + # Other + { name = "tmux-complete-vim"; } + { name = "fugitive"; } + { name = "rhubarb"; } + { name = "repeat"; } + { name = "vim-unimpaired"; } + { name = "tabular"; } + { name = "vimwiki"; } + { name = "vim-abolish"; } + + ] ++ config.vim.extraPlugins; + + }; + + }; +}); +in { + options.vim = with lib; { + + variables = mkOption { + type = types.attrsOf types.str; + default = { + dominant_color = "'${config.theme.colors.dominant}'"; + ripgrep_path = "'${pkgs.ripgrep}/bin/rg'"; + fd_path = "'${pkgs.fd}/bin/fd'"; + }; + description = '' + Extra global variables to add at the beginning of the vim configuration. + + Remember to escape strings with single-quotes. + ''; + }; + + extraPlugins = mkOption { + type = types.listOf (types.attrsOf types.str); + default = []; + description = "Names of extra plugins to add"; + }; + + extraRepoPlugins = mkOption { + type = types.listOf (types.attrsOf types.str); + default = []; + description = "Names of extra plugins to add that are present in the local repository"; + }; + + beforePlugins = mkOption { + type = types.lines; + default = ""; + description = "Extra lines to add in the vim configuration before loading plugins"; + }; + + extraConfig = mkOption { + type = types.lines; + default = ""; + description = "Extra lines to add at the end of the vim configuration"; + }; + }; + + config = { + environment.systemPackages = with pkgs; [ + myNeovim + ]; + + environment.sessionVariables = { + EDITOR = "nvim"; + }; + }; +} -- cgit v1.2.3