flake/nixos/shell.nix

182 lines
5.5 KiB
Nix

{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
any-nix-shell
];
users.defaultUserShell = pkgs.zsh;
programs.zsh = {
enable = true;
enableBashCompletion = true;
enableCompletion = true;
autosuggestions.enable = true;
syntaxHighlighting.enable = true;
shellInit = # zsh
''
# Directory containing the Python scripts
SCRIPT_DIR="/etc/nixos/scripts/py"
# Ensure the directory exists
if [[ ! -d "$SCRIPT_DIR" ]]; then
echo "Directory $SCRIPT_DIR does not exist."
return 1
fi
# Register aliases for each .py file in the directory
for script in "$SCRIPT_DIR"/*.py; do
[[ -f "$script" ]] || continue # Skip if no .py files found
script_name="''${script##*/}" # Extract filename
alias_name="''${script_name%.py}" # Strip .py extension
alias "$alias_name"="\"$script\""
done
_edit() {
local args=("$@")
if [[ ''${#args[@]} -eq 0 ]]; then
args=(".")
fi
if [[ -n "$SSH_CONNECTION" ]]; then
command "$EDITOR" "''${args[@]}"
else
command "$VISUAL" "''${args[@]}"
fi
}
_set_secret_and_run() {
if [[ $# -lt 2 ]]; then
echo "Usage: _set_secret_and_run <secret_file> <var_name> <command> [args...]"
return 1
fi
local secret_file="$1"
local var_name="$2"
shift 2
if [[ ! -f "$secret_file" ]]; then
echo "Error: Secret file '$secret_file' not found."
return 1
fi
echo "Setting $var_name to secret value from $secret_file"
local old_value="''${(P)var_name}"
local secret_value=$(<"$secret_file")
export $var_name="$secret_value"
echo "Running command: $@"
command "$@"
export $var_name="$old_value"
}
if (( $+commands[kitten] )); then
alias "ssh"="kitten ssh"
fi
source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
'';
promptInit = # zsh
''
${pkgs.any-nix-shell}/bin/any-nix-shell zsh --info-right | source /dev/stdin
'';
shellAliases = {
ff = "fastfetch";
neofetch = "fastfetch";
nf = "fastfetch";
lg = "lazygit";
lad = "lazydocker";
clip = "wl-copy";
clp = "clip";
paste = "wl-paste";
cat = "bat";
git = "hub";
cc = "fj --host=https://c.csw.im --style=fancy";
cb = "fj --host https://codeberg.org --style=fancy";
eza = "eza --time-style=long-iso --icons=auto --hyperlink";
l = "eza -lhg";
la = "eza -lAh";
ll = "l";
ls = "eza";
lsa = "eza -lah";
tree = "eza --tree --git-ignore";
nixpkgs-update = "nix run ;--option extra-substituters 'https://nix-community.cachix.org/' --option extra-trusted-public-keys 'nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=' github:ryantm/nixpkgs-update --";
nixrc = "edit /etc/nixos";
taildrop = "tailscale file";
forgejo-runner = "act_runner";
runactions = "act_runner exec --default-actions-url=https://c.csw.im --gitea-instance=https://c.csw.im";
uvr = "uv run";
ns = "nix-shell";
edit = "_edit";
e = "edit";
c = "clear";
sudo = "sudo ";
bun = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bun";
bunx = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bunx";
publish = "_set_secret_and_run /run/secrets/npm NPM_CONFIG_TOKEN bun publish --access public";
s = "sudo";
};
histSize = 10000;
histFile = "$HOME/.zsh_history";
};
# starship - a customizable prompt for any shell
programs.starship = {
enable = true;
# custom settings
settings = {
format = "[](bg:#1e1e2e fg:#a6e3a1)$username$hostname[](fg:#a6e3a1 bg:#89b4fa)$directory[](fg:#89b4fa bg:#cba6f7)$direnv[](fg:#cba6f7 bg:#f9e2af)$git_branch$git_status[](fg:#f9e2af bg:#1e1e2e)$character";
username = {
show_always = true;
format = "[ $user@]($style)";
style_user = "fg:#313244 bg:#a6e3a1";
style_root = "fg:#313244 bg:#a6e3a1";
};
hostname = {
ssh_only = false;
format = "[$hostname $ssh_symbol]($style)";
style = "fg:#313244 bg:#a6e3a1";
};
directory = {
format = "[ $path ]($style)";
style = "fg:#313244 bg:#89b4fa";
};
git_branch = {
format = "[ $symbol$branch(:$remote_branch) ]($style)";
symbol = " ";
style = "fg:#313244 bg:#f9e2af";
};
direnv = {
symbol = "󱄅 ";
format = "[ $symbol$loaded/$allowed ]($style)";
disabled = false;
style = "fg:#313244 bg:#cba6f7";
};
git_status = {
format = "[$all_status]($style)";
style = "fg:#313244 bg:#f9e2af";
};
git_metrics = {
format = "([+$added]($added_style))[]($added_style)";
added_style = "fg:#313244 bg:#f9e2af";
deleted_style = "fg:bright-red bg:235";
disabled = false;
};
hg_branch = {
format = "[ $symbol$branch ]($style)";
symbol = " ";
};
cmd_duration = {
format = "[ $duration ]($style)";
style = "fg:bright-white bg:18";
};
character = {
success_symbol = "[ ](#a6e3a1) ";
error_symbol = "[ ](#f38ba8) ";
};
add_newline = false;
};
};
}