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 --- .gitignore | 4 + 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 +++++++++++++++++++ configuration.nix | 72 ++++++++++++ dotfiles/vimrc.vim | 139 ++++++++++++++++++++++ dotfiles/zshrc | 242 +++++++++++++++++++++++++++++++++++++++ lib/theme.nix | 35 ++++++ profiles/server.nix | 9 ++ 17 files changed, 1294 insertions(+) create mode 100644 .gitignore 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 create mode 100644 configuration.nix create mode 100644 dotfiles/vimrc.vim create mode 100644 dotfiles/zshrc create mode 100644 lib/theme.nix create mode 100644 profiles/server.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f47876 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +result +*secret.nix +private +/hardware-configuration.nix 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"; + }; + }; +} diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..1a5530f --- /dev/null +++ b/configuration.nix @@ -0,0 +1,72 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, modulesPath, ... }: + +{ + imports = [ + ./hardware-configuration.nix + ./host-secret.nix + ./common/default.nix + ]; + + # Set your time zone. + time.timeZone = "Europe/Paris"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + wget + vim tmux + ripgrep file progress psmisc lsof nethogs + fd tree ncdu + lm_sensors hddtemp smartmontools + elinks + wipe + gnupg + nix-prefetch-scripts + shellcheck + ]; + + # 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; + passwordAuthentication = false; + }; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.extraUsers.minijackson = { + isNormalUser = true; + extraGroups = [ "users" "wheel" ]; + openssh.authorizedKeys.keys = ["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCmyjB5yuU8GK3ZVFznELVEwXN7zzjQJcPYZ89YCGTANjPHpHxZv5R9/kgjTtIKrqqHdTvfr8V8sao9Nr7PhtcV9UywrFn+kplyGf9WDl2oDF9eZprX3beR9zwDj/YIcFRx3wXk4JK/ioZJjcVZ3+xWPixiFplvHIyMsTjKfgRplntHpvoyLM8vURjLOCdPr6SRPReVXuSR2DRlVO7q7y+4FwA1FKAndg9YACoM1g2bEJ6eGyCPp2kFde+GvMv1y6FlBS1OFddGmBpUJzJ4mQ4ebqDVFsKQMx1xCkiz0l7tfVpXqXToHF+baTESEKbC4654PunD99BC0J4otHKrerdmX0HdTgHKtAnslSwRD5NZVAojk/CR3DiSQYFSO9OhFVjHNQsc1zpoKPtJYMe1ax3pcvc+XLCrKLUdHH8x9rVGefZXwIyLrrGrB7fVlyIyX7j04dNALQZiuFOKCInaYypVLHLy0k+buhQlVqKCS6N1xP5O6JiWUKXFYYyoRmSoX9+bfPiwsMrPL+rYXkee0K67BI1NiFAYPmdFFM0jtdFaYuvgEAWw7b9WyWyO/JAdHRwtlqfAqraPBrb4sldvQfLBm8RdORBYMaVbg4EUKMOJjIeAAK+7xWPtg2XeJNnsje/IsWaVXIBx2IAC50uAnIZ/ksw5lyAZP+HyGIHhCAQChQ== minijackson@riseup.net"]; + }; + + nix = { + autoOptimiseStore = true; + gc = { + automatic = true; + dates = "03:15"; + options = "--delete-older-than 30d"; + }; + }; + + system.autoUpgrade.enable = true; +} diff --git a/dotfiles/vimrc.vim b/dotfiles/vimrc.vim new file mode 100644 index 0000000..a0451c6 --- /dev/null +++ b/dotfiles/vimrc.vim @@ -0,0 +1,139 @@ +" Some global variables are defined in ../vim.nix + +" Better default options {{{ + +set undofile +set backup +set backupdir-=. + +set mouse=a + +set ignorecase +set smartcase + +set smartindent +set tabstop=4 +set shiftwidth=4 + +set inccommand=split + +set scrolloff=1 +set sidescrolloff=5 + +set colorcolumn=80 +set cursorline + +set modeline + +set title + +set wildmode=longest:full,full + +let g:maplocalleader = ',' +let g:mapleader = ';' + +" If previously opened jump to the last position in the file +au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + +let &grepprg = g:ripgrep_path . ' --vimgrep $*' +let &grepformat = '%f:%l:%c:%m,' . &grepformat + +let g:tex_flavor = 'latex' + +" }}} + +" Colors, Statusline, Tabline, Code display {{{ + +set termguicolors +let g:gruvbox_contrast_dark = 'soft' +let g:gruvbox_italic = 1 +set background=dark +colorscheme gruvbox + +" Doesn't do anything because the tabline gets overwritten by lightline +"exe 'hi! TabLineSel guifg=' . g:dominant_color + +let g:lightline = { + \ 'colorscheme': 'gruvbox', + \ 'subseparator': { 'left': '|', 'right': '|' }, + \ 'tab_linesubseparator': { 'left': '|', 'right': '|' }, + \ } + +set noshowmode + +" Do not set "trail:-" because it messes up the highlighting +set listchars=tab:│\ ,extends:>,precedes:<,nbsp:+ +set list + +set fillchars=fold:─,vert:│ + +highlight ExtraWhitespace term=inverse cterm=inverse gui=inverse +" Show trailing whitespace and spaces before tabs: +autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL + +" }}} + +" Mappings {{{ + +call camelcasemotion#CreateMotionMappings(g:maplocalleader) + +nmap =of :set =(&formatoptions =~ "a") ? 'formatoptions-=a' : 'formatoptions+=a' + +" }}} + +set completefunc=syntaxcomplete#Complete +set completeopt+=noinsert,noselect + +" Deoplete {{{ + +let g:deoplete#enable_at_startup = 1 + +" }}} + +" Neosnippets {{{ + +imap (neosnippet_expand_or_jump) +smap (neosnippet_expand_or_jump) +xmap (neosnippet_expand_target) + +set conceallevel=2 +set concealcursor=nv + +" }}} + +" CtrlP {{{ +let g:ctrlp_user_command = g:fd_path . ' --type f --color never "" %s' +let g:ctrlp_use_caching = 0 +" }}} + +" LanguageClient {{{ +let g:LanguageClient_loggingFile = stdpath('data') . '/LanguageClient.log' +let g:LanguageClient_serverStderr = stdpath('data') . '/LanguageServer.log' +" }}} + +" VimWiki {{{ + " {'path': '~/Documents/Wiki', 'path_html': '~/Documents/Wiki/html'} \ +let g:vimwiki_list = [ + \ {'path': '~/Documents/Wiki/personal', + \ 'path_html': '~/Documents/Wiki/personal/html', + \ 'auto_tags': 1}, + \ {'path': '~/Documents/Wiki/science', 'path_html': '~/Documents/Wiki/science/html', 'auto_tags': 1}, + \ {'path': '~/Documents/Wiki/work', 'path_html': '~/Documents/Wiki/work/html', 'auto_tags': 1}, +\ ] + +let g:vimwiki_global_ext = 0 + +let g:vimwiki_auto_header = 1 +let g:vimwiki_hl_headers = 1 +let g:vimwiki_hl_cb_checked = 1 +let g:vimwiki_html_header_numbering = 2 +let g:vimwiki_html_header_numbering_sym = '.' + +let g:vimwiki_links_header_level = 2 +let g:vimwiki_tags_header_level = 2 +let g:vimwiki_toc_header_level = 2 + +call deoplete#custom#var('omni', 'input_patterns', { 'vimwiki': '\[\[\w*|\:\w+' }) +" }}} + +" vim: fdm=marker diff --git a/dotfiles/zshrc b/dotfiles/zshrc new file mode 100644 index 0000000..1263eeb --- /dev/null +++ b/dotfiles/zshrc @@ -0,0 +1,242 @@ +# Some variables are defined in ../commandline.nix + +# For users using home-manager +if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then + . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" +fi + +# Grml Zsh configuration {{{ +# ========================== + +# With prompt specific sequences +local dominated="%{${dominant_escape_code}%}" +local dimmed="%{${dim_fg_escape_code}%}" + +# Use the dominant color in the prompt +# In the username item for non-root, in the host item for root +if [ "$EUID" -ne 0 ]; then + zstyle ':prompt:grml:left:items:user' pre "${dominated}%B" +else + zstyle ':prompt:grml:left:items:host' pre "${dominated}" + zstyle ':prompt:grml:left:items:host' post "%f" +fi + +# Change the style of VCS prompt info +zstyle ':vcs_info:*' check-for-changes true +zstyle ':vcs_info:*' stagedstr "s" +zstyle ':vcs_info:*' unstagedstr "u" +zstyle ':vcs_info:*' formats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r" +zstyle ':vcs_info:*' actionformats "${dimmed}(%f%s${dimmed})-[${dominated}%b${dimmed}|%F{yellow}%a${dimmed}]-{%f%c%u${dimmed}}%f " "zsh: %r" + +# }}} + +# Completion system {{{ +# ===================== + +# Change completion messages +zstyle ':completion:*:corrections' format "${dominated}%BFTFY: %b${dominated}(errors: %e)%f" +zstyle ':completion:*:descriptions' format "${dominated} -- So you want a %B%d%b${dominated}? --%f" +zstyle ':completion:*:messages' format "${dominated}You got mail: %f%d" +zstyle ':completion:*:warnings' format "%F{red}I'm sorry Dave, but I cannot allow you to find%f %d" + +# Always activate selection in completion +zstyle ':completion:*' menu select + +# Case insensitive completion and substring completion +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + +# Increase the number of errors based on the length of the typed word. But make +# sure to cap (at 7) the max-errors to avoid hanging. +zstyle -e ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3>7?7:($#PREFIX+$#SUFFIX)/3))numeric)' + +# Tmux Completion {{{ +# ------------------- + +# From: https://blog.plenz.com/2012-01/zsh-complete-words-from-tmux-pane.html +# And: https://gist.github.com/blueyed/6856354 + +_tmux_pane_words() { + local expl + local -a w + if [[ -z "$TMUX_PANE" ]]; then + _message "not running inside tmux!" + return 1 + fi + + # Based on vim-tmuxcomplete's splitwords function. + # https://github.com/wellle/tmux-complete.vim/blob/master/sh/tmuxcomplete + _tmux_capture_pane() { + tmux capture-pane -J -p -S -100 $@ | + # Remove "^C". + sed 's/\^C\S*/ /g' | + # copy lines and split words + sed -e 'p;s/[^a-zA-Z0-9_]/ /g' | + # split on spaces + tr -s '[:space:]' '\n' | + # remove surrounding non-word characters + =grep -o "\w.*\w" + } + # Capture current pane first. + w=( ${(u)=$(_tmux_capture_pane)} ) + echo $w > /tmp/w1 + local i + for i in $(tmux list-panes -F '#D'); do + # Skip current pane (handled before). + [[ "$TMUX_PANE" = "$i" ]] && continue + w+=( ${(u)=$(_tmux_capture_pane -t $i)} ) + done + _wanted values expl 'word from current tmux pane' compadd -a w +} + +zle -C tmux-pane-words-prefix complete-word _generic +zle -C tmux-pane-words-anywhere complete-word _generic + +zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words +zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current +# Display the menu on first execution of the hotkey. +zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' menu yes select +zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}' + +# }}} + +# }}} + +# Bindkeys {{{ +# ============ + +bindkey -v + +bindkey '^X^T' tmux-pane-words-prefix + +bindkey '^[[A' history-substring-search-up +bindkey '^[[B' history-substring-search-down +bindkey '^[OA' history-substring-search-up +bindkey '^[OB' history-substring-search-down + +# }}} + +# Aliases {{{ +# =========== + +# Some aliases taken from the Prezo zsh configuration framework: +# https://github.com/sorin-ionescu/prezto + +# Git {{{ +# ------- + +alias g='git' + +# Branch (b) +alias gb='git branch' + +# Commit (c) +alias gc='git commit --verbose' +alias gca='git commit --verbose --all' +alias gcf='git commit --amend --reuse-message HEAD' +alias gcs='git show' + +alias gco='git checkout' +alias gcO='git checkout --patch' + +# Fetch (f) +alias gf='git fetch' +alias gfm='git pull' +alias gfc='git clone' +alias gfcr='git clone --recurse-submodules' + +# Index (i) +alias gia='git add' +alias giA='git add --patch' +alias gid='git diff --cached' +alias giD='git diff --cached --word-diff' + +# Log (l) +logMediumFormat='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B' +logBriefFormat='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n' +logOnelineFormat='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n' + +alias gl='git log --topo-order --pretty=format:"${logMediumFormat}"' +alias gls='git log --topo-order --stat --pretty=format:"${logMediumFormat}"' +alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${logMediumFormat}"' +alias glg='git log --topo-order --all --graph --pretty=format:"${logOnelineFormat}"' +alias glo='git log --topo-order --pretty=format:"${logOnelineFormat}"' +alias glb='git log --topo-order --pretty=format:"${logBriefFormat}"' +alias glc='git shortlog --summary --numbered' + +# Merge (m) +alias gm='git merge' +alias gmt='git mergetool' + +# Push (p) +alias gp='git push' +alias gpf='git push --force-with-lease' +alias gpt='git push --tags' + +# Rebase (r) +alias gr='git rebase' + +# Stash (s) +alias gs='git stash' + +# Working Copy (w) +alias gws='git status --ignore-submodules=none' +alias gwd='git diff' +alias gwD='git diff --word-diff' + +# }}} + +# Prevents some mistakes +alias cp='cp -i' +alias mv='mv -i' +alias rm='rm -i' + +# }}} + +# Helpful functions {{{ +# ===================== + +function ssht +{ + /usr/bin/env ssh -t "$@" "tmux new-session -A -s 'ssh-$HOST'" +} + +compdef ssht=ssh + +# }}} + +# Abbreviations {{{ +# ================= + +# Abbreviation system provided by the grml config +# More info here: +# http://www.zshwiki.org/home/examples/zleiab + +abk=( + 'P' '|& ${(z)PAGER}' + 'L' '|& ${(z)PAGER}' + + 'HL' ' --help |& ${(z)PAGER}' + + 'G' '|& rg' + 'FG' '|& rg -F' + + 'H' '| head' + 'T' '| tail' + 'C' '| wc -l' +) + +# }}} + +# GPG / SSH agents {{{ +# ==================== + +#function _gpg-agent-update-tty +#{ +# gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null +#} +# +#add-zsh-hook preexec _gpg-agent-update-tty + +# }}} + +# vim: fdm=marker diff --git a/lib/theme.nix b/lib/theme.nix new file mode 100644 index 0000000..72e43bc --- /dev/null +++ b/lib/theme.nix @@ -0,0 +1,35 @@ +{ lib, ... }: + +with lib; +let + # Convert 2 consecutive characters from a string from hexadecimal to decimal + hex2dec = str: start: + let + conversionTable = { + "0" = 0; "1" = 1; "2" = 2; "3" = 3; "4" = 4; + "5" = 5; "6" = 6; "7" = 7; "8" = 8; "9" = 9; + "a" = 10; "b" = 11; "c" = 12; + "d" = 13; "e" = 14; "f" = 15; + }; + firstHexDigit = toLower (elemAt (stringToCharacters str) start); + secondHexDigit = toLower (elemAt (stringToCharacters str) (start + 1)); + in conversionTable.${firstHexDigit} * 16 + conversionTable.${secondHexDigit}; + + makeColorCode = color: + let genComponent = hex2dec color; + in "${toString (genComponent 1)};${toString (genComponent 3)};${toString (genComponent 5)}"; + + hex2RGB = color: + let genComponent = hex2dec color; + in { + red = genComponent 1; + green = genComponent 3; + blue = genComponent 5; + }; + + fgEscapeCode = hexCode: "[38;2;${makeColorCode hexCode}m"; + bgEscapeCode = hexCode: "[48;2;${makeColorCode hexCode}m"; +in +{ + inherit fgEscapeCode bgEscapeCode hex2RGB; +} diff --git a/profiles/server.nix b/profiles/server.nix new file mode 100644 index 0000000..3084d26 --- /dev/null +++ b/profiles/server.nix @@ -0,0 +1,9 @@ +{ modulesPath, ... }: + +{ + imports = [ + (modulesPath + "/profiles/headless.nix") + (modulesPath + "/profiles/hardened.nix") + ]; + +} -- cgit v1.2.3