diff --git a/flake.nix b/flake.nix index beb0981..f1f3d63 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,11 @@ # Specify your home configuration modules here, for example, # the path to your home.nix. - modules = [ ./home-manager/home.nix ]; + modules = [ + ./home-manager/home.nix + ./home-manager/modules/shell/zsh/default.nix + ./home-manager/modules/shell/direnv.nix + ]; # Optionally use extraSpecialArgs # to pass through arguments to home.nix diff --git a/home-manager/home.nix b/home-manager/home.nix index 9fdbb49..42c3b72 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -7,6 +7,13 @@ # DO NOT CHANGE!!! home.stateVersion = "23.11"; + modules = { + shell = { + zsh.enable = true; + direnv.enable = true; + }; + }; + home.packages = with pkgs; [ # Code formatters for use with doom emacs nixfmt # nix @@ -24,9 +31,6 @@ # Further tools lazygit - # TODO: migrate to module config - starship - # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) # (pkgs.writeShellScriptBin "my-hello" '' @@ -34,75 +38,7 @@ # '') ]; - home.shellAliases = { - g = "git status"; - fd = "fd -HI"; - }; - programs = { - direnv = { - enable = true; - enableZshIntegration = true; - }; - - starship = { - enable = true; - enableZshIntegration = true; - }; - - zsh = { - enable = true; - - initExtra = '' - function go_dir_up() { - cd .. || return 1 - } - - function zle_go_dir_up() { - zle .kill-buffer - go_dir_up - zle .accept-line - } - - fzf-z() { - dir=$(z | fzf --tiebreak=index --tac | sed -E 's/^[0-9]+[[:space:]]+//') - cd $dir - } - - mkcd () - { - mkdir -p -- "$1" && cd -P -- "$1" - } - - zle -N zle_go_dir_up - bindkey "^[[1;3A" zle_go_dir_up - bindkey "^[[A" history-substring-search-up - bindkey "^[[B" history-substring-search-down - - bindkey "^[[1;5C" forward-word - bindkey "^[[1;5D" backward-word - ''; - - zplug = { - enable = true; - plugins = [ - # list of plugins: https://github.com/unixorn/awesome-zsh-plugins - { name = "agkozak/zsh-z"; } - { name = "mdumitru/last-working-dir"; } - { - name = "zsh-users/zsh-completions"; - } - - # make it behave like fish - { name = "zsh-users/zsh-autosuggestions"; } - { name = "zsh-users/zsh-history-substring-search"; } - { - name = "zsh-users/zsh-syntax-highlighting"; - } # must be last sourced plugin - ]; - }; - }; - neovim = let toLua = str: '' lua << EOF @@ -169,7 +105,6 @@ source = ../alacritty; recursive = true; }; - ".config/starship.toml".source = ../starship/starship.toml; }; # Home Manager can also manage your environment variables through @@ -180,6 +115,16 @@ # or # /etc/profiles/per-user/julian/etc/profile.d/hm-session-vars.sh # + # + + home.shellAliases = { + g = "git status"; + fd = "fd -HI"; + ls = "ls --color"; + la = "ls -Alh --color"; + grep = "grep --color"; + }; + home.sessionVariables = { TERMINAL = "alacritty"; EDITOR = "nvim"; diff --git a/home-manager/modules/shell/direnv.nix b/home-manager/modules/shell/direnv.nix new file mode 100644 index 0000000..77a5eb5 --- /dev/null +++ b/home-manager/modules/shell/direnv.nix @@ -0,0 +1,15 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.modules.shell.direnv; +in { + options.modules.shell.direnv = { enable = mkOption { default = false; }; }; + + config = mkIf cfg.enable { + programs.direnv = { + enable = true; + enableZshIntegration = true; + }; + }; +} diff --git a/home-manager/modules/shell/zsh/default.nix b/home-manager/modules/shell/zsh/default.nix new file mode 100644 index 0000000..0deb795 --- /dev/null +++ b/home-manager/modules/shell/zsh/default.nix @@ -0,0 +1,75 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.modules.shell.zsh; +in { + options.modules.shell.zsh = { enable = mkOption { default = false; }; }; + + config = mkIf cfg.enable { + + home.file = { + ".config/starship.toml".source = ../../../../starship/starship.toml; + }; + + home.packages = with pkgs; [ starship ]; + + programs.starship = { + enable = true; + enableZshIntegration = true; + }; + + programs.zsh = { + enable = true; + + initExtra = '' + function go_dir_up() { + cd .. || return 1 + } + + function zle_go_dir_up() { + zle .kill-buffer + go_dir_up + zle .accept-line + } + + fzf-z() { + dir=$(z | fzf --tiebreak=index --tac | sed -E 's/^[0-9]+[[:space:]]+//') + cd $dir + } + + mkcd () + { + mkdir -p -- "$1" && cd -P -- "$1" + } + + zle -N zle_go_dir_up + bindkey "^[[1;3A" zle_go_dir_up + bindkey "^[[A" history-substring-search-up + bindkey "^[[B" history-substring-search-down + + bindkey "^[[1;5C" forward-word + bindkey "^[[1;5D" backward-word + ''; + + zplug = { + enable = true; + plugins = [ + # list of plugins: https://github.com/unixorn/awesome-zsh-plugins + { name = "agkozak/zsh-z"; } + { name = "mdumitru/last-working-dir"; } + { + name = "zsh-users/zsh-completions"; + } + + # make it behave like fish + { name = "zsh-users/zsh-autosuggestions"; } + { name = "zsh-users/zsh-history-substring-search"; } + { + name = "zsh-users/zsh-syntax-highlighting"; + } # must be last sourced plugin + ]; + }; + }; + }; +} diff --git a/home-manager/templates/module.default.nix b/home-manager/templates/module.default.nix new file mode 100644 index 0000000..3e68bb2 --- /dev/null +++ b/home-manager/templates/module.default.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let cfg = config.modules.X; +in { + options.modules.X = { enable = mkOption { default = false; }; }; + + config = mkIf cfg.enable { }; +}