From b50e4e489c6affc86b78829626f938a0ba43091b Mon Sep 17 00:00:00 2001 From: Wong Ding Feng Date: Sat, 15 Nov 2025 23:45:33 +0800 Subject: [PATCH] a --- flake.lock | 37 ++++-- home-manager/README.md | 79 +++++++++++++ home-manager/common.nix | 23 ---- home-manager/development.nix | 76 ------------ home-manager/home.nix | 18 +-- home-manager/modules/cli-tools.nix | 39 +++++++ home-manager/modules/dev-tools.nix | 46 ++++++++ home-manager/modules/editors.nix | 27 +++++ home-manager/modules/git.nix | 40 +++++++ home-manager/modules/multiplexers.nix | 47 ++++++++ .../{shell.nix => modules/shells.nix} | 2 +- home-manager/modules/terminal-emulators.nix | 39 +++++++ home-manager/{ => platform}/darwin.nix | 0 home-manager/{ => platform}/linux.nix | 0 home-manager/terminal.nix | 110 ------------------ 15 files changed, 358 insertions(+), 225 deletions(-) create mode 100644 home-manager/README.md delete mode 100644 home-manager/development.nix create mode 100644 home-manager/modules/cli-tools.nix create mode 100644 home-manager/modules/dev-tools.nix create mode 100644 home-manager/modules/editors.nix create mode 100644 home-manager/modules/git.nix create mode 100644 home-manager/modules/multiplexers.nix rename home-manager/{shell.nix => modules/shells.nix} (97%) create mode 100644 home-manager/modules/terminal-emulators.nix rename home-manager/{ => platform}/darwin.nix (100%) rename home-manager/{ => platform}/linux.nix (100%) delete mode 100644 home-manager/terminal.nix diff --git a/flake.lock b/flake.lock index cf2a756..e90805a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,25 @@ { "nodes": { + "darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1763136804, + "narHash": "sha256-6p2ljK42s0S8zS0UU59EsEqupz0GVCaBYRylpUadeBM=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "973db96394513fd90270ea5a1211a82a4a0ba47f", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -7,32 +27,32 @@ ] }, "locked": { - "lastModified": 1714043624, - "narHash": "sha256-Xn2r0Jv95TswvPlvamCC46wwNo8ALjRCMBJbGykdhcM=", + "lastModified": 1726989464, + "narHash": "sha256-Vl+WVTJwutXkimwGprnEtXc/s/s8sMuXzqXaspIGlwM=", "owner": "nix-community", "repo": "home-manager", - "rev": "86853e31dc1b62c6eeed11c667e8cdd0285d4411", + "rev": "2f23fa308a7c067e52dfcc30a0758f47043ec176", "type": "github" }, "original": { "owner": "nix-community", - "ref": "release-23.11", + "ref": "release-24.05", "repo": "home-manager", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1713995372, - "narHash": "sha256-fFE3M0vCoiSwCX02z8VF58jXFRj9enYUSTqjyHAjrds=", + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "dd37924974b9202f8226ed5d74a252a9785aedf8", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-23.11", + "ref": "nixos-24.05", "repo": "nixpkgs", "type": "github" } @@ -55,6 +75,7 @@ }, "root": { "inputs": { + "darwin": "darwin", "home-manager": "home-manager", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable" diff --git a/home-manager/README.md b/home-manager/README.md new file mode 100644 index 0000000..3187956 --- /dev/null +++ b/home-manager/README.md @@ -0,0 +1,79 @@ +# Home-Manager Configuration + +This directory contains a refactored, modular home-manager configuration organized by program/tool. + +## Directory Structure + +``` +home-manager/ +├── home.nix # Main entry point with all imports +├── common.nix # Base configuration (overlays, minimal packages) +│ +├── platform/ # Platform-specific configurations +│ ├── darwin.nix # macOS-specific settings +│ └── linux.nix # Linux-specific settings +│ +└── modules/ # Modular configurations by program/tool + ├── git.nix # Git configuration (unified from old common + development) + ├── shells.nix # Bash, Zsh, Fish configurations + ├── cli-tools.nix # Modern CLI tools (ripgrep, fd, bat, etc.) + ├── terminal-emulators.nix # Terminal emulator configs (Alacritty) + ├── editors.nix # Text editor configs (Neovim) + ├── multiplexers.nix # Terminal multiplexers (tmux) + └── dev-tools.nix # Development tools (gh, lazygit, direnv) +``` + +## What Changed? + +### Problems Solved + +1. **Git configuration conflict**: Previously, both `common.nix` and `development.nix` configured `programs.git`, causing conflicts. Now unified in `modules/git.nix` + +2. **Package duplication**: Tools like `ripgrep` and `fd` were listed in multiple files. Now centralized in `modules/cli-tools.nix` + +3. **Unclear module boundaries**: `development.nix` mixed version control, build tools, and editors without clear purpose. Now split into focused modules. + +4. **Mixed concerns**: `terminal.nix` contained terminal emulator + CLI tools + text editor + tmux. Now properly separated. + +### File Mapping + +| Old File | New Location | +|----------|--------------| +| `development.nix` | → Split into `modules/git.nix` and `modules/dev-tools.nix` | +| `shell.nix` | → `modules/shells.nix` | +| `terminal.nix` | → Split into `modules/terminal-emulators.nix`, `modules/editors.nix`, `modules/multiplexers.nix`, and `modules/cli-tools.nix` | +| `common.nix` | → Simplified (git config moved to `modules/git.nix`, CLI tools to `modules/cli-tools.nix`) | +| `darwin.nix` | → `platform/darwin.nix` | +| `linux.nix` | → `platform/linux.nix` | + +## Benefits + +- **Clear separation of concerns**: Each module has a single, well-defined purpose +- **No more conflicts**: Git is configured in one place +- **No duplication**: Packages appear once +- **Easy to find things**: Need to configure git? Check `modules/git.nix` +- **Easy to disable features**: Comment out imports in `home.nix` +- **Platform-specific code isolated**: macOS and Linux configs clearly separated + +## Usage + +To disable a feature, simply comment out its import in `home.nix`: + +```nix +imports = [ + ./common.nix + ./platform/darwin.nix + ./platform/linux.nix + ./modules/git.nix + ./modules/shells.nix + # ./modules/multiplexers.nix # Disable tmux + # ... +]; +``` + +## Next Steps + +1. Configure your git identity in `modules/git.nix` (lines 11-13) +2. Enable/disable optional packages in each module as needed +3. Add new modules following the same pattern (one file per program/tool category) + diff --git a/home-manager/common.nix b/home-manager/common.nix index 9061dc4..e624f91 100644 --- a/home-manager/common.nix +++ b/home-manager/common.nix @@ -29,31 +29,8 @@ # Archives zip unzip - - # Utils - ripgrep # Better grep - fd # Better find - jq # JSON processor - yq-go # YAML processor - - # System tools - htop - tree - wget - curl ]; - # Basic git configuration - programs.git = { - enable = true; - extraConfig = { - init.defaultBranch = "main"; - pull.rebase = true; - push.autoSetupRemote = true; - }; - }; - # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion home.stateVersion = "24.05"; } - diff --git a/home-manager/development.nix b/home-manager/development.nix deleted file mode 100644 index 3a18aaf..0000000 --- a/home-manager/development.nix +++ /dev/null @@ -1,76 +0,0 @@ -# Development tools and environment -{ - inputs, - lib, - config, - pkgs, - ... -}: { - home.packages = with pkgs; [ - # Version control - git - gh # GitHub CLI - lazygit # Terminal UI for git - - # Languages and runtimes (add what you need) - # python311 - # nodejs_20 - # go - # rustc - # cargo - - # Build tools - gnumake - cmake - - # Text editors / IDEs - # neovim - # vscode - - # Docker and containers (Linux only, macOS uses Docker Desktop) - ] ++ lib.optionals pkgs.stdenv.isLinux [ - # docker - # docker-compose - ]; - - # Git configuration for development - programs.git = { - enable = true; - # TODO: Configure your git identity - # userName = "Your Name"; - # userEmail = "your.email@example.com"; - - extraConfig = { - core.editor = "vim"; - merge.conflictstyle = "diff3"; - diff.algorithm = "histogram"; - }; - - # Git aliases - aliases = { - st = "status"; - co = "checkout"; - br = "branch"; - ci = "commit"; - unstage = "reset HEAD --"; - last = "log -1 HEAD"; - lg = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"; - }; - }; - - # GitHub CLI - programs.gh = { - enable = true; - settings = { - git_protocol = "ssh"; - prompt = "enabled"; - }; - }; - - # Direnv for per-directory environments - programs.direnv = { - enable = true; - nix-direnv.enable = true; - }; -} - diff --git a/home-manager/home.nix b/home-manager/home.nix index b72248d..df1eaad 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -12,14 +12,18 @@ # Base configuration shared across all platforms ./common.nix - # Feature modules - ./development.nix - ./shell.nix - ./terminal.nix - # Platform-specific configurations - ./linux.nix - ./darwin.nix + ./platform/darwin.nix + ./platform/linux.nix + + # Modular configurations by program/tool + ./modules/git.nix + ./modules/shells.nix + ./modules/cli-tools.nix + ./modules/terminal-emulators.nix + ./modules/editors.nix + ./modules/multiplexers.nix + ./modules/dev-tools.nix # If you want to use modules your own flake exports (from modules/home-manager): # inputs.self.homeManagerModules.example diff --git a/home-manager/modules/cli-tools.nix b/home-manager/modules/cli-tools.nix new file mode 100644 index 0000000..436d670 --- /dev/null +++ b/home-manager/modules/cli-tools.nix @@ -0,0 +1,39 @@ +# Modern CLI tools and utilities +{ + inputs, + lib, + config, + pkgs, + ... +}: { + home.packages = with pkgs; [ + # Modern replacements for standard tools + ripgrep # Better grep + fd # Better find + sd # Better sed + du-dust # Better du + duf # Better df + procs # Better ps + bottom # Better top/htop + + # System monitoring + htop + + # File utilities + tree + + # Network tools + wget + curl + + # Text processing + jq # JSON processor + yq-go # YAML processor + + # Optional file managers (commented out by default) + # ranger + # nnn + # lf + ]; +} + diff --git a/home-manager/modules/dev-tools.nix b/home-manager/modules/dev-tools.nix new file mode 100644 index 0000000..b588a4c --- /dev/null +++ b/home-manager/modules/dev-tools.nix @@ -0,0 +1,46 @@ +# Development tools and utilities +{ + inputs, + lib, + config, + pkgs, + ... +}: { + home.packages = with pkgs; [ + # Version control tools + gh # GitHub CLI + lazygit # Terminal UI for git + + # Build tools + gnumake + cmake + + # Optional language runtimes (uncomment as needed) + # python311 + # nodejs_20 + # go + # rustc + # cargo + + # Docker and containers (Linux only, macOS uses Docker Desktop) + ] ++ lib.optionals pkgs.stdenv.isLinux [ + # docker + # docker-compose + ]; + + # GitHub CLI configuration + programs.gh = { + enable = true; + settings = { + git_protocol = "ssh"; + prompt = "enabled"; + }; + }; + + # Direnv for per-directory environments + programs.direnv = { + enable = true; + nix-direnv.enable = true; + }; +} + diff --git a/home-manager/modules/editors.nix b/home-manager/modules/editors.nix new file mode 100644 index 0000000..efe6b6a --- /dev/null +++ b/home-manager/modules/editors.nix @@ -0,0 +1,27 @@ +# Text editor configurations +{ + inputs, + lib, + config, + pkgs, + ... +}: { + # Neovim configuration + programs.neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + + extraConfig = '' + set number + set relativenumber + set expandtab + set tabstop=2 + set shiftwidth=2 + set smartindent + set clipboard=unnamedplus + ''; + }; +} + diff --git a/home-manager/modules/git.nix b/home-manager/modules/git.nix new file mode 100644 index 0000000..af55a2c --- /dev/null +++ b/home-manager/modules/git.nix @@ -0,0 +1,40 @@ +# Git configuration - unified from common.nix and development.nix +{ + inputs, + lib, + config, + pkgs, + ... +}: { + programs.git = { + enable = true; + + # TODO: Configure your git identity + # userName = "Your Name"; + # userEmail = "your.email@example.com"; + + extraConfig = { + # From common.nix + init.defaultBranch = "main"; + pull.rebase = true; + push.autoSetupRemote = true; + + # From development.nix + core.editor = "vim"; + merge.conflictstyle = "diff3"; + diff.algorithm = "histogram"; + }; + + # Git aliases + aliases = { + st = "status"; + co = "checkout"; + br = "branch"; + ci = "commit"; + unstage = "reset HEAD --"; + last = "log -1 HEAD"; + lg = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"; + }; + }; +} + diff --git a/home-manager/modules/multiplexers.nix b/home-manager/modules/multiplexers.nix new file mode 100644 index 0000000..463b74c --- /dev/null +++ b/home-manager/modules/multiplexers.nix @@ -0,0 +1,47 @@ +# Terminal multiplexer configurations +{ + inputs, + lib, + config, + pkgs, + ... +}: { + home.packages = with pkgs; [ + # Optional multiplexers (tmux enabled by default below) + # zellij + ]; + + # Tmux configuration + programs.tmux = { + enable = true; + terminal = "tmux-256color"; + historyLimit = 10000; + baseIndex = 1; + keyMode = "vi"; + mouse = true; + + plugins = with pkgs.tmuxPlugins; [ + sensible + yank + vim-tmux-navigator + ]; + + extraConfig = '' + # Split panes using | and - + bind | split-window -h + bind - split-window -v + unbind '"' + unbind % + + # Reload config + bind r source-file ~/.config/tmux/tmux.conf + + # Easy pane switching + bind -n M-Left select-pane -L + bind -n M-Right select-pane -R + bind -n M-Up select-pane -U + bind -n M-Down select-pane -D + ''; + }; +} + diff --git a/home-manager/shell.nix b/home-manager/modules/shells.nix similarity index 97% rename from home-manager/shell.nix rename to home-manager/modules/shells.nix index f3290c5..1b070e4 100644 --- a/home-manager/shell.nix +++ b/home-manager/modules/shells.nix @@ -1,4 +1,4 @@ -# Shell configuration (bash, zsh, fish, etc.) +# Shell configuration (bash, zsh, fish) with integrations { inputs, lib, diff --git a/home-manager/modules/terminal-emulators.nix b/home-manager/modules/terminal-emulators.nix new file mode 100644 index 0000000..048489d --- /dev/null +++ b/home-manager/modules/terminal-emulators.nix @@ -0,0 +1,39 @@ +# Terminal emulator configurations +{ + inputs, + lib, + config, + pkgs, + ... +}: { + # Alacritty terminal emulator configuration + programs.alacritty = { + enable = true; + settings = { + window = { + padding = { + x = 10; + y = 10; + }; + decorations = "full"; + opacity = 0.95; + }; + + font = { + size = 13.0; + normal = { + family = "JetBrainsMono Nerd Font"; + style = "Regular"; + }; + }; + + colors = { + primary = { + background = "0x1e1e1e"; + foreground = "0xd4d4d4"; + }; + }; + }; + }; +} + diff --git a/home-manager/darwin.nix b/home-manager/platform/darwin.nix similarity index 100% rename from home-manager/darwin.nix rename to home-manager/platform/darwin.nix diff --git a/home-manager/linux.nix b/home-manager/platform/linux.nix similarity index 100% rename from home-manager/linux.nix rename to home-manager/platform/linux.nix diff --git a/home-manager/terminal.nix b/home-manager/terminal.nix deleted file mode 100644 index 3b50c80..0000000 --- a/home-manager/terminal.nix +++ /dev/null @@ -1,110 +0,0 @@ -# Terminal applications and utilities -{ - inputs, - lib, - config, - pkgs, - ... -}: { - home.packages = with pkgs; [ - # Modern CLI tools - ripgrep # Better grep - fd # Better find - sd # Better sed - du-dust # Better du - duf # Better df - procs # Better ps - bottom # Better top/htop - - # File managers - # ranger - # nnn - # lf - - # Multiplexers - # tmux - # zellij - ]; - - # Tmux configuration - programs.tmux = { - enable = true; - terminal = "tmux-256color"; - historyLimit = 10000; - baseIndex = 1; - keyMode = "vi"; - mouse = true; - - plugins = with pkgs.tmuxPlugins; [ - sensible - yank - vim-tmux-navigator - ]; - - extraConfig = '' - # Split panes using | and - - bind | split-window -h - bind - split-window -v - unbind '"' - unbind % - - # Reload config - bind r source-file ~/.config/tmux/tmux.conf - - # Easy pane switching - bind -n M-Left select-pane -L - bind -n M-Right select-pane -R - bind -n M-Up select-pane -U - bind -n M-Down select-pane -D - ''; - }; - - # Neovim (optional, can be expanded) - programs.neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - - extraConfig = '' - set number - set relativenumber - set expandtab - set tabstop=2 - set shiftwidth=2 - set smartindent - set clipboard=unnamedplus - ''; - }; - - # Alacritty terminal emulator configuration - programs.alacritty = { - enable = true; - settings = { - window = { - padding = { - x = 10; - y = 10; - }; - decorations = "full"; - opacity = 0.95; - }; - - font = { - size = 13.0; - normal = { - family = "JetBrainsMono Nerd Font"; - style = "Regular"; - }; - }; - - colors = { - primary = { - background = "0x1e1e1e"; - foreground = "0xd4d4d4"; - }; - }; - }; - }; -} -