From d15473aa173dac79b910d5fd71742f1ab58edb24 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Fri, 25 Jul 2025 23:25:21 +0200 Subject: [PATCH] Initial Nix configuration setup - Add nix-darwin and home-manager flake configuration - Include modular neovim setup with plugins and keybinds - Add tmux configuration with gruvbox theme and vim-like bindings - Set up .gitignore for nix build outputs and temporary files Ready for multi-machine deployment across macOS systems. --- .gitignore | 19 ++++++++ flake.lock | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 69 ++++++++++++++++++++++++++ nvim.nix | 66 +++++++++++++++++++++++++ tmux.nix | 98 +++++++++++++++++++++++++++++++++++++ 5 files changed, 391 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nvim.nix create mode 100644 tmux.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4032d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Nix build outputs +result +result-* + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Editor temporary files +*~ +.#* +#*# +*.swp +*.swo \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..02a57e0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,139 @@ +{ + "nodes": { + "claude-code": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1752797049, + "narHash": "sha256-bc8KceOB9tAl8reHLGRcHfHx1sga0uMCA7koXWQp3A8=", + "owner": "sadjow", + "repo": "claude-code-nix", + "rev": "ce6b22f6c2b7fa6d24ee1080560909804a33a196", + "type": "github" + }, + "original": { + "owner": "sadjow", + "repo": "claude-code-nix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1752814804, + "narHash": "sha256-irfg7lnfEpJY+3Cffkluzp2MTVw1Uq9QGxFp6qadcXI=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "d0300c8808e41da81d6edfc202f3d3833c157daf", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747494142, + "narHash": "sha256-7TAUwDVZWq82t/x3+zZ5y+Tjl2hLL2c8+8pv9zCUbTo=", + "owner": "nix-darwin", + "repo": "nix-darwin", + "rev": "8e251e45346e9d58e0eece2512e40c183f967e8f", + "type": "github" + }, + "original": { + "owner": "nix-darwin", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1752747119, + "narHash": "sha256-2Kp9St3Pbsmu+xMsobLcgzzUxPvZR7alVJWyuk2BAPc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "fa0ef8a6bb1651aa26c939aeb51b5f499e86b0ec", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1747426788, + "narHash": "sha256-N4cp0asTsJCnRMFZ/k19V9akkxb7J/opG+K+jU57JGc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "12a55407652e04dcf2309436eb06fef0d3713ef3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "claude-code": "claude-code", + "home-manager": "home-manager", + "nix-darwin": "nix-darwin", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7f78304 --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + description = "Default environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nix-darwin.url = "github:nix-darwin/nix-darwin/master"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + claude-code.url = "github:sadjow/claude-code-nix"; + }; + + outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager, claude-code }: + let + configuration = { pkgs, ... }: { + environment.systemPackages = + [ pkgs.vim + pkgs.git + ]; + + nix.settings.experimental-features = "nix-command flakes"; + system.stateVersion = 6; + nixpkgs.hostPlatform = "aarch64-darwin"; + + programs.zsh.enable = true; + }; + + homeConfiguration = { pkgs, ... }: { + imports = [ ./nvim.nix ./tmux.nix ]; + + home.username = "yanlin"; + home.homeDirectory = "/Users/yanlin"; + home.stateVersion = "24.05"; + + home.packages = with pkgs; [ + texlive.combined.scheme-full + btop + python312 + python312Packages.pip + python312Packages.virtualenv + lftp + claude-code.packages.aarch64-darwin.claude-code + nerd-fonts.fira-code + nerd-fonts.jetbrains-mono + ]; + + fonts.fontconfig.enable = true; + + programs.home-manager.enable = true; + + programs.zsh = { + enable = true; + defaultKeymap = "viins"; + enableVteIntegration = true; + }; + }; + in + { + darwinConfigurations."iMac" = nix-darwin.lib.darwinSystem { + modules = [ configuration ]; + }; + + homeConfigurations.yanlin = home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.aarch64-darwin; + modules = [ homeConfiguration ]; + extraSpecialArgs = { inherit claude-code; }; + }; + }; +} diff --git a/nvim.nix b/nvim.nix new file mode 100644 index 0000000..77ad6bf --- /dev/null +++ b/nvim.nix @@ -0,0 +1,66 @@ +{ pkgs, ... }: + +{ + programs.neovim = { + enable = true; + defaultEditor = true; + plugins = with pkgs.vimPlugins; [ + nvim-tree-lua + nvim-treesitter.withAllGrammars + lualine-nvim + nvim-web-devicons + ]; + extraLuaConfig = '' + -- Basic settings + vim.opt.number = true + vim.opt.relativenumber = false + vim.opt.expandtab = true + vim.opt.shiftwidth = 2 + vim.opt.tabstop = 2 + vim.opt.smartindent = true + vim.opt.wrap = false + vim.opt.termguicolors = true + + -- Enable filetype detection and syntax + vim.cmd('filetype on') + vim.cmd('filetype plugin on') + vim.cmd('filetype indent on') + vim.cmd('syntax enable') + + -- Leader key + vim.g.mapleader = " " + + -- Use terminal default colors - no custom colorscheme + + -- Nvim-tree setup + require("nvim-tree").setup({}) + vim.keymap.set("n", "e", ":NvimTreeToggle", { desc = "Toggle file explorer" }) + + -- Treesitter setup + require('nvim-treesitter.configs').setup({ + highlight = { + enable = true, + additional_vim_regex_highlighting = true, + }, + indent = { + enable = true, + }, + ensure_installed = {}, -- Managed by Nix + auto_install = false, + }) + + -- Lualine setup + require('lualine').setup({ + options = { + theme = 'gruvbox_dark', + component_separators = { left = '|', right = '|'}, + section_separators = { left = ' ', right = ' '}, + }, + }) + + -- Basic keymaps + vim.keymap.set("n", "w", ":w", { desc = "Save file" }) + vim.keymap.set("n", "q", ":q", { desc = "Quit" }) + ''; + }; +} diff --git a/tmux.nix b/tmux.nix new file mode 100644 index 0000000..2b25691 --- /dev/null +++ b/tmux.nix @@ -0,0 +1,98 @@ +{ pkgs, ... }: + +{ + programs.tmux = { + enable = true; + shortcut = "b"; + baseIndex = 1; # Start windows and panes at 1, not 0 + mouse = true; # Enable mouse support + keyMode = "vi"; # Use vi key bindings in copy mode + + extraConfig = '' + # Terminal settings + set -g default-terminal "screen-256color" + set -ga terminal-overrides ",*256col*:Tc" + + # Gruvbox Dark Theme + # Status bar colors + set -g status-style 'bg=#282828,fg=#ebdbb2' + set -g status-left-style 'bg=#a89984,fg=#282828' + set -g status-right-style 'bg=#a89984,fg=#282828' + + # Window status colors + set -g window-status-style 'bg=#3c3836,fg=#a89984' + set -g window-status-current-style 'bg=#fabd2f,fg=#282828' + set -g window-status-activity-style 'bg=#fb4934,fg=#282828' + + # Pane border colors + set -g pane-border-style 'fg=#3c3836' + set -g pane-active-border-style 'fg=#fabd2f' + + # Message colors + set -g message-style 'bg=#fabd2f,fg=#282828' + set -g message-command-style 'bg=#fabd2f,fg=#282828' + + # Status bar content + set -g status-left-length 40 + set -g status-right-length 50 + set -g status-left ' #S ' + set -g status-right ' %H:%M %d-%b-%y ' + + # Window status format + set -g window-status-format ' #I:#W ' + set -g window-status-current-format ' #I:#W ' + + # Better key bindings for splitting panes + bind | split-window -h -c "#{pane_current_path}" + bind - split-window -v -c "#{pane_current_path}" + unbind '"' + unbind % + + # Vim-like pane navigation + bind h select-pane -L + bind j select-pane -D + bind k select-pane -U + bind l select-pane -R + + # Vim-like pane resizing + bind -r H resize-pane -L 5 + bind -r J resize-pane -D 5 + bind -r K resize-pane -U 5 + bind -r L resize-pane -R 5 + + # Quick pane cycling + unbind o + bind ^A select-pane -t :.+ + + # Reload config file + bind r source-file ~/.config/tmux/tmux.conf \; display-message "Config reloaded!" + + # Better copy mode + bind-key -T copy-mode-vi v send-keys -X begin-selection + bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" + bind-key -T copy-mode-vi r send-keys -X rectangle-toggle + + # New window with current path + bind c new-window -c "#{pane_current_path}" + + # Don't rename windows automatically + set-option -g allow-rename off + + # Increase scrollback buffer size + set -g history-limit 10000 + + # Display messages for longer + set -g display-time 2000 + + # Faster command sequences + set -s escape-time 0 + + # Activity monitoring + setw -g monitor-activity on + set -g visual-activity off + + # Automatically renumber windows + set -g renumber-windows on + ''; + }; +}