From 11d7923b72b8a5ab056a162347cb62ab6b0d1bef Mon Sep 17 00:00:00 2001
From: Crony Akatsuki <crony@cronyakatsuki.xyz>
Date: Thu, 30 Jan 2025 11:30:49 +0100
Subject: [PATCH] Modulize home.nix into a couple of modules.

---
 hosts/nixos/home.nix              | 164 +-----------------------------
 modules/home-manager/default.nix  |   9 +-
 modules/home-manager/mangohud.nix |  45 ++++++++
 modules/home-manager/neovim.nix   | 104 +++++++++++++++++++
 modules/home-manager/tmux.nix     |  81 +++++++++++++++
 modules/home-manager/zsh.nix      |  45 ++++++++
 6 files changed, 285 insertions(+), 163 deletions(-)
 create mode 100644 modules/home-manager/mangohud.nix
 create mode 100644 modules/home-manager/neovim.nix
 create mode 100644 modules/home-manager/tmux.nix
 create mode 100644 modules/home-manager/zsh.nix

diff --git a/hosts/nixos/home.nix b/hosts/nixos/home.nix
index 9d93e6c..a61c41a 100644
--- a/hosts/nixos/home.nix
+++ b/hosts/nixos/home.nix
@@ -20,6 +20,7 @@
     nix-output-monitor
     nvd
     thunderbird
+    sesh
   ];
 
   # Install librewolf
@@ -31,43 +32,9 @@
     flake = "/home/crony/Repos/nixos";
   };
 
-  # Enable programs to get their themes
+  # Install foot
   programs.foot.enable = true;
 
-  # Setup nice view for mangohud
-  programs.mangohud = {
-    enable = true;
-    settings = {
-      fps_limit = "0,30,60,120,144";
-      gpu_stats = true;
-      gpu_temp = true;
-      gpu_core_clock = true;
-      gpu_power = true;
-      gpu_text = "GPU";
-      gpu_load_change = true;
-
-      cpu_stats = true;
-      cpu_temps = true;
-      cpu_text = "CPU";
-      cpu_mhz = true;
-      cpu_load_change = true;
-
-      vram = true;
-      ram = true;
-
-      fps = true;
-      fps_sampling_period = "1000";
-      fps_color_change = true;
-      gpu_name = true;
-      vulka_driver = true;
-      round_corder = "10";
-      offset_x = "10";
-      offset_y = "10";
-
-      width = "250";
-    };
-  };
-
   # Enable theming chromium + use ungoogled chromium package
   programs.chromium = {
     enable = true;
@@ -81,136 +48,9 @@
     userEmail = "crony@cronyakatsuki.xyz";
   };
 
-  # Setup neovim
-  programs.nvf = {
-    enable = true;
-    settings = {
-      vim = {
-        # Enable the aliases, I love them
-        viAlias = true;
-        vimAlias = true;
-
-        # Changing some basic settings
-        options = {
-          tabstop = 2;
-          shiftwidth = 2;
-          updatetime = 50;
-        };
-
-        # Enable the undo file
-        undoFile = {
-          enable = true;
-        };
-
-        binds = {
-          # Setup whichkey
-          whichKey.enable = true;
-        };
-
-        # Enable gitsings
-        git.gitsigns = {
-          enable = true;
-        };
-
-        # Enable lsp
-        lsp = {
-          enable = true;
-          lspkind.enable = true;
-        };
-
-        # Setup the theme
-        theme = {
-          enable = true;
-          name = "gruvbox";
-          style = "dark";
-        };
-
-        # Setup lsp's and languages
-        languages = {
-          enableLSP = true;
-          enableTreesitter = true;
-          enableFormat = true;
-
-          nix = {
-            enable = true;
-          };
-          bash.enable = true;
-          go.enable = true;
-          markdown = {
-            enable = true;
-            extensions.render-markdown-nvim.enable = true;
-          };
-        };
-
-        # Enable mini modules ( mini is amazing )
-        mini = {
-          statusline.enable = true;
-          comment.enable = true;
-          notify.enable = true;
-          surround.enable = true;
-          diff.enable = true;
-          pairs.enable = true;
-          indentscope.enable = true;
-          bufremove.enable = true;
-          git.enable = true;
-        };
-
-        # Use telescope
-        telescope.enable = true;
-
-        # Enable autocompletion
-        autocomplete.nvim-cmp = {
-          enable = true;
-
-          mappings = {
-            close = null;
-            complete = null;
-            confirm = "<C-l>";
-            next = "<C-j>";
-            previous = "<C-k>";
-          };
-        };
-      };
-    };
-  };
-
   # Enable syncthing
   services.syncthing.enable = true;
 
-  # Setup zsh
-  programs.zsh = {
-    enable = true;
-    enableCompletion = true;
-    autosuggestion.enable = true;
-    historySubstringSearch.enable = true;
-
-    dotDir = ".config/zsh";
-
-    initExtra = ''
-      # VI Mode escape timeout fix
-      export KEYTIMEOUT=1
-
-      # Substring search settings
-      export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND="bg=blue,fg=black,bold"
-      export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=black,bold'
-      bindkey -M vicmd 'k' history-substring-search-up
-      bindkey -M vicmd 'j' history-substring-search-down
-    '';
-
-    zplug = {
-      enable = true;
-      plugins = [
-        {name = "zap-zsh/supercharge";}
-        {name = "zap-zsh/completions";}
-        {name = "zap-zsh/vim";}
-        {name = "chivalryq/git-alias";}
-        {name = "zdharma-continuum/fast-syntax-highlighting";}
-        {name = "zsh-users/zsh-history-substring-search";}
-        {name = "MichaelAquilina/zsh-you-should-use";}
-      ];
-    };
-  };
-
   # Install fzf
   programs.fzf = {
     enable = true;
diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix
index 6462967..922fa2e 100644
--- a/modules/home-manager/default.nix
+++ b/modules/home-manager/default.nix
@@ -1 +1,8 @@
-{...}: {}
+{lib, ...}: {
+  imports = [./mangohud.nix ./neovim.nix ./zsh.nix ./tmux.nix];
+
+  crony.mangohud.enable = lib.mkDefault true;
+  crony.neovim.enable = lib.mkDefault true;
+  crony.zsh.enable = lib.mkDefault true;
+  crony.tmux.enable = lib.mkDefault true;
+}
diff --git a/modules/home-manager/mangohud.nix b/modules/home-manager/mangohud.nix
new file mode 100644
index 0000000..7eebaf9
--- /dev/null
+++ b/modules/home-manager/mangohud.nix
@@ -0,0 +1,45 @@
+{
+  config,
+  lib,
+  ...
+}: {
+  options = {
+    crony.mangohud.enable = lib.mkEnableOption "Enable mangohud and customize it";
+  };
+
+  config = lib.mkIf config.crony.mangohud.enable {
+    # Setup nice view for mangohud
+    programs.mangohud = {
+      enable = true;
+      settings = {
+        fps_limit = "0,30,60,120,144";
+        gpu_stats = true;
+        gpu_temp = true;
+        gpu_core_clock = true;
+        gpu_power = true;
+        gpu_text = "GPU";
+        gpu_load_change = true;
+
+        cpu_stats = true;
+        cpu_temps = true;
+        cpu_text = "CPU";
+        cpu_mhz = true;
+        cpu_load_change = true;
+
+        vram = true;
+        ram = true;
+
+        fps = true;
+        fps_sampling_period = "1000";
+        fps_color_change = true;
+        gpu_name = true;
+        vulka_driver = true;
+        round_corder = "10";
+        offset_x = "10";
+        offset_y = "10";
+
+        width = "250";
+      };
+    };
+  };
+}
diff --git a/modules/home-manager/neovim.nix b/modules/home-manager/neovim.nix
new file mode 100644
index 0000000..f2014b5
--- /dev/null
+++ b/modules/home-manager/neovim.nix
@@ -0,0 +1,104 @@
+{
+  config,
+  lib,
+  ...
+}: {
+  options = {
+    crony.neovim.enable = lib.mkEnableOption "Enable neovim and apply a good config.";
+  };
+
+  config = lib.mkIf config.crony.neovim.enable {
+    # Setup neovim
+    programs.nvf = {
+      enable = true;
+      settings = {
+        vim = {
+          # Enable the aliases, I love them
+          viAlias = true;
+          vimAlias = true;
+
+          # Changing some basic settings
+          options = {
+            tabstop = 2;
+            shiftwidth = 2;
+            updatetime = 50;
+          };
+
+          # Enable the undo file
+          undoFile = {
+            enable = true;
+          };
+
+          binds = {
+            # Setup whichkey
+            whichKey.enable = true;
+          };
+
+          # Enable gitsings
+          git.gitsigns = {
+            enable = true;
+          };
+
+          # Enable lsp
+          lsp = {
+            enable = true;
+            lspkind.enable = true;
+          };
+
+          # Setup the theme
+          theme = {
+            enable = true;
+            name = "gruvbox";
+            style = "dark";
+          };
+
+          # Setup lsp's and languages
+          languages = {
+            enableLSP = true;
+            enableTreesitter = true;
+            enableFormat = true;
+
+            nix = {
+              enable = true;
+            };
+            bash.enable = true;
+            go.enable = true;
+            markdown = {
+              enable = true;
+              extensions.render-markdown-nvim.enable = true;
+            };
+          };
+
+          # Enable mini modules ( mini is amazing )
+          mini = {
+            statusline.enable = true;
+            comment.enable = true;
+            notify.enable = true;
+            surround.enable = true;
+            diff.enable = true;
+            pairs.enable = true;
+            indentscope.enable = true;
+            bufremove.enable = true;
+            git.enable = true;
+          };
+
+          # Use telescope
+          telescope.enable = true;
+
+          # Enable autocompletion
+          autocomplete.nvim-cmp = {
+            enable = true;
+
+            mappings = {
+              close = null;
+              complete = null;
+              confirm = "<C-l>";
+              next = "<C-j>";
+              previous = "<C-k>";
+            };
+          };
+        };
+      };
+    };
+  };
+}
diff --git a/modules/home-manager/tmux.nix b/modules/home-manager/tmux.nix
new file mode 100644
index 0000000..4a689d6
--- /dev/null
+++ b/modules/home-manager/tmux.nix
@@ -0,0 +1,81 @@
+{
+  config,
+  lib,
+  pkgs,
+  ...
+}: {
+  options = {
+    crony.tmux.enable = lib.mkEnableOption "Enable tmux and customize it";
+  };
+
+  config = lib.mkIf config.crony.tmux.enable {
+    programs.tmux = {
+      enable = true;
+      escapeTime = 0;
+      keyMode = "vi";
+      prefix = "C-Space";
+
+      extraConfig = ''
+        # start window and panes indexing at 1
+        set -g base-index 1
+        set -g pane-base-index 1
+        set-window-option -g pane-base-index 1
+        set-option -g renumber-windows on
+
+        # SPEED
+        set-option -g status-interval 1
+
+        # set vi-mode
+        set-window-option -g mode-keys vi
+        # keybindings
+        bind-key -T copy-mode-vi v send-keys -X begin-selection
+        bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
+        bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
+
+        bind "'" split-window -v -c "#{pane_current_path}"
+        bind '\' split-window -h -c "#{pane_current_path}"
+
+        # Vim keybindings for pane movement
+        setw -g mode-keys vi
+        bind-key h select-pane -L
+        bind-key j select-pane -D
+        bind-key k select-pane -U
+        bind-key l select-pane -R
+
+        # Skip kill pane %Number% (y/n) prompt
+        bind-key x kill-pane
+
+        # Don't exit from tmux when closing a session
+        set -g detach-on-destroy off
+
+        # Bar to top
+        set-option -g status-position top
+
+        # sesh for session management
+        bind-key "T" run-shell "sesh connect \"$(
+          sesh list --icons | fzf-tmux -p 55%,60% \
+            --no-sort --ansi --border-label ' sesh ' --prompt '⚡  ' \
+            --header '  ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
+            --bind 'tab:down,btab:up' \
+            --bind 'ctrl-a:change-prompt(⚡  )+reload(sesh list --icons)' \
+            --bind 'ctrl-t:change-prompt(🪟  )+reload(sesh list -t --icons)' \
+            --bind 'ctrl-g:change-prompt(⚙️  )+reload(sesh list -c --icons)' \
+            --bind 'ctrl-x:change-prompt(📁  )+reload(sesh list -z --icons)' \
+            --bind 'ctrl-f:change-prompt(🔎  )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
+            --bind 'ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(⚡  )+reload(sesh list --icons)' \
+        )\""
+
+        bind-key "n" run-shell "sesh connect nnn"
+
+        # use sesh for last session
+        bind -N "last-session (via sesh) " L run-shell "sesh last"
+      '';
+
+      plugins = with pkgs; [
+        tmuxPlugins.sensible
+        tmuxPlugins.yank
+        tmuxPlugins.fzf-tmux-url
+      ];
+    };
+  };
+}
diff --git a/modules/home-manager/zsh.nix b/modules/home-manager/zsh.nix
new file mode 100644
index 0000000..180cc94
--- /dev/null
+++ b/modules/home-manager/zsh.nix
@@ -0,0 +1,45 @@
+{
+  config,
+  lib,
+  ...
+}: {
+  options = {
+    crony.zsh.enable = lib.mkEnableOption "Enable zsh and customize it.";
+  };
+
+  config = lib.mkIf config.crony.zsh.enable {
+    # Setup zsh
+    programs.zsh = {
+      enable = true;
+      enableCompletion = true;
+      autosuggestion.enable = true;
+      historySubstringSearch.enable = true;
+
+      dotDir = ".config/zsh";
+
+      initExtra = ''
+        # VI Mode escape timeout fix
+        export KEYTIMEOUT=1
+
+        # Substring search settings
+        export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND="bg=blue,fg=black,bold"
+        export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=black,bold'
+        bindkey -M vicmd 'k' history-substring-search-up
+        bindkey -M vicmd 'j' history-substring-search-down
+      '';
+
+      zplug = {
+        enable = true;
+        plugins = [
+          {name = "zap-zsh/supercharge";}
+          {name = "zap-zsh/completions";}
+          {name = "zap-zsh/vim";}
+          {name = "chivalryq/git-alias";}
+          {name = "zdharma-continuum/fast-syntax-highlighting";}
+          {name = "zsh-users/zsh-history-substring-search";}
+          {name = "MichaelAquilina/zsh-you-should-use";}
+        ];
+      };
+    };
+  };
+}