From 1d7c7146f63441ba1a3342b61ce003c416326b20 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Fri, 5 Jan 2024 19:49:55 -0300 Subject: [PATCH] feat: terminal and shell configuration --- flake.lock | 17 +++++ flake.nix | 5 ++ hosts/default/configuration.nix | 3 + hosts/default/home.nix | 1 + modules/home-manager/config/terminal.nix | 29 ++++++++ modules/home-manager/programs/starship.nix | 18 +++++ modules/home-manager/programs/tmux.nix | 79 ++++++++++++++++++++++ modules/home-manager/programs/wezterm.nix | 70 +++++++++++++++++++ modules/home-manager/programs/zsh.nix | 27 ++++++++ 9 files changed, 249 insertions(+) create mode 100644 modules/home-manager/config/terminal.nix create mode 100644 modules/home-manager/programs/starship.nix create mode 100644 modules/home-manager/programs/tmux.nix create mode 100644 modules/home-manager/programs/wezterm.nix create mode 100644 modules/home-manager/programs/zsh.nix diff --git a/flake.lock b/flake.lock index 7f12618..1e2cea0 100644 --- a/flake.lock +++ b/flake.lock @@ -128,6 +128,7 @@ "home-manager": "home-manager", "nix-colors": "nix-colors", "nixpkgs": "nixpkgs_2", + "tmux-plugin-manager": "tmux-plugin-manager" } }, "systems": { @@ -145,6 +146,22 @@ "type": "github" } }, + "tmux-plugin-manager": { + "flake": false, + "locked": { + "lastModified": 1677502767, + "narHash": "sha256-hW8mfwB8F9ZkTQ72WQp/1fy8KL1IIYMZBtZYIwZdMQc=", + "owner": "tmux-plugins", + "repo": "tpm", + "rev": "99469c4a9b1ccf77fade25842dc7bafbc8ce9946", + "type": "github" + }, + "original": { + "owner": "tmux-plugins", + "repo": "tpm", + "type": "github" + } + }, "utils": { "inputs": { "systems": "systems" diff --git a/flake.nix b/flake.nix index d252af2..8475dac 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,11 @@ # Used for theming the OS, see modules/home-manager/theme.nix nix-colors.url = "github:misterio77/nix-colors"; + # Necessary for modules/home-manager/programs/tmux.nix + tmux-plugin-manager = { + url = "github:tmux-plugins/tpm"; + flake = false; + }; }; outputs = { self, nixpkgs, home-manager, ... }@inputs: diff --git a/hosts/default/configuration.nix b/hosts/default/configuration.nix index 4fd9cbd..e43d974 100644 --- a/hosts/default/configuration.nix +++ b/hosts/default/configuration.nix @@ -85,6 +85,7 @@ # Enable touchpad support (enabled default in most desktopManager). # services.xserver.libinput.enable = true; + programs.zsh.enable = true; # Define a user account. Don't forget to set a password with ‘passwd’. users.users."guz" = { isNormalUser = true; @@ -94,6 +95,7 @@ firefox # thunderbird ]; + shell = pkgs.zsh; }; home-manager = { @@ -118,6 +120,7 @@ environment.sessionVariables = { EDITOR = "nvim"; }; + environment.pathsToLink = [ "/share/zsh" ]; # Some programs need SUID wrappers, can be configured further or are # started in user sessions. diff --git a/hosts/default/home.nix b/hosts/default/home.nix index 10e26ce..0205ebf 100644 --- a/hosts/default/home.nix +++ b/hosts/default/home.nix @@ -4,6 +4,7 @@ imports = [ inputs.flatpaks.homeManagerModules.default ../../modules/home-manager/theme.nix + ../../modules/home-manager/config/terminal.nix ]; # theme.accent = "f38ba8"; diff --git a/modules/home-manager/config/terminal.nix b/modules/home-manager/config/terminal.nix new file mode 100644 index 0000000..99ebc82 --- /dev/null +++ b/modules/home-manager/config/terminal.nix @@ -0,0 +1,29 @@ +{ config, inputs, pkgs, ... }: + +{ + imports = [ + ../programs/starship.nix + ../programs/tmux.nix + ../programs/wezterm.nix + ../programs/zsh.nix + ]; + options = {}; + config = { + starship.enable = true; + starship.enableZsh = true; + + tmux.enable = true; + tmux.shell = "\${pkgs.zsh}/bin/zsh"; + + wezterm.enable = true; + wezterm.integration.zsh = true; + wezterm.defaultProg = [ + "zsh" + "--login" + "-c" + "tmux" + ]; + + zsh.enable = true; + }; +} diff --git a/modules/home-manager/programs/starship.nix b/modules/home-manager/programs/starship.nix new file mode 100644 index 0000000..a594c8e --- /dev/null +++ b/modules/home-manager/programs/starship.nix @@ -0,0 +1,18 @@ +{ inputs, config, lib, pkgs, ...}: + +let + cfg = config.starship; +in +{ + options.starship = { + enable = lib.mkEnableOption "Enable module"; + enableZsh = lib.mkEnableOption "Enable Zsh Integration"; + enableBash = lib.mkEnableOption "Enable Bash Integration"; + }; + config = lib.mkIf cfg.enable { + programs.starship.enable = true; + + programs.starship.enableZshIntegration = lib.mkIf cfg.enableZsh true; + programs.starship.enableBashIntegration = lib.mkIf cfg.enableBash true; + }; +} diff --git a/modules/home-manager/programs/tmux.nix b/modules/home-manager/programs/tmux.nix new file mode 100644 index 0000000..16fd02a --- /dev/null +++ b/modules/home-manager/programs/tmux.nix @@ -0,0 +1,79 @@ +{ inputs, config, pkgs, lib, ... }: + +let + cfg = config.tmux; +in +{ + options.tmux = { + enable = lib.mkEnableOption "Enable Tmux module"; + baseIndex = lib.mkOption { + type = lib.types.ints.unsigned; + default = 1; + }; + prefix = lib.mkOption { + type = lib.types.str; + default = "C-Space"; + }; + shell = lib.mkOption { + type = lib.types.str; + default = "\${pkgs.bash}/bin/bash"; + }; + }; + config = lib.mkIf cfg.enable { + programs.tmux.enable = true; + + programs.tmux.baseIndex = cfg.baseIndex; + + programs.tmux.keyMode = "vi"; + + programs.tmux.mouse = true; + + programs.tmux.terminal = "screen-256color"; + + programs.tmux.prefix = cfg.prefix; + + # TODO: package tmux plugins so tpm is not necessary + home.file."${config.xdg.configHome}/tmux/plugins/tpm" = { + source = inputs.tmux-plugin-manager; + }; + + home.packages = with pkgs; [ + entr # b0o/tmux-autoreload depends on it + ]; + + programs.tmux.extraConfig = '' + set -g @plugin 'b0o/tmux-autoreload' + set -g @plugin 'aserowy/tmux.nvim' + set -g @plugin 'guz013/frappuccino-tmux' + + set -sg terminal-overrides ",*:RGB" + + set -g renumber-windows on + + bind -T prefix / split-window -v -c "#''''{pane_current_path}" + bind -T prefix \\ split-window -h -c "#''''{pane_current_path}" + + set -g @catppuccin_window_left_separator "" + set -g @catppuccin_window_right_separator " " + set -g @catppuccin_window_middle_separator " █" + set -g @catppuccin_window_number_position "right" + + set -g @catppuccin_window_default_fill "number" + set -g @catppuccin_window_default_text "#W" + + set -g @catppuccin_window_current_fill "number" + set -g @catppuccin_window_current_text "#W" + + set -g @catppuccin_status_modules_right "application directory session" + set -g @catppuccin_status_left_separator " " + set -g @catppuccin_status_right_separator "" + set -g @catppuccin_status_right_separator_inverse "no" + set -g @catppuccin_status_fill "icon" + set -g @catppuccin_status_connect_separator "no" + + set -g @catppuccin_directory_text "#{pane_current_path}" + + run '${config.xdg.configHome}/tmux/plugins/tpm/tpm' + ''; + }; +} diff --git a/modules/home-manager/programs/wezterm.nix b/modules/home-manager/programs/wezterm.nix new file mode 100644 index 0000000..1af12c5 --- /dev/null +++ b/modules/home-manager/programs/wezterm.nix @@ -0,0 +1,70 @@ +{ inputs, pkgs, lib, config, ... }: + +let + cfg = config.wezterm; +in +{ + options.wezterm = { + enable = lib.mkEnableOption "Enable Wezterm"; + integration = { + zsh = lib.mkEnableOption "Enable Zsh Integration"; + }; + colorScheme = lib.mkOption { + type = lib.types.str; + default = "system"; + }; + defaultProg = lib.mkOption { + default = []; + }; + }; + config = lib.mkIf cfg.enable { + programs.wezterm.enable = true; + programs.wezterm.enableZshIntegration = lib.mkIf (cfg.integration.zsh) true; + + programs.wezterm.extraConfig = '' + return { + enable_tab_bar = false; + color_scheme = "${cfg.colorScheme}", + default_prog = { ${lib.concatMapStrings (x: "'" + x + "',") cfg.defaultProg} }, + } + ''; + + programs.wezterm.colorSchemes = { + system = with config.colorScheme.colors; { + foreground = "#${base05}"; + background = "#${base00}"; + + cursor_fg = "#${base01}"; + cursor_bg = "#${config.theme.accent}"; + cursor_border = "#${config.theme.accent}"; + + selection_fg = "#${base04}"; + selection_bg = "#${config.theme.accent}"; + + split = "#${base04}"; + + ansi = [ + "#${base03}" + "#${base08}" + "#${base0B}" + "#${base0A}" + "#${base0D}" + "#${base0E}" + "#${base0C}" + "#${base03}" + ]; + + brights = [ + "#${base03}" + "#${base08}" + "#${base0B}" + "#${base0A}" + "#${base0D}" + "#${base0E}" + "#${base0C}" + "#${base03}" + ]; + }; + }; + }; +} diff --git a/modules/home-manager/programs/zsh.nix b/modules/home-manager/programs/zsh.nix new file mode 100644 index 0000000..f6381ef --- /dev/null +++ b/modules/home-manager/programs/zsh.nix @@ -0,0 +1,27 @@ +{ inputs, config, pkgs, lib, ... }: + +let + cfg = config.zsh; +in +{ + options.zsh = { + enable = lib.mkEnableOption "Enable Zsh shell"; + plugins = { + suggestions.enable = lib.mkOption { + type = lib.types.bool; + default = true; + }; + completion.enable = lib.mkOption { + type = lib.types.bool; + default = true; + }; + }; + }; + config = lib.mkIf cfg.enable { + programs.zsh.enable = true; + programs.zsh.oh-my-zsh.enable = true; + + programs.zsh.enableAutosuggestions = lib.mkIf (cfg.plugins.suggestions.enable) true; + programs.zsh.enableCompletion = lib.mkIf (cfg.plugins.completion.enable) true; + }; +}