feat: user profiles and gterminal profile

This commit is contained in:
Gustavo "Guz" L. de Mello
2024-04-05 18:01:36 -03:00
parent 1e857fb8f4
commit 810f3bce5b
9 changed files with 259 additions and 1 deletions

View File

@@ -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 = { };

View File

@@ -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;
};
};
}

View File

@@ -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;
};
};
}

View File

@@ -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 { };
}

View File

@@ -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;
};
}

View File

@@ -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 { };
}

View File

@@ -0,0 +1,12 @@
{ config, lib, pkgs, ... }:
let
cfg = config.profiles;
in
{
imports = [
./gterminal.nix
];
options.profiles = { };
config = { };
}

View File

@@ -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";
'';
};
};
}

View File

@@ -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