Working on modularizing stuff, again

This commit is contained in:
Chris Kruining 2024-07-21 14:03:57 +02:00
parent b698ce3485
commit 9ba5f8fdf0
32 changed files with 1481 additions and 88 deletions

48
modules/shell/default.nix Normal file
View file

@ -0,0 +1,48 @@
{ options, config, lib, pkgs, ... }:
let
inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf mkMerge;
cfg = config.modules.shell;
in
{
options.modules.shell = let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) nullOr enum;
in {
default = mkOption {
type = nullOr (enum ["fish" "zsh" "xonsh"]);
default = null;
description = "Default system shell";
};
corePkgs.enable = mkEnableOption "core shell packages";
};
config = mkMerge [
(mkIf (cfg.default != null) {
users.defaultUserShell = pkgs."${cfg.default}";
})
(mkIf cfg.corePkgs.enable {
modules.shell.toolset = {
btop.enable = true;
fzf.enable = true;
starship.enable = true;
tmux.enable = true;
};
hm.programs.direnv = {
enable = true;
nix-direnv.enable = true;
config.whitelist.prefix = ["/home"];
};
user.packages = attrValues {
inherit (pkgs) any-nix-shell pwgen yt-dlp ripdrag yazi;
inherit (pkgs) bat fd zoxide;
rgFull = pkgs.ripgrep.override {withPCRE2 = true;};
};
})
];
}

View file

@ -0,0 +1,146 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
inherit (lib.strings) concatStringsSep;
in
{
options.modules.shell.toolset.btop = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "system-monitor"; };
config = mkIf config.modules.shell.toolset.btop.enable {
hm.programs.btop = let
inherit (config.modules.themes) active;
in
{
enable = true;
settings = {
force_tty = false;
vim_keys = true; # Directional keys: "h,j,k,l,g,G"
update_ms = 1500; # ms (s^{-3})
temp_scale = "celsius";
base_10_sizes = false;
show_cpu_freq = true;
clock_format = "%H:%M";
background_update = true;
disks_filter = "exclude=/boot";
color_theme = "${active}";
rounded_corners = true;
theme_background = false;
truecolor = true;
presets = concatStringsSep "," [
"cpu:1:default"
"proc:0:default cpu:0:default"
"mem:0:default"
"net:0:default cpu:0:block"
"net:0:tty"
];
graph_symbol = "braille";
graph_symbol_cpu = "default";
graph_symbol_mem = "default";
graph_symbol_net = "default";
graph_symbol_proc = "default";
shown_boxes = "proc cpu mem net";
proc_sorting = "cpu lazy";
proc_reversed = false;
proc_tree = false;
proc_colors = true;
proc_gradient = true;
proc_per_core = true;
proc_mem_bytes = true;
proc_info_smaps = false;
proc_left = false;
cpu_graph_upper = "total";
cpu_graph_lower = "total";
cpu_single_graph = false;
cpu_bottom = false;
show_uptime = true;
check_temp = true;
cpu_sensor = "Auto";
show_coretemp = true;
cpu_core_map = "";
custom_cpu_name = "";
mem_graphs = true;
mem_below_net = false;
show_swap = true;
swap_disk = true;
show_disks = true;
only_physical = true;
use_fstab = false; # Enable -> disables `only_physical`
disk_free_priv = false;
show_io_stat = true;
io_mode = false;
io_graph_combined = false;
io_graph_speeds = "";
net_download = 100;
net_upload = 100;
net_auto = true;
net_sync = false;
net_iface = "br0";
show_battery = true;
selected_battery = "Auto";
log_level = "DEBUG";
};
};
home.configFile.btop-theme = let
inherit (config.modules.themes) active;
in
mkIf (active != null) {
target = "btop/themes/${active}.theme";
text = let
inherit (config.modules.themes.colors.main) bright types;
in ''
theme[main_bg]="${types.bg}"
theme[main_fg]="${types.fg}"
theme[title]="${types.fg}"
theme[hi_fg]="${types.highlight}"
theme[selected_bg]="${types.border}"
theme[selected_fg]="${types.bg}"
theme[inactive_fg]="${bright.black}"
theme[graph_text]="${bright.yellow}"
theme[meter_bg]="${bright.black}"
theme[proc_misc]="${bright.yellow}"
theme[cpu_box]="${bright.cyan}"
theme[mem_box]="${bright.green}"
theme[net_box]="${bright.magenta}"
theme[proc_box]="${bright.yellow}"
theme[div_line]="${bright.black}"
theme[temp_start]="${bright.yellow}"
theme[temp_mid]="${types.panelbg}"
theme[temp_end]="${bright.red}"
theme[cpu_start]="${bright.cyan}"
theme[cpu_mid]="${types.border}"
theme[cpu_end]="${bright.green}"
theme[free_start]="${bright.green}"
theme[free_mid]="${bright.green}"
theme[free_end]="${bright.green}"
theme[cached_start]="${bright.yellow}"
theme[cached_mid]="${bright.yellow}"
theme[cached_end]="${bright.magenta}"
theme[available_start]="${bright.yellow}"
theme[available_mid]="${bright.yellow}"
theme[available_end]="${bright.yellow}"
theme[used_start]="${types.panelbg}"
theme[used_mid]="${types.panelbg}"
theme[used_end]="${bright.red}"
theme[download_start]="${bright.blue}"
theme[download_mid]="${bright.blue}"
theme[download_end]="${bright.magenta}"
theme[upload_start]="${bright.blue}"
theme[upload_mid]="${bright.blue}"
theme[upload_end]="${bright.magenta}"
theme[process_start]="${bright.cyan}"
theme[process_mid]="${types.border}"
theme[process_end]="${bright.green}"
'';
};
};
}

View file

@ -0,0 +1,53 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.attrsets) optionalAttrs;
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.fzf = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "TUI Fuzzy Finder."; };
config = mkIf config.modules.shell.toolset.fzf.enable {
hm.programs.fzf = let
defShell = config.modules.shell.default;
in {
enable = true;
enableBashIntegration = true;
enableZshIntegration = defShell == "zsh";
enableFishIntegration = defShell == "fish";
tmux.enableShellIntegration = true;
tmux.shellIntegrationOptions = ["-d 40%"];
defaultCommand = "fd --type f";
defaultOptions = ["--height 40%" "--border"];
changeDirWidgetCommand = "fd --type d";
changeDirWidgetOptions = ["--preview 'tree -C {} | head -200'"];
fileWidgetCommand = "fd --type f";
fileWidgetOptions = ["--preview 'head {}'"];
historyWidgetOptions = ["--sort" "--exact"];
colors = let
inherit (config.modules.themes) active;
inherit (config.modules.themes.colors.main) normal types;
in
mkIf (active != null) {
bg = "${types.bg}";
"bg+" = "${types.bg}";
fg = "${types.border}";
"fg+" = "${types.border}";
hl = "${normal.red}";
"hl+" = "${normal.red}";
header = "${normal.red}";
marker = "${normal.magenta}";
info = "${normal.magenta}";
prompt = "${types.border}";
spinner = "${types.panelbg}";
pointer = "${types.border}";
};
};
};
}

View file

@ -0,0 +1,117 @@
{ config, options, lib, pkgs, ... }:
let
inherit (builtins) readFile;
inherit (lib.attrsets) attrValues optionalAttrs;
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.git = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "version-control system"; };
config = mkIf config.modules.shell.toolset.git.enable {
user.packages = attrValues ({
inherit (pkgs) act dura lazygit;
inherit (pkgs.gitAndTools) gh git-open;
}
// optionalAttrs config.modules.shell.toolset.gnupg.enable {
inherit (pkgs.gitAndTools) git-crypt;
});
# Prevent x11 askPass prompt on git push:
programs.ssh.askPassword = "";
hm.programs.zsh.initExtra = ''
# -------===[ Helpful Git Fn's ]===------- #
gitignore() {
curl -s -o .gitignore https://gitignore.io/api/$1
}
'';
hm.programs.fish.functions = {
gitignore = "curl -sL https://www.gitignore.io/api/$argv";
};
env = {GITHUB_TOKEN = "$(cat /run/agenix/tokenGH)";};
hm.programs.git = {
enable = true;
package = pkgs.gitFull;
difftastic = {
enable = true;
background = "dark";
color = "always";
display = "inline";
};
ignores = [
# General:
"*.bloop"
"*.bsp"
"*.metals"
"*.metals.sbt"
"*metals.sbt"
"*.direnv"
"*.envrc"
"*hie.yaml"
"*.mill-version"
"*.jvmopts"
# OS-related:
".DS_Store?"
".DS_Store"
".CFUserTextEncoding"
".Trash"
".Xauthority"
"thumbs.db"
"Thumbs.db"
"Icon?"
# Compiled residues:
"*.class"
"*.exe"
"*.o"
"*.pyc"
"*.elc"
];
extraConfig = {
init.defaultBranch = "main";
core = {
editor = "nvim";
whitespace = "trailing-space,space-before-tab";
};
credential.helper = "${pkgs.gitFull}/bin/git-credential-libsecret";
user = {
name = "Chris Kruining";
email = "chris@kruining.eu";
signingKey = readFile "${config.user.home}/.ssh/id_ed25519.pub";
};
gpg.format = "ssh";
commit.gpgSign = true;
tag.gpgSign = true;
push = {
default = "current";
gpgSign = "if-asked";
autoSquash = true;
};
pull.rebase = true;
filter = {
required = true;
smudge = "git-lfs smudge -- %f";
process = "git-lfs filter-process";
clean = "git-lfs clean -- %f";
};
url = {
"https://github.com/".insteadOf = "gh:";
"git@github.com:".insteadOf = "ssh+gh:";
};
};
};
};
}

View file

@ -0,0 +1,31 @@
{ config, options, lib, pkgs, ... }:
let
inherit (builtins) getEnv;
inherit (lib.modules) mkIf;
cfg = config.modules.shell.toolset.gnupg;
in
{
options.modules.shell.toolset.gnupg = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "cryptographic suite"; };
config = mkIf config.modules.shell.toolset.gnupg.enable {
environment.variables.GNUPGHOME = "$XDG_CONFIG_HOME/gnupg";
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
pinentryPackage = pkgs.pinentry-gnome3;
settings = let
cacheTTL = 86400;
in {
default-cache-ttl = cacheTTL;
default-cache-ttl-ssh = cacheTTL;
max-cache-ttl = cacheTTL;
max-cache-ttl-ssh = cacheTTL;
};
};
};
}

View file

@ -0,0 +1,85 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.starship = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "minimal shell ricing"; };
config = mkIf config.modules.shell.toolset.starship.enable {
hm.programs.starship = {
enable = true;
settings = let
inherit (config.modules.themes.colors.main) normal types;
in {
scan_timeout = 10;
add_newline = true;
line_break.disabled = true;
format = "$username$hostname$nix_shell$git_branch$git_commit$git_state$git_status$directory$jobs$cmd_duration$character";
username = {
style_user = "${normal.blue} bold";
style_root = "${normal.red} bold";
format = "[$user]($style) ";
disabled = false;
show_always = true;
};
hostname = {
ssh_only = false;
ssh_symbol = "🌐 ";
format = "on [$hostname](bold ${normal.red}) ";
trim_at = ".local";
disabled = false;
};
nix_shell = {
symbol = " ";
format = "[$symbol$name]($style) ";
style = "${normal.purple} bold";
};
git_branch = {
only_attached = true;
format = "[$symbol$branch]($style) ";
symbol = "";
style = "${normal.yellow} bold";
};
git_commit = {
only_detached = true;
format = "[$hash]($style) ";
style = "${normal.yellow} bold";
};
git_state = {
style = "${normal.purple} bold";
};
git_status = {
style = "${normal.green} bold";
};
directory = {
read_only = " ";
truncation_length = 0;
};
cmd_duration = {
format = "[$duration]($style) ";
style = "${normal.blue}";
};
jobs = {
style = "${normal.green} bold";
};
character = {
success_symbol = "[\\$](${normal.green} bold)";
error_symbol = "[\\$](${normal.red} bold)";
};
};
};
};
}

View file

@ -0,0 +1,126 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.tmux = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "terminal multiplexer"; };
config = mkIf config.modules.shell.toolset.tmux.enable {
hm.programs.tmux = {
enable = true;
secureSocket = true;
keyMode = "vi";
prefix = "C-a";
terminal = "tmux-256color";
baseIndex = 1;
clock24 = true;
disableConfirmationPrompt = true;
escapeTime = 0;
aggressiveResize = false;
resizeAmount = 2;
reverseSplit = false;
historyLimit = 5000;
newSession = true;
plugins = let
inherit (pkgs.tmuxPlugins) resurrect continuum;
in [
{
plugin = resurrect;
extraConfig = "set -g @resurrect-strategy-nvim 'session'";
}
{
plugin = continuum;
extraConfig = ''
set -g @continuum-restore 'on'
set -g @continuum-save-interval '60' # minutes
'';
}
];
extraConfig = let
inherit (config.modules.themes.colors.main) normal types;
in ''
# -------===[ Color Correction ]===------- #
set-option -ga terminal-overrides ",*256col*:Tc"
set-option -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
# -------===[ General-Configurations ]===------- #
set-option -g renumber-windows on
set-window-option -g automatic-rename on
set-window-option -g word-separators ' @"=()[]'
set-option -g mouse on
set-option -s focus-events on
set-option -g renumber-windows on
set-option -g allow-rename off
# -------===[ Activity/Sound ]===------- #
set-option -g bell-action none
set-option -g visual-bell off
set-option -g visual-silence off
set-option -g visual-activity off
set-window-option -g monitor-activity off
# -------===[ Status-Bar ]===------- #
set-option -g status on
set-option -g status-interval 1
set-option -g status-style bg=default,bold,italics
set-option -g status-position top
set-option -g status-justify left
set-option -g status-left-length "40"
set-option -g status-right-length "80"
# Messages:
set-option -g message-style fg="${types.bg}",bg="${types.highlight}",align="centre"
set-option -g message-command-style fg="${types.bg}",bg="${types.highlight}",align="centre"
# Panes:
set-option -g pane-border-style fg="${types.fg}"
set-option -g pane-active-border-style fg="${types.border}"
# Windows:
set-option -g window-status-format "#[fg=${types.fg}] #W/#{window_panes} "
set-option -g window-status-current-format "#{?client_prefix,#[fg=${types.bg}]#[bg=${normal.red}] #I:#W #[fg=${normal.red}]#[bg=default],#[fg=${types.bg}]#[bg=${normal.magenta}] #I:#W #[fg=${normal.magenta}]#[bg=default]}"
# -------===[ Statusline ]===------- #
set-option -g status-left "#[fg=${types.bg}]#[bg=${normal.blue}]#[bold] #[fg=${normal.blue}]#[bg=default]"
set-option -g status-bg default
set-option -g status-right "#[italics] #H | %b %d, %H:%M #[fg=${types.bg},bg=${types.highlight},bold,italics] base-#S "
# -------===[ Clock & Selection ]===------- #
set-window-option -g clock-mode-colour "${types.border}"
set-window-option -g mode-style "fg=${types.bg} bg=${types.highlight} bold"
# -------===[ Keybindings ]===------- #
bind-key c clock-mode
# Window Control(s):
bind-key q kill-session
bind-key Q kill-server
bind-key t new-window -c '#{pane_current_path}'
# Buffers:
bind-key b list-buffers
bind-key p paste-buffer
bind-key P choose-buffer
# Split bindings:
bind-key - split-window -v -c '#{pane_current_path}'
bind-key / split-window -h -c '#{pane_current_path}'
# Copy/Paste bindings:
bind-key -T copy-mode-vi v send-keys -X begin-selection -N "Start visual mode for selection"
bind-key -T copy-mode-vi y send-keys -X copy-selection -N "Yank text into buffer"
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle -N "Yank region into buffer"
'';
};
};
}

149
modules/shell/zsh.nix Normal file
View file

@ -0,0 +1,149 @@
{ config, options, pkgs, lib, ... }:
let
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.modules) mkIf;
inherit (lib.strings) concatStrings escapeNixString;
cfg = config.modules.shell;
in
{
config = mkIf (cfg.default == "zsh") {
modules.shell = {
corePkgs.enable = true;
toolset = {
macchina.enable = true;
starship.enable = true;
};
};
hm.programs.starship.enableZshIntegration = true;
# Enable completion for sys-packages:
environment.pathsToLink = ["/share/zsh"];
programs.zsh.enable = true;
hm.programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
history = {
size = 10000;
path = "${config.xdg.dataHome}/zsh/history";
};
oh-my-zsh = {
enable = true;
plugins = ["git" "docker-compose" "zoxide"];
};
plugins = let
mkZshPlugin = {
pkg,
file ? "${pkg.pname}.plugin.zsh",
}: {
name = pkg.pname;
src = pkg.src;
inherit file;
};
in
with pkgs; [
(mkZshPlugin {pkg = zsh-abbr;})
(mkZshPlugin {pkg = zsh-autopair;})
(mkZshPlugin {pkg = zsh-you-should-use;})
(mkZshPlugin {
pkg = zsh-nix-shell;
file = "nix-shell.plugin.zsh";
})
];
syntaxHighlighting = let
inherit (config.modules.themes) active;
inherit (config.modules.themes.colors.main) normal bright types;
in
mkIf (active != null) {
enable = true;
highlighters = ["main" "brackets" "pattern" "cursor" "regexp" "root" "line"];
patterns = {
"sudo " = "fg=${normal.red},bold";
"rm -rf *" = "fg=${normal.red},bold";
};
styles = {
# -------===[ Comments ]===------- #
comment = "fg=${normal.black}";
# -------===[ Functions/Methods ]===------- #
alias = "fg=${normal.magenta}";
"suffix-alias" = "fg=${normal.magenta}";
"global-alias" = "fg=${normal.magenta}";
function = "fg=${normal.blue}";
command = "fg=${normal.green}";
precommand = "fg=${normal.green},italic";
autodirectory = "fg=${normal.yellow},italic";
"single-hyphen-option" = "fg=${normal.yellow}";
"double-hyphen-option" = "fg=${normal.yellow}";
"back-quoted-argument" = "fg=${normal.magenta}";
# -------===[ Built-ins ]===------- #
builtin = "fg=${normal.blue}";
"reserved-word" = "fg=${normal.green}";
"hashed-command" = "fg=${normal.green}";
# -------===[ Punctuation ]===------- #
commandseparator = "fg=${bright.red}";
"command-substitution-delimiter" = "fg=${types.border}";
"command-substitution-delimiter-unquoted" = "fg=${types.border}";
"process-substitution-delimiter" = "fg=${types.border}";
"back-quoted-argument-delimiter" = "fg=${bright.red}";
"back-double-quoted-argument" = "fg=${bright.red}";
"back-dollar-quoted-argument" = "fg=${bright.red}";
# -------===[ Strings ]===------- #
"command-substitution-quoted" = "fg=${bright.yellow}";
"command-substitution-delimiter-quoted" = "fg=${bright.yellow}";
"single-quoted-argument" = "fg=${bright.yellow}";
"single-quoted-argument-unclosed" = "fg=${normal.red}";
"double-quoted-argument" = "fg=${bright.yellow}";
"double-quoted-argument-unclosed" = "fg=${normal.red}";
"rc-quote" = "fg=${bright.yellow}";
# -------===[ Variables ]===------- #
"dollar-quoted-argument" = "fg=${types.highlight}";
"dollar-quoted-argument-unclosed" = "fg=${bright.red}";
"dollar-double-quoted-argument" = "fg=${types.highlight}";
assign = "fg=${types.highlight}";
"named-fd" = "fg=${types.highlight}";
"numeric-fd" = "fg=${types.highlight}";
# -------===[ Non-Exclusive ]===------- #
"unknown-token" = "fg=${normal.red}";
path = "fg=${types.highlight},underline";
path_pathseparator = "fg=${bright.red},underline";
path_prefix = "fg=${types.highlight},underline";
path_prefix_pathseparator = "fg=${bright.red},underline";
globbing = "fg=${types.highlight}";
"history-expansion" = "fg=${normal.magenta}";
"back-quoted-argument-unclosed" = "fg=${normal.red}";
redirection = "fg=${types.highlight}";
arg0 = "fg=${types.highlight}";
default = "fg=${types.highlight}";
cursor = "fg=${types.highlight}";
};
};
};
home.configFile.zsh-abbreviations = {
target = "zsh/abbreviations";
text = let
abbrevs = import "${config.snowflake.configDir}/shell-abbr";
in ''
${concatStrings (mapAttrsToList
(k: v: "abbr ${k}=${escapeNixString v}")
abbrevs
)}
'';
};
};
}