262 lines
6.9 KiB
Nix
262 lines
6.9 KiB
Nix
{
|
||
lib,
|
||
pkgs,
|
||
...
|
||
}:
|
||
let
|
||
zshSourceCommon = ./zsh/common;
|
||
|
||
isDarwin = pkgs.stdenv.hostPlatform.isDarwin;
|
||
isLinux = pkgs.stdenv.hostPlatform.isLinux;
|
||
in
|
||
{
|
||
imports = [
|
||
(import ./nix-init-scripts.nix {
|
||
inherit lib pkgs;
|
||
})
|
||
];
|
||
|
||
home.packages = with pkgs; [
|
||
awscli2
|
||
kubectl
|
||
nixd
|
||
yq
|
||
viu
|
||
];
|
||
|
||
# Let Home Manager install and manage itself.
|
||
programs.home-manager.enable = true;
|
||
|
||
programs.bat = {
|
||
enable = true;
|
||
};
|
||
|
||
programs.direnv = {
|
||
enable = true;
|
||
nix-direnv.enable = true;
|
||
};
|
||
|
||
programs.fzf = {
|
||
enable = true;
|
||
enableZshIntegration = true;
|
||
};
|
||
|
||
programs.htop = {
|
||
enable = true;
|
||
};
|
||
|
||
programs.k9s = {
|
||
enable = true;
|
||
settings = {
|
||
k9s = {
|
||
refreshRate = 2;
|
||
ui = {
|
||
logoless = true;
|
||
headless = true;
|
||
skin = "darkerbg";
|
||
};
|
||
logger = {
|
||
tail = 1000;
|
||
sinceSeconds = 60 * 30;
|
||
fullScreen = true;
|
||
showtime = true;
|
||
};
|
||
};
|
||
};
|
||
|
||
skins = {
|
||
darkerbg = {
|
||
k9s = {
|
||
body = {
|
||
bgColor = "#333";
|
||
};
|
||
frame = {
|
||
title = {
|
||
bgColor = "#333";
|
||
};
|
||
};
|
||
views = {
|
||
table = {
|
||
bgColor = "#333";
|
||
|
||
header = {
|
||
bgColor = "#333";
|
||
};
|
||
};
|
||
logs = {
|
||
bgColor = "#333";
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
};
|
||
|
||
programs.jq = {
|
||
enable = true;
|
||
};
|
||
|
||
programs.ripgrep = {
|
||
enable = true;
|
||
arguments = [
|
||
"--smart-case"
|
||
"--hidden"
|
||
];
|
||
};
|
||
|
||
programs.vim = {
|
||
enable = true;
|
||
settings = {
|
||
number = lib.mkDefault true;
|
||
relativenumber = lib.mkDefault true;
|
||
};
|
||
};
|
||
|
||
programs.zsh = {
|
||
enable = true;
|
||
|
||
autocd = lib.mkDefault true;
|
||
|
||
shellAliases =
|
||
{
|
||
# use eval $(aws-export-credentials) to expose them to environment
|
||
aws-export-credentials = lib.mkDefault "${pkgs.awscli2}/bin/aws configure export-credentials --format env --profile";
|
||
|
||
aws-export-assume-role = lib.mkDefault "${pkgs.writeShellScript "aws-export-assume-role" ''
|
||
[[ -z "$1" || -z "$2" ]] && echo "Usage: aws-export-assume-role <profile> <role-arn>" && exit 1
|
||
${pkgs.coreutils}/bin/printf 'export AWS_ACCESS_KEY_ID=%s\nexport AWS_SECRET_ACCESS_KEY=%s\nexport AWS_SESSION_TOKEN=%s' $(${pkgs.awscli2}/bin/aws --profile "$1" sts assume-role --role-arn "$2" --role-session-name lcech --query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" --output text)
|
||
''}";
|
||
|
||
aws-s3-cp-public = lib.mkDefault ''
|
||
${pkgs.awscli2}/bin/aws s3 cp --acl "public-read" --expires "$(${pkgs.coreutils}/bin/date '+%a, %d %b %Y 00:00:00 GMT' -d "$(${pkgs.coreutils}/bin/date +%Y-%m-%d) + 365 day")" --cache-control "max-age=31536000" --metadata-directive REPLACE
|
||
'';
|
||
|
||
bcrypt = lib.mkDefault "${pkgs.writeShellScript "bcrypt" ''
|
||
if [[ -z "$1" ]]; then
|
||
echo "Usage: bcrypt <password> [cost]"
|
||
exit 1
|
||
fi
|
||
|
||
echo -n "$1" | ${pkgs.apacheHttpd}/bin/htpasswd -i -nB -C ''${2:-12} "" | tr -d ':'
|
||
''}";
|
||
|
||
cat = lib.mkDefault "${pkgs.bat}/bin/bat --paging=never";
|
||
|
||
# use curl-aws --aws-sigv4 "aws:amz:region:service"
|
||
curl-aws = lib.mkDefault "${pkgs.curl}/bin/curl -H \"X-Amz-Security-Token: $AWS_SESSION_TOKEN\" --user \"$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY\"";
|
||
|
||
curl-timing = lib.mkDefault "${pkgs.curl}/bin/curl -w \" time_namelookup: %{time_namelookup}s\n time_connect: %{time_connect}s\n time_appconnect: %{time_appconnect}s\n time_pretransfer: %{time_pretransfer}s\n time_redirect: %{time_redirect}s\n time_starttransfer: %{time_starttransfer}s\n ----------\n time_total: %{time_total}s\n\" -o /dev/null";
|
||
|
||
dbase64 = lib.mkDefault "${pkgs.writeShellScript "dbase64" "echo -n \"$1\" | base64 -d"}";
|
||
|
||
git-sync-remote = lib.mkDefault "git remote update origin --prune";
|
||
|
||
klogs = lib.mkDefault "${pkgs.writeShellScript "klogs" ''
|
||
ctx="$1"
|
||
shift
|
||
namespace="$1"
|
||
shift
|
||
label="$1"
|
||
shift
|
||
|
||
if [[ "$ctx" == "" || "$namespace" == "" || "$label" == "" ]]; then
|
||
echo "Usage: klogs context namespace label"
|
||
echo "${"\n"}Contexts:"
|
||
kubectl config get-contexts -o name | sed 's/^/\t/g'
|
||
|
||
echo "Label examples:"
|
||
echo "${"\t"}app.kubernetes.io/name=..."
|
||
echo "${"\t"}eks.amazonaws.com/component=..."
|
||
exit 1
|
||
fi
|
||
|
||
kubectl --context "$ctx" logs -f -n "$namespace" -l "$label" $@
|
||
''}";
|
||
|
||
nixfix = lib.mkDefault "nix fmt ./**/*.nix";
|
||
|
||
# Git
|
||
a = "git add";
|
||
c = "git commit -m";
|
||
d = "git diff";
|
||
d-s = "git diff --staged";
|
||
gtag = "${pkgs.writeShellScript "gtag" "git tag -a $1 -m '$2'"}";
|
||
gtag-replace = "${pkgs.writeShellScript "gtag" ''
|
||
msg=$(git tag -l -n9 $1 | sed "s/$1\s\+//g")
|
||
git tag -d $1 && \
|
||
git push origin :refs/tags/$1 && \
|
||
git tag -a $1 -m "$msg" && \
|
||
git push origin $1
|
||
''}";
|
||
gtagl = "git fetch --tags && git tag -l -n9 --sort=-v:refname";
|
||
s = "git status";
|
||
}
|
||
// (
|
||
if isDarwin then
|
||
{
|
||
hm-switch = lib.mkDefault "darwin-rebuild switch --flake ~/.config/nix";
|
||
}
|
||
else if isLinux then
|
||
{
|
||
hm-switch = lib.mkDefault "home-manager switch --impure --flake ~/.config/nix";
|
||
}
|
||
else
|
||
{ }
|
||
);
|
||
|
||
initContent = lib.mkBefore ''
|
||
for file in ${zshSourceCommon}/*.zsh; do
|
||
source "$file"
|
||
done
|
||
|
||
# [Ctrl-RightArrow] - move forward one word
|
||
bindkey '^[[1;3C' forward-word
|
||
# [Ctrl-LeftArrow] - move backward one word
|
||
bindkey '^[[1;3D' backward-word
|
||
'';
|
||
};
|
||
|
||
programs.starship = {
|
||
enable = true;
|
||
enableZshIntegration = true;
|
||
|
||
settings = {
|
||
format = lib.concatStrings [
|
||
"$username"
|
||
"$hostname"
|
||
"$directory"
|
||
"$character"
|
||
];
|
||
right_format = lib.concatStrings [
|
||
"$git_branch"
|
||
"$git_commit"
|
||
"$git_state"
|
||
"$git_metrics"
|
||
"$git_status"
|
||
"($cmd_duration)"
|
||
];
|
||
scan_timeout = 25;
|
||
add_newline = false;
|
||
continuation_prompt = "[▸▹ ](dimmed white)";
|
||
follow_symlinks = false;
|
||
directory = {
|
||
truncate_to_repo = false;
|
||
truncation_length = 20;
|
||
truncation_symbol = "…/";
|
||
};
|
||
|
||
cmd_duration = {
|
||
min_time = 100;
|
||
show_milliseconds = true;
|
||
format = "took [$duration]($style) ";
|
||
style = "bold yellow";
|
||
};
|
||
|
||
character = {
|
||
success_symbol = "[›](bold green)";
|
||
error_symbol = "[!](bold red)";
|
||
};
|
||
};
|
||
};
|
||
}
|