diff --git a/home/.config/home-manager/fish.nix b/home/.config/home-manager/fish.nix new file mode 100644 index 00000000..b1f0bece --- /dev/null +++ b/home/.config/home-manager/fish.nix @@ -0,0 +1,53 @@ +{ pkgs, ... }: + +{ + xdg.configFile."fish/fish_variables".source = ../fish/fish_variables; + xdg.configFile."fish/functions/fish_prompt.fish".source = ../fish/functions/fish_prompt.fish; + + programs.fish = { + enable = true; + + shellInit = + '' + switch (uname -s) + case Linux + # Keep this comment + case Darwin + # nix + # https://github.com/NixOS/nix/issues/2280 + if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' + fenv source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' + end + case FreeBSD NetBSD DragonFly + # Keep this comment + case '*' + # Keep this comment + end + + # nix + if test -e "$HOME/.nix-profile/etc/profile.d/nix.sh" + fenv source "$HOME/.nix-profile/etc/profile.d/nix.sh" + end + + # home-manager + if test -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" + end + + # starship + if status is-interactive + starship init fish | source + end + ''; + + plugins = [{ + name = "foreign-env"; + src = pkgs.fetchFromGitHub { + owner = "oh-my-fish"; + repo = "plugin-foreign-env"; + rev = "3ee95536106c11073d6ff466c1681cde31001383"; + sha256 = "sha256-vyW/X2lLjsieMpP9Wi2bZPjReaZBkqUbkh15zOi8T4Y="; + }; + }]; + }; +} diff --git a/home/.config/home-manager/home.nix b/home/.config/home-manager/home.nix index 944d6cef..75d3762a 100644 --- a/home/.config/home-manager/home.nix +++ b/home/.config/home-manager/home.nix @@ -4,6 +4,13 @@ # - How to get sha256? => assume by `lib.fakeSha256` { + imports = [ + ./packages.nix + ./zsh.nix + ./fish.nix + ./nushell.nix + ]; + home.username = lib.mkDefault "kachick"; # TODO: How to cover lima? The default is /home/kachick.local home.homeDirectory = if pkgs.stdenv.hostPlatform.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}"; @@ -67,53 +74,6 @@ package = pkgs.nix; }; - programs.fish = { - enable = true; - - shellInit = - '' - switch (uname -s) - case Linux - # Keep this comment - case Darwin - # nix - # https://github.com/NixOS/nix/issues/2280 - if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' - fenv source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' - end - case FreeBSD NetBSD DragonFly - # Keep this comment - case '*' - # Keep this comment - end - - # nix - if test -e "$HOME/.nix-profile/etc/profile.d/nix.sh" - fenv source "$HOME/.nix-profile/etc/profile.d/nix.sh" - end - - # home-manager - if test -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" - fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" - end - - # starship - if status is-interactive - starship init fish | source - end - ''; - - plugins = [{ - name = "foreign-env"; - src = pkgs.fetchFromGitHub { - owner = "oh-my-fish"; - repo = "plugin-foreign-env"; - rev = "3ee95536106c11073d6ff466c1681cde31001383"; - sha256 = "sha256-vyW/X2lLjsieMpP9Wi2bZPjReaZBkqUbkh15zOi8T4Y="; - }; - }]; - }; - programs.readline = { enable = true; variables = { @@ -132,15 +92,10 @@ nix-direnv = { enable = true; }; - - enableZshIntegration = true; - enableNushellIntegration = true; }; programs.zoxide = { enable = true; - enableZshIntegration = true; - enableNushellIntegration = true; }; # https://nixos.wiki/wiki/Home_Manager @@ -149,8 +104,6 @@ xdg.configFile."home-manager/home.nix".source = ./home.nix; xdg.configFile."git/config".source = ../git/config; - xdg.configFile."fish/fish_variables".source = ../fish/fish_variables; - xdg.configFile."fish/functions/fish_prompt.fish".source = ../fish/functions/fish_prompt.fish; xdg.configFile."alacritty/alacritty.yml".source = ../alacritty/alacritty.yml; # Not under "starship/starship.toml" @@ -193,163 +146,12 @@ irb-power_assert ''; - # https://nixos.wiki/wiki/Zsh - # https://github.com/nix-community/home-manager/blob/master/modules/programs/zsh.nix - programs.zsh = { - enable = true; - - # How about to point `xdg.configFile`? - dotDir = ".config/zsh"; - - history = { - # in memory - size = 100000; - - # in file - save = 4200000; - path = "${config.xdg.stateHome}/zsh/history"; - - ignoreDups = true; - ignoreSpace = true; - - extended = true; - share = true; - }; - - historySubstringSearch = { - enable = true; - }; - enableSyntaxHighlighting = true; - enableAutosuggestions = true; - enableCompletion = true; - - # home-manager path will set in `programs.home-manager.enable = true`; - envExtra = '' - # https://wiki.archlinux.jp/index.php/XDG_Base_Directory - # https://www.reddit.com/r/zsh/comments/tpwx9t/zcompcache_vs_zcompdump/ - zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache" - - if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi # added by Nix installer - ''; - - initExtra = '' - typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='fg=blue,bold' - typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' - typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY='true' - - setopt correct - unsetopt BEEP - - setopt hist_ignore_all_dups - setopt hist_reduce_blanks - setopt hist_save_no_dups - setopt hist_no_store - - eval "$($XDG_DATA_HOME/rtx/bin/rtx activate -s zsh)" - - case ''${OSTYPE} in - darwin*) - test -e "''${HOME}/.iterm2_shell_integration.zsh" && source "''${HOME}/.iterm2_shell_integration.zsh" - ;; - esac - - # https://github.com/starship/starship/blob/0d98c4c0b7999f5a8bd6e7db68fd27b0696b3bef/docs/uk-UA/advanced-config/README.md#change-window-title - function set_win_title() { - echo -ne "\033]0; $(basename "$PWD") \007" - } - precmd_functions+=(set_win_title) - - zshaddhistory() { whence ''${''${(z)1}[1]} >| /dev/null || return 1 } - ''; - - # TODO: May move to sessionVariables - profileExtra = '' - if [[ "$OSTYPE" == darwin* ]]; then - export BROWSER='open' - fi - ''; - }; - - programs.nushell = { - enable = true; - - # Do not set `shell_integration: true for now` - # - window title requires `shell_integration: true` - https://github.com/nushell/nushell/issues/2527 - # - several terminal requires `shell_integration: false` - https://github.com/nushell/nushell/issues/6214 - extraConfig = '' - let-env config = { - show_banner: false - - keybindings: [ - # https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173 - { - name: fuzzy_history - modifier: control - keycode: char_r - mode: [emacs, vi_normal, vi_insert] - event: [ - { - send: ExecuteHostCommand - cmd: "commandline ( - history - | each { |it| $it.command } - | uniq - | reverse - | str join (char -i 0) - | fzf --read0 --layout=reverse --height=40% -q (commandline) - | decode utf-8 - | str trim - )" - } - ] - } - # Same as above for Up Arrow - { - name: fuzzy_history - modifier: control - keycode: Up - mode: [emacs, vi_normal, vi_insert] - event: [ - { - send: ExecuteHostCommand - cmd: "commandline ( - history - | each { |it| $it.command } - | uniq - | reverse - | str join (char -i 0) - | fzf --read0 --layout=reverse --height=40% -q (commandline) - | decode utf-8 - | str trim - )" - } - ] - } - ] - } - ''; - }; - programs.fzf = { enable = true; - - # enableShellIntegration = true; - - enableZshIntegration = true; - - # enableFishIntegration = true; - - # fzf manager does not have nushell integration yet. - # https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173 may help you. }; programs.starship = { enable = true; - - # enableShellIntegration = true; - enableZshIntegration = true; - # enableFishIntegration = true; - enableNushellIntegration = true; }; # - Tiny tools by me, they may be rewritten with another language. @@ -358,83 +160,4 @@ xdg.dataFile."homemade/bin/updeps".source = ../../../home/.local/share/homemade/bin/updeps.bash; xdg.dataFile."homemade/bin/la".source = ../../../home/.local/share/homemade/bin/la.bash; xdg.dataFile."homemade/bin/zj".source = ../../../home/.local/share/homemade/bin/zj.bash; - - home.packages = [ - pkgs.dprint - pkgs.gitleaks - pkgs.shellcheck - pkgs.shfmt - pkgs.git - pkgs.coreutils - pkgs.tig - pkgs.tree - pkgs.curl - pkgs.wget - pkgs.zsh - # Don't include bash - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730 - # pkgs.bash - pkgs.fish - pkgs.nushell - pkgs.starship - pkgs.jq - pkgs.gh - pkgs.direnv - pkgs.ripgrep - pkgs.fzf - pkgs.exa - pkgs.bat - pkgs.duf - pkgs.fd - pkgs.du-dust - pkgs.procs - pkgs.bottom - pkgs.tig - pkgs.zellij - pkgs.nixpkgs-fmt - pkgs.nil - pkgs.typos - pkgs.hyperfine - pkgs.zoxide - pkgs.difftastic - - # Required in many asdf(rtx) plugins - pkgs.unzip - - # Includes follows in each repository if needed, not in global - # pkgs.deno - # pkgs.rustup - # pkgs.go - # pkgs.crystal - # pkgs.elmPackages.elm - # pkgs.gcc - # pkgs.sqlite - # pkgs.postgresql - # pkgs.gnumake - # pkgs.cargo-make - - # This section is just a note for my strggle - # Often failed to build ruby even if I enabled following dependencies - # pkgs.zlib - # pkgs.libyaml - # pkgs.openssl - # - # Don't include nixpkgs ruby, because of installing into .nix-profile hides - # adhoc use of https://github.com/bobvanderlinden/nixpkgs-ruby - # pkgs.ruby - - # As a boardgamer - # pkgs.tesseract - # pkgs.imagemagick - # pkgs.pngquant - # pkgs.img2pdf - # pkgs.ocrmypdf - ] ++ ( - if pkgs.stdenv.hostPlatform.isDarwin then - [ ] - else - [ - # Fix missing locales as `locale: Cannot set LC_CTYPE to default locale` - pkgs.glibc - ] - ); } diff --git a/home/.config/home-manager/nushell.nix b/home/.config/home-manager/nushell.nix new file mode 100644 index 00000000..41c9da43 --- /dev/null +++ b/home/.config/home-manager/nushell.nix @@ -0,0 +1,70 @@ +{ ... }: + +{ + programs.starship.enableNushellIntegration = true; + programs.direnv.enableNushellIntegration = true; + programs.zoxide.enableNushellIntegration = true; + + programs.nushell = { + enable = true; + + # fzf manager does not have nushell integration yet. + # https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173 may help you. + + # Do not set `shell_integration: true for now` + # - window title requires `shell_integration: true` - https://github.com/nushell/nushell/issues/2527 + # - several terminal requires `shell_integration: false` - https://github.com/nushell/nushell/issues/6214 + extraConfig = '' + let-env config = { + show_banner: false + + keybindings: [ + # https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173 + { + name: fuzzy_history + modifier: control + keycode: char_r + mode: [emacs, vi_normal, vi_insert] + event: [ + { + send: ExecuteHostCommand + cmd: "commandline ( + history + | each { |it| $it.command } + | uniq + | reverse + | str join (char -i 0) + | fzf --read0 --layout=reverse --height=40% -q (commandline) + | decode utf-8 + | str trim + )" + } + ] + } + # Same as above for Up Arrow + { + name: fuzzy_history + modifier: control + keycode: Up + mode: [emacs, vi_normal, vi_insert] + event: [ + { + send: ExecuteHostCommand + cmd: "commandline ( + history + | each { |it| $it.command } + | uniq + | reverse + | str join (char -i 0) + | fzf --read0 --layout=reverse --height=40% -q (commandline) + | decode utf-8 + | str trim + )" + } + ] + } + ] + } + ''; + }; +} diff --git a/home/.config/home-manager/packages.nix b/home/.config/home-manager/packages.nix new file mode 100644 index 00000000..9e409247 --- /dev/null +++ b/home/.config/home-manager/packages.nix @@ -0,0 +1,82 @@ +{ pkgs, ... }: + +{ + home.packages = [ + pkgs.dprint + pkgs.gitleaks + pkgs.shellcheck + pkgs.shfmt + pkgs.git + pkgs.coreutils + pkgs.tig + pkgs.tree + pkgs.curl + pkgs.wget + pkgs.zsh + # Don't include bash - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730 + # pkgs.bash + pkgs.fish + pkgs.nushell + pkgs.starship + pkgs.jq + pkgs.gh + pkgs.direnv + pkgs.ripgrep + pkgs.fzf + pkgs.exa + pkgs.bat + pkgs.duf + pkgs.fd + pkgs.du-dust + pkgs.procs + pkgs.bottom + pkgs.tig + pkgs.zellij + pkgs.nixpkgs-fmt + pkgs.nil + pkgs.typos + pkgs.hyperfine + pkgs.zoxide + pkgs.difftastic + + # Required in many asdf(rtx) plugins + pkgs.unzip + + # Includes follows in each repository if needed, not in global + # pkgs.deno + # pkgs.rustup + # pkgs.go + # pkgs.crystal + # pkgs.elmPackages.elm + # pkgs.gcc + # pkgs.sqlite + # pkgs.postgresql + # pkgs.gnumake + # pkgs.cargo-make + + # This section is just a note for my strggle + # Often failed to build ruby even if I enabled following dependencies + # pkgs.zlib + # pkgs.libyaml + # pkgs.openssl + # + # Don't include nixpkgs ruby, because of installing into .nix-profile hides + # adhoc use of https://github.com/bobvanderlinden/nixpkgs-ruby + # pkgs.ruby + + # As a boardgamer + # pkgs.tesseract + # pkgs.imagemagick + # pkgs.pngquant + # pkgs.img2pdf + # pkgs.ocrmypdf + ] ++ ( + if pkgs.stdenv.hostPlatform.isDarwin then + [ ] + else + [ + # Fix missing locales as `locale: Cannot set LC_CTYPE to default locale` + pkgs.glibc + ] + ); +} diff --git a/home/.config/home-manager/zsh.nix b/home/.config/home-manager/zsh.nix new file mode 100644 index 00000000..2b317107 --- /dev/null +++ b/home/.config/home-manager/zsh.nix @@ -0,0 +1,85 @@ +{ config, ... }: + +{ + programs.starship.enableZshIntegration = true; + programs.direnv.enableZshIntegration = true; + programs.zoxide.enableZshIntegration = true; + programs.fzf.enableZshIntegration = true; + + # https://nixos.wiki/wiki/Zsh + # https://github.com/nix-community/home-manager/blob/master/modules/programs/zsh.nix + programs.zsh = { + enable = true; + + # How about to point `xdg.configFile`? + dotDir = ".config/zsh"; + + history = { + # in memory + size = 100000; + + # in file + save = 4200000; + path = "${config.xdg.stateHome}/zsh/history"; + + ignoreDups = true; + ignoreSpace = true; + + extended = true; + share = true; + }; + + historySubstringSearch = { + enable = true; + }; + enableSyntaxHighlighting = true; + enableAutosuggestions = true; + enableCompletion = true; + + # home-manager path will set in `programs.home-manager.enable = true`; + envExtra = '' + # https://wiki.archlinux.jp/index.php/XDG_Base_Directory + # https://www.reddit.com/r/zsh/comments/tpwx9t/zcompcache_vs_zcompdump/ + zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache" + + if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi # added by Nix installer + ''; + + initExtra = '' + typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='fg=blue,bold' + typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' + typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY='true' + + setopt correct + unsetopt BEEP + + setopt hist_ignore_all_dups + setopt hist_reduce_blanks + setopt hist_save_no_dups + setopt hist_no_store + + eval "$($XDG_DATA_HOME/rtx/bin/rtx activate -s zsh)" + + case ''${OSTYPE} in + darwin*) + test -e "''${HOME}/.iterm2_shell_integration.zsh" && source "''${HOME}/.iterm2_shell_integration.zsh" + ;; + esac + + # https://github.com/starship/starship/blob/0d98c4c0b7999f5a8bd6e7db68fd27b0696b3bef/docs/uk-UA/advanced-config/README.md#change-window-title + function set_win_title() { + echo -ne "\033]0; $(basename "$PWD") \007" + } + precmd_functions+=(set_win_title) + + zshaddhistory() { whence ''${''${(z)1}[1]} >| /dev/null || return 1 } + ''; + + # TODO: May move to sessionVariables + profileExtra = '' + if [[ "$OSTYPE" == darwin* ]]; then + export BROWSER='open' + fi + ''; + }; +}