diff --git a/modules/nih/programs/default.nix b/modules/nih/programs/default.nix index 78f8d50..29723ba 100644 --- a/modules/nih/programs/default.nix +++ b/modules/nih/programs/default.nix @@ -1,12 +1,17 @@ { config, lib, pkgs, ... }: let - cfg = config.nih.programs; + cfg = config.programs; in { imports = [ + ./direnv.nix ./hyprland.nix ./lf.nix + ./starship.nix + ./tmux.nix + ./wezterm.nix + ./zsh.nix ]; options.programs = { }; config = { }; diff --git a/modules/nih/programs/direnv.nix b/modules/nih/programs/direnv.nix new file mode 100644 index 0000000..c4ea1fa --- /dev/null +++ b/modules/nih/programs/direnv.nix @@ -0,0 +1,19 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.direnv; +in +{ + imports = [ ]; + options.programs.direnv = with lib; with lib.types; { }; + config = with lib; mkIf cfg.enable { + programs.direnv = { + enableBashIntegration = mkDefault config.programs.bash.enable; + enableFishIntegration = mkDefault config.programs.fish.enable; + enableNushellIntegration = mkDefault config.programs.nushell.enable; + enableZshIntegration = mkDefault config.programs.zsh.enable; + + nix-direnv.enable = true; + }; + }; +} diff --git a/modules/nih/programs/starship.nix b/modules/nih/programs/starship.nix new file mode 100644 index 0000000..3022261 --- /dev/null +++ b/modules/nih/programs/starship.nix @@ -0,0 +1,17 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.starship; +in +{ + imports = [ ]; + options.programs.starship = with lib; with lib.types; { }; + config = with lib; mkIf cfg.enable { + programs.starship = { + enableFishIntegration = mkDefault config.programs.fish.enable; + enableIonIntegration = mkDefault config.programs.ion.enable; + enableNushellIntegration = mkDefault config.programs.nushell.enable; + enableZshIntegration = mkDefault config.programs.zsh.enable; + }; + }; +} diff --git a/modules/nih/programs/tmux.nix b/modules/nih/programs/tmux.nix new file mode 100644 index 0000000..d98128a --- /dev/null +++ b/modules/nih/programs/tmux.nix @@ -0,0 +1,11 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.tmux; +in +{ + imports = [ ]; + options.programs.tmux = with lib; with lib.types; { }; + config = with lib; mkIf cfg.enable { }; +} + diff --git a/modules/nih/programs/wezterm.nix b/modules/nih/programs/wezterm.nix new file mode 100644 index 0000000..585111e --- /dev/null +++ b/modules/nih/programs/wezterm.nix @@ -0,0 +1,76 @@ +{ config, lib, pkgs, ... }: + +with builtins; +let + cfg = config.programs.wezterm; + jsonFormat = pkgs.formats.json { }; + toLua = with lib.strings; v: + if isList v then + "{ ${concatMapStringsSep ", " (i: toLua i) v} }" + else if isAttrs v then + "\{ ${concatStringsSep ", " (attrValues (mapAttrs (n: a: "${n} = ${toLua a}") v))} \}" + else if isNull v then + "nil" + else if isBool v then + if v then "true" else "false" + else if isInt v then + toString v + else if isString v && hasPrefix "lua " v then + "${substring 4 (stringLength v) v}" + else + "\"${toString v}\""; + configInLua = + pkgs.writeText "nih-wezterm-generated-config" '' + local wezterm = require("wezterm"); + + local nih_generated_config = {}; + ${concatStringsSep "\n" (attrValues (mapAttrs + (n: v: "nih_generated_config.${n} = ${toLua v};") + cfg.config))} + + local function extra_config() + ${cfg.extraConfig} + end + + for k,v in pairs(extra_config()) do nih_generated_config[k] = v end + + return nih_generated_config; + ''; + prettyConfig = pkgs.runCommand "nih-wezterm-pretty-config" { config = configInLua; } '' + echo "Nih's Wezterm configuration file builder"; + echo "input file: $config"; + echo "output file: $out"; + echo "" + echo "Formatting config file with Stylua" + cat $config | ${pkgs.stylua}/bin/stylua - > $out + echo "" + echo "Checking erros with luacheck" + ${pkgs.luajitPackages.luacheck}/bin/luacheck \ + --no-max-line-length \ + --no-unused \ + "$out"; + ''; +in +{ + imports = [ ]; + options.programs.wezterm = with lib; with lib.types; { + config = mkOption { + type = submodule ({ ... }: { + freeformType = jsonFormat.type; + }); + default = { }; + }; + }; + config = with lib; mkIf cfg.enable { + programs.wezterm = { + enableBashIntegration = mkDefault config.programs.bash.enable; + enableZshIntegration = mkDefault config.programs.zsh.enable; + }; + + xdg.configFile."wezterm/wezterm.lua".source = prettyConfig; + }; +} + + + + diff --git a/modules/nih/programs/zsh.nix b/modules/nih/programs/zsh.nix new file mode 100644 index 0000000..a412a14 --- /dev/null +++ b/modules/nih/programs/zsh.nix @@ -0,0 +1,10 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.zsh; +in +{ + imports = [ ]; + options.programs.zsh = with lib; with lib.types; { }; + config = with lib; mkIf cfg.enable { }; +} diff --git a/modules/nih/user-profiles/default.nix b/modules/nih/user-profiles/default.nix new file mode 100644 index 0000000..d0cfcab --- /dev/null +++ b/modules/nih/user-profiles/default.nix @@ -0,0 +1,12 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.profiles; +in +{ + imports = [ + ./gterminal.nix + ]; + options.profiles = { }; + config = { }; +} diff --git a/modules/nih/user-profiles/gterminal.nix b/modules/nih/user-profiles/gterminal.nix new file mode 100644 index 0000000..f0f84ea --- /dev/null +++ b/modules/nih/user-profiles/gterminal.nix @@ -0,0 +1,104 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.profiles.gterminal; +in +{ + imports = [ ]; + options.profiles.gterminal = with lib; with lib.types; { + enable = mkEnableOption ""; + }; + config = with lib; mkIf cfg.enable { + programs = { + direnv.enable = true; + + lf.enable = true; + + starship.enable = true; + + tmux.baseIndex = 1; + tmux.enable = true; + tmux.extraConfig = '' + 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}" + ''; + tmux.keyMode = "vi"; + tmux.mouse = true; + tmux.prefix = "C-Space"; + tmux.plugins = with pkgs; [ + { + plugin = (tmuxPlugins.catppuccin.overrideAttrs (_: { + src = fetchFromGitHub { + owner = "guz013"; + repo = "frappuccino-tmux"; + rev = "4255b0a769cc6f35e12595fe5a33273a247630aa"; + sha256 = "0k8yprhx5cd8v1ddpcr0dkssspc17lq2a51qniwafkkzxi3kz3i5"; + }; + })); + extraConfig = '' + 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}" + ''; + } + { plugin = tmuxPlugins.better-mouse-mode; extraConfig = "set-option -g mouse on"; } + { + plugin = (tmuxPlugins.mkTmuxPlugin { + pluginName = "tmux.nvim"; + version = "unstable-2024-04-05"; + src = fetchFromGitHub { + owner = "aserowy"; + repo = "tmux.nvim"; + rev = "63e9c5e054099dd30af306bd8ceaa2f1086e1b07"; + sha256 = "0ynzljwq6hv7415p7pr0aqx8kycp84p3p3dy4jcx61dxfgdpgc4c"; + }; + }); + extraConfig = ''''; + } + ]; + + tmux.shell = "${pkgs.zsh}/bin/zsh"; + tmux.terminal = "screen-256color"; + + wezterm = mkIf (config._nih.type != "server") { + enable = true; + config = { + default_prog = [ "zsh" "--login" ]; + enable_wayland = false; + enable_tab_bar = false; + font = "lua wezterm.font(\"Fira Code\")"; + font_size = 10; + }; + }; + + zsh.enable = true; + zsh.enableAutosuggestions = true; + zsh.enableCompletion = true; + zsh.initExtra = '' + export GPG_TTY=$(tty) + + alias tmux="tmux -f ${config.xdg.configHome}/tmux/tmux.conf"; + ''; + }; + }; +} diff --git a/modules/nih/users.nix b/modules/nih/users.nix index cbab0a2..e0aebd9 100644 --- a/modules/nih/users.nix +++ b/modules/nih/users.nix @@ -105,6 +105,7 @@ in inputs.nix-index-database.hmModules.nix-index inputs.flatpaks.homeManagerModules.nix-flatpak ./programs + ./user-profiles ]; options = with lib; with lib.types; { _nih = mkOption { @@ -117,6 +118,9 @@ in _nih = { type = config.nih.type; }; + + profiles = mkMerge [ value.profiles ]; + programs = mkMerge [ { home-manager.enable = true; } value.programs