nixos/apps/fastfetch.nix
2025-12-21 20:26:58 +00:00

107 lines
2.9 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ config, pkgs, ... }:
{
# Install fastfetch
environment.systemPackages = with pkgs; [
fastfetch
];
# Install Nerd Fonts for icon support
fonts.packages = with pkgs; [
nerd-fonts.fira-code
nerd-fonts.jetbrains-mono
nerd-fonts.meslo-lg
];
# Create the fastfetch config file
environment.etc."fastfetch/config.jsonc".text = ''
{
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
"logo": {
"source": "none"
},
"display": {
"separator": " ",
"color": {
"keys": "blue",
"title": "cyan"
},
"key": {
"type": "icon"
}
},
"modules": [
{
"type": "command",
"text": "echo $(whoami)@$(hostname) $(uname -r)"
},
{
"type": "colors",
"symbol": "circle"
}
]
}
'';
# Set up bash with fastfetch and a nice prompt
programs.bash.promptInit = ''
# Simple colored prompt without backgrounds
# Foreground colors
FG_ORANGE="\001$(echo -e '\033[38;5;208m')\002"
FG_GREEN="\001$(echo -e '\033[38;5;35m')\002"
FG_CYAN="\001$(echo -e '\033[38;5;37m')\002"
FG_BLUE="\001$(echo -e '\033[38;5;33m')\002"
FG_PURPLE="\001$(echo -e '\033[38;5;98m')\002"
FG_GRAY="\001$(echo -e '\033[38;5;245m')\002"
RESET="\001$(echo -e '\033[0m')\002"
# Function to build path with colored segments
build_path_prompt() {
local output=""
# Username in orange
output+="''${FG_ORANGE}\u''${RESET} "
# Path segments
local path="''${PWD/#$HOME/\~}"
# If we're in home directory, just show ~
if [ "$path" = "~" ]; then
output+="''${FG_GREEN}~''${RESET}"
echo -n "$output"
return
fi
local IFS='/'
local parts=($path)
local colors=("''${FG_GREEN}" "''${FG_CYAN}" "''${FG_BLUE}")
local i=0
for part in "''${parts[@]}"; do
if [ -n "$part" ]; then
local color_idx=$((i % 3))
if [ $i -gt 0 ]; then
output+="''${FG_GRAY}/''${RESET}"
fi
output+="''${colors[$color_idx]}$part''${RESET}"
((i++))
fi
done
echo -n "$output"
}
# Function to get git branch
parse_git_branch() {
local branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ -n "$branch" ]; then
echo -n " ''${FG_PURPLE} $branch''${RESET}"
fi
}
# Set prompt command to rebuild on each prompt
PROMPT_COMMAND='PS1="$(build_path_prompt)$(parse_git_branch) ''${FG_PURPLE}''${RESET} "'
'';
programs.bash.interactiveShellInit = ''
# Run fastfetch on terminal start
if [[ $- == *i* ]]; then
${pkgs.fastfetch}/bin/fastfetch --config /etc/fastfetch/config.jsonc
fi
'';
}