From f31a38af3c563cb3c26621b7392e523b3eaa4f07 Mon Sep 17 00:00:00 2001 From: chn Date: Wed, 21 May 2025 18:03:29 +0800 Subject: [PATCH] modules.packages.bash: init --- modules/packages/bash.nix | 17 ++++ modules/packages/zsh/default.nix | 147 ++++++++++++++++--------------- 2 files changed, 91 insertions(+), 73 deletions(-) create mode 100644 modules/packages/bash.nix diff --git a/modules/packages/bash.nix b/modules/packages/bash.nix new file mode 100644 index 00000000..550e9f97 --- /dev/null +++ b/modules/packages/bash.nix @@ -0,0 +1,17 @@ +inputs: +{ + options.nixos.packages.bash = let inherit (inputs.lib) mkOption types; in mkOption + { type = types.nullOr (types.submodule {}); default = {}; }; + config = let inherit (inputs.config.nixos.packages) bash; in inputs.lib.mkIf (bash != null) + { + nixos.user.sharedModules = [(homeInputs: + { + config = + { + # set bash history file path, avoid overwriting zsh history + programs.bash = { enable = true; historyFile = "${homeInputs.config.xdg.dataHome}/bash/bash_history"; }; + home.shell.enableBashIntegration = true; + }; + })]; + }; +} diff --git a/modules/packages/zsh/default.nix b/modules/packages/zsh/default.nix index 7dbd8dc3..bde6cf53 100644 --- a/modules/packages/zsh/default.nix +++ b/modules/packages/zsh/default.nix @@ -4,85 +4,86 @@ inputs: { type = types.nullOr (types.submodule {}); default = {}; }; config = let inherit (inputs.config.nixos.packages) zsh; in inputs.lib.mkIf (zsh != null) { - nixos.user.sharedModules = [(home-inputs: { config.programs = inputs.lib.mkMerge - [ - # general config - { - zsh = + nixos.user.sharedModules = [(home-inputs: + { + config = inputs.lib.mkMerge + [ { - enable = true; - history = - { - path = "${home-inputs.config.xdg.dataHome}/zsh/zsh_history"; - extended = true; - save = 100000000; - size = 100000000; - }; - syntaxHighlighting.enable = true; - autosuggestion.enable = true; - enableCompletion = true; - oh-my-zsh = + programs.zsh = { enable = true; - plugins = [ "git" "colored-man-pages" "extract" "history-substring-search" "autojump" ]; - theme = inputs.lib.mkDefault "clean"; + history = + { + path = "${home-inputs.config.xdg.dataHome}/zsh/zsh_history"; + extended = true; + save = 100000000; + size = 100000000; + }; + syntaxHighlighting.enable = true; + autosuggestion.enable = true; + enableCompletion = true; + oh-my-zsh = + { + enable = true; + plugins = [ "git" "colored-man-pages" "extract" "history-substring-search" "autojump" ]; + theme = inputs.lib.mkDefault "clean"; + }; + # ensure ~/.zlogin exists + loginExtra = " "; }; - # ensure ~/.zlogin exists - loginExtra = " "; - }; - # set bash history file path, avoid overwriting zsh history - bash = { enable = true; historyFile = "${home-inputs.config.xdg.dataHome}/bash/bash_history"; }; - } - # config for root and chn - { - zsh = inputs.lib.mkIf (builtins.elem home-inputs.config.home.username [ "chn" "root" "aleksana" "alikia" ]) + home.shell.enableZshIntegration = true; + } { - plugins = - [ + programs.zsh = inputs.lib.mkIf + (builtins.elem home-inputs.config.home.username [ "chn" "root" "aleksana" "alikia" ]) { - file = "powerlevel10k.zsh-theme"; - name = "powerlevel10k"; - src = "${inputs.pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k"; - } - { file = "p10k.zsh"; name = "powerlevel10k-config"; src = ./p10k-config; } - { - name = "zsh-lsd"; - src = inputs.pkgs.fetchFromGitHub - { - owner = "z-shell"; - repo = "zsh-lsd"; - rev = "65bb5ac49190beda263aae552a9369127961632d"; - hash = "sha256-JSNsfpgiqWhtmGQkC3B0R1Y1QnDKp9n0Zaqzjhwt7Xk="; - }; - } - ]; - initContent = inputs.lib.mkOrder 550 - '' - # p10k instant prompt - P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh" - [[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT" - HYPHEN_INSENSITIVE="true" - export PATH=~/bin:$PATH - function br - { - local cmd cmd_file code - cmd_file=$(mktemp) - if broot --outcmd "$cmd_file" "$@"; then - cmd=$(<"$cmd_file") - command rm -f "$cmd_file" - eval "$cmd" - else - code=$? - command rm -f "$cmd_file" - return "$code" - fi - } - alias todo="todo.sh" - ''; - oh-my-zsh.theme = ""; - }; - } - ];})]; + plugins = + [ + { + file = "powerlevel10k.zsh-theme"; + name = "powerlevel10k"; + src = "${inputs.pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k"; + } + { file = "p10k.zsh"; name = "powerlevel10k-config"; src = ./p10k-config; } + { + name = "zsh-lsd"; + src = inputs.pkgs.fetchFromGitHub + { + owner = "z-shell"; + repo = "zsh-lsd"; + rev = "65bb5ac49190beda263aae552a9369127961632d"; + hash = "sha256-JSNsfpgiqWhtmGQkC3B0R1Y1QnDKp9n0Zaqzjhwt7Xk="; + }; + } + ]; + initContent = inputs.lib.mkOrder 550 + '' + # p10k instant prompt + P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh" + [[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT" + HYPHEN_INSENSITIVE="true" + export PATH=~/bin:$PATH + function br + { + local cmd cmd_file code + cmd_file=$(mktemp) + if broot --outcmd "$cmd_file" "$@"; then + cmd=$(<"$cmd_file") + command rm -f "$cmd_file" + eval "$cmd" + else + code=$? + command rm -f "$cmd_file" + return "$code" + fi + } + alias todo="todo.sh" + ''; + oh-my-zsh.theme = ""; + }; + } + ]; + })]; environment.pathsToLink = [ "/share/zsh" ]; programs.zsh.enable = true; };