Compare commits

..

4 Commits

Author SHA1 Message Date
Lukas Cech
46f71fabdd Refactor nix init scripts 2025-01-23 13:03:52 +01:00
Lukas Cech
28a44e36fa Refactor aliases 2025-01-23 13:03:39 +01:00
Lukas Cech
ae9c1b1469 Shell alias rewrite part 1 2025-01-21 17:36:40 +01:00
Lukas Cech
802eba9819 Update nix init scripts 2025-01-21 17:36:23 +01:00
13 changed files with 176 additions and 295 deletions

View File

@ -225,8 +225,13 @@ in
enable = true; enable = true;
shellAliases = { shellAliases = {
hm-switch = "home-manager switch --impure --flake ~/.config/nix";
configure-ssh-terminfo = "f(){ infocmp -x | ssh \"$@\" -- tic -x -; unset -f f; }; f"; configure-ssh-terminfo = "f(){ infocmp -x | ssh \"$@\" -- tic -x -; unset -f f; }; f";
aws-ecr-login-skoda = "aws --profile skoda-prod --region eu-central-1 ecr get-login-password | sudo docker login 943160431142.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin";
aws-ecr-login-scholaris = "aws --profile skoda-sch-dev --region eu-central-1 ecr get-login-password | sudo docker login 442913623981.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin";
aws-ecr-login-yp = "aws-vault exec yp aws --region eu-central-1 ecr get-login-password | sudo docker login 060714730522.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin";
aws-ecr-login-investbay = "aws-vault exec InvestBay-AccountManagement aws --region eu-central-1 ecr get-login-password | sudo docker login 297503416491.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin";
}; };
dirHashes = { dirHashes = {
mac = "${homedir}/storage/.macshare"; mac = "${homedir}/storage/.macshare";
@ -393,5 +398,7 @@ in
EDITOR = "vim"; EDITOR = "vim";
GO111MODULE = "on"; GO111MODULE = "on";
TERMINAL = "ghostty"; TERMINAL = "ghostty";
AWS_VAULT_BACKEND = "secret-service";
AWS_VAULT_SECRET_SERVICE_COLLECTION_NAME = "default";
}; };
} }

View File

@ -110,13 +110,61 @@ in
shellAliases = shellAliases =
{ {
cat = lib.mkDefault "bat --paging=never";
nixfix = lib.mkDefault "nix fmt ./**/*.nix";
# use eval $(aws-export-credentials) to expose them to environment # use eval $(aws-export-credentials) to expose them to environment
aws-export-credentials = lib.mkDefault "aws configure export-credentials --format env --profile"; aws-export-credentials = lib.mkDefault "${pkgs.awscli2}/bin/aws configure export-credentials --format env --profile";
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
'';
cat = lib.mkDefault "${pkgs.bat}/bin/bat --paging=never";
# use curl-aws --aws-sigv4 "aws:amz:region:service" # use curl-aws --aws-sigv4 "aws:amz:region:service"
curl-aws = lib.mkDefault "curl -H \"X-Amz-Security-Token: $AWS_SESSION_TOKEN\" --user \"$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY\""; 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"; git-sync-remote = lib.mkDefault "git remote update origin --prune";
klogs = lib.mkDefault "${pkgs.writeShellScript "klogs" ''
local ctx="$1"
local namespace="$2"
local label="$3"
if [[ "$ctx" == "" || "$namespace" == "" || "$label" == "" ]]; then
echo "Usage: klogs context namespace label"
echo "\nContexts:"
kubectl config get-contexts -o name | sed 's/^/\t/g'
echo "Label examples:"
echo "\tapp.kubernetes.io/name=..."
echo "\teks.amazonaws.com/component=..."
return 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 if isDarwin then
@ -125,7 +173,7 @@ in
} }
else if isLinux then else if isLinux then
{ {
hm-switch = lib.mkDefault "home-manager switch --flake ~/.config/nix"; hm-switch = lib.mkDefault "home-manager switch --impure --flake ~/.config/nix";
} }
else else
{ } { }
@ -181,7 +229,7 @@ in
character = { character = {
success_symbol = "[](bold green)"; success_symbol = "[](bold green)";
error_symbol = "[](bold red)"; error_symbol = "[!](bold red)";
}; };
}; };
}; };

View File

@ -0,0 +1,23 @@
{
inputs = {
nix.url = "git+ssh://git@git.investbay.dev/devops/nix?branch=main";
};
outputs =
{ self, nix }:
{
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "investbay";
packages = with pkgs; [
];
commands = [ ];
};
});
};
}

View File

@ -0,0 +1,23 @@
{
inputs = {
nix.url = "git+ssh://git@bitbucket.org/yourpass/nix";
};
outputs =
{ self, nix }:
{
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "yp";
packages = with pkgs; [
];
commands = [ ];
};
});
};
}

View File

@ -1,66 +1,90 @@
{ lib, pkgs, ... }: { lib, pkgs, ... }:
let let
nix-prepare = pkgs.writeShellScript "nix-prepare" '' flake-dir =
run() { {
local dir="$1" flake,
echo "Preparing nix environment in $dir" impure ? false,
}:
pkgs.writeShellScript "nix-prepare" ''
run() {
local dir="$1"
echo "Preparing nix environment in $dir"
if [ "$dir" = "" ]; then if [ "$dir" = "" ]; then
echo "Usage: nix-prepare <dir>" echo "Usage: nix-prepare <dir>"
exit 1 exit 1
fi fi
mkdir -p $dir mkdir -p $dir
cd $dir cd $dir
git init git init
# Insert the nix flake # Insert the nix flake
cp ${./flake-templates/c3c-flake.nix} flake.nix cp ${flake} flake.nix
chmod 644 flake.nix chmod 644 flake.nix
echo '/*' > .gitignore echo '/*' > .gitignore
echo '!/.gitignore' >> .gitignore echo '!/.gitignore' >> .gitignore
echo '!/flake.nix' >> .gitignore echo '!/flake.nix' >> .gitignore
echo '!/flake.lock' >> .gitignore echo '!/flake.lock' >> .gitignore
echo 'use flake . --impure' > .envrc echo 'use flake .${(if impure then " --impure" else "")}' > .envrc
git add flake.nix .gitignore git add flake.nix .gitignore
git commit -m "Setup initial flake" git commit -m "Setup initial flake"
direnv allow direnv allow
eval "$(direnv export bash)" eval "$(direnv export bash)"
git add flake.lock git add flake.lock
git commit -m "Lock flakes" git commit -m "Lock flakes"
} }
run "$@" run "$@"
''; '';
git-nix-clone = pkgs.writeShellScript "git-nix-clone" '' git-flake-dir-clone =
# Input is a git repository such as git@github.com:group/project-name.git {
run() { flake,
local repo="$1" impure ? false,
local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//') }:
pkgs.writeShellScript "git-nix-clone" ''
# Input is a git repository such as git@github.com:group/project-name.git
run() {
local repo="$1"
local projectName=$(echo "$repo" | sed 's/.*\///' | sed 's/\.git//')
if [ "$repo" = "" ]; then if [ "$repo" = "" ]; then
echo "Usage: git-nix-clone <repo>" echo "Usage: git-nix-clone <repo>"
exit 1 exit 1
fi fi
${nix-prepare} "$projectName"-nix ${flake-dir { inherit flake impure; }} "$projectName"-nix
git clone "$repo" "$projectName"-nix"/$projectName" git clone "$repo" "$projectName"-nix"/$projectName"
} }
run "$@" run "$@"
''; '';
in in
{ {
programs.zsh.shellAliases = { programs.zsh.shellAliases = {
git-nix-clone = lib.mkDefault "${git-nix-clone}"; git-c3c-clone = lib.mkDefault "${git-flake-dir-clone {
nix-prepare = lib.mkDefault "${nix-prepare}"; flake = ./flake-templates/c3c-flake.nix;
impure = true;
}}";
flake-dir-c3c = lib.mkDefault "${flake-dir {
flake = ./flake-templates/c3c-flake.nix;
impure = true;
}}";
flake-dir-yp = lib.mkDefault "${flake-dir {
flake = ./flake-templates/yp-flake.nix;
impure = false;
}}";
flake-dir-investbay = lib.mkDefault "${flake-dir {
flake = ./flake-templates/investbay-flake.nix;
impure = false;
}}";
}; };
} }

View File

@ -1 +0,0 @@
alias hm-switch="home-manager switch --flake ~/.config/nix"

View File

@ -1,11 +1,4 @@
# Allow usage of aliases when using sudo
alias less='less -R' alias less='less -R'
alias curlTiming="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_starttransfe
r: %{time_starttransfer}s\n ----------\n time_total: %{time_total}s\n\" -o /dev/null"
dbase64() {
echo -n "${1}" | base64 -d
}
function appConnections() function appConnections()
{ {

View File

@ -1,9 +0,0 @@
alias dockerVolumeSizes="for vol in \$(docker volume ls -q); do sudo du -hs \$(docker volume inspect --format \"{{.Mountpoint}}\" \$vol); done"
alias dockerstats="docker stats \$(docker ps --format \"{{.Names}}\")"
alias dockerRemove="docker rmi -f \$(docker images | grep none | awk '{print \$3}')"
function bcrypt() {
nix-shell -p apacheHttpd --run "echo -n '${1}' | htpasswd -i -nB -C ${2:-12} '' | tr -d ':'"
}

View File

@ -1,71 +0,0 @@
# Git
alias c="git commit -m"
alias s="git status"
alias gtagl="git fetch --tags && git tag -l -n9 --sort=-v:refname"
alias d="git diff"
alias d-s="git diff --staged"
alias a="git add"
alias n="git checkout -b"
alias m="git merge --no-ff"
alias gitSquash="git rebase --root -i"
gtag() {
git tag -a $1 -m "$2"
}
gtagReplace() {
local msg
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
}
gtagRemoveMinor() {
if [[ $1 = "" ]]; then
echo "How does the tag begin?"
fi
local remove
local tags=$(git tag -l | grep "^${1}\.")
echo "${tags}"
echo -n "Remove these tags? (y/n) "
read remove
if [[ ${remove} != "y" ]] && [[ ${remove} != "yes" ]]; then
echo "Ok then!"
return 2
fi
while read -r tag; do
git tag -d ${tag}
git push origin :refs/tags/${tag}
done <<< "${tags}"
}
gdiff() {
local awkFormat='{ $2=on $2 off }; 1'
local masterDiff=$(git cherry -v develop master | awk -v on="\033[31;33m" -v off="\033[0m" ${awkFormat})
local develDiff=$(git cherry -v master develop | awk -v on="\033[31;33m" -v off="\033[0m" ${awkFormat})
if [[ "${masterDiff}" != "" ]]; then
echo "\033[1;31;32mOnly in master:\033[0m"
echo
echo "${masterDiff}"
fi
if [[ "${develDiff}" != "" ]]; then
echo "\033[1;31;33mOnly in develop:\033[0m"
echo
echo "${develDiff}"
fi
}
alias gitRemoveMerged="git branch --merged origin/master | grep -v '* master' | xargs git branch -d"

View File

@ -1,18 +0,0 @@
function klogs() {
local ctx="$1"
local namespace="$2"
local label="$3"
if [[ "$ctx" == "" || "$namespace" == "" || "$label" == "" ]]; then
echo "Usage: klogs context namespace label"
echo "\nContexts:"
kubectl config get-contexts -o name | sed 's/^/\t/g'
echo "Label examples:"
echo "\tapp.kubernetes.io/name=..."
echo "\teks.amazonaws.com/component=..."
return 1
fi
kubectl --context "$context" logs -f -n "$namespace" -l "$label"
}

View File

@ -1,124 +0,0 @@
init-nix-flake() {
local tpl=$1
local name=$2
local flakePath="$(pwd)/flake.nix"
local envrcPath="$(pwd)/.envrc"
[[ -f "${flakePath}" ]] && echo "${flakePath} already present" && return 1
[[ -f "${envrcPath}" ]] && echo "${envrcPath} already present" && return 1
if [[ "$tpl" == "yp" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@bitbucket.org/yourpass/nix";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "yp-${name}";
packages = with pkgs; [
];
commands = [];
};
});
};
}
EOF
echo "use flake" > "${envrcPath}"
direnv allow
elif [[ "$tpl" == "investbay" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@git.investbay.dev/morosystems/investbay/devops/nix?branch=main";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
name = "investbay-${name}";
packages = with pkgs; [
];
commands = [];
};
});
};
}
EOF
echo "use flake" > "${envrcPath}"
direnv allow
elif [[ "$tpl" == "c3c" ]]; then
cat <<EOF > "${flakePath}"
{
inputs = {
nix.url = "git+ssh://git@git.c3c.cz/C3C/nix";
};
outputs = { self, nix }: {
formatter = nix.formatter;
devShells = nix.lib.forAllSystems (pkgs: {
default = nix.lib.mkDevenvShell {
inherit pkgs;
inputs = {
self = self;
nixpkgs = pkgs;
};
modules = [
{
packages = with pkgs; [
];
scripts = {
menu = {
description = "Print this menu";
exec = ''
echo "Commands:"
echo -n '\${
builtins.toJSON (
builtins.mapAttrs (s: value: value.description) self.devShells.\${pkgs.system}.default.config.scripts
)
}' | \
\${pkgs.jq}/bin/jq -r 'to_entries | map(" \(.key)\n" + " - \(if .value == "" then "no description provided" else .value end)") | "" + .[]'
'';
};
fix = {
exec = ''
\${nix.lib.cd_root}
nix fmt ./*.nix
\${pkgs.golangci-lint}/bin/golangci-lint run --sort-results --out-format tab --config \${nix.lib.golangci-config-file} --fix --issues-exit-code 0 ./...
stylua ./src
'';
};
};
}
];
};
});
};
}
EOF
echo "use flake . --impure" > "${envrcPath}"
direnv allow
else
echo "Wrong template as first arg: [yp/investbay/c3c]"
return 1
fi
}

View File

@ -1,5 +0,0 @@
alias awsKubeconfig="aws eks --region eu-central-1 update-kubeconfig --name "
alias loginToSkodaECR="aws --profile skoda-prod --region eu-central-1 ecr get-login-password | sudo docker login 943160431142.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToSkodaScholarisECR="aws --profile skoda-sch-dev --region eu-central-1 ecr get-login-password | sudo docker login 442913623981.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToYpECR="aws-vault exec yp aws --region eu-central-1 ecr get-login-password | sudo docker login 060714730522.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"
alias loginToInvestBayECR="aws-vault exec InvestBay-AccountManagement aws --region eu-central-1 ecr get-login-password | sudo docker login 297503416491.dkr.ecr.eu-central-1.amazonaws.com -u AWS --password-stdin"

View File

@ -1,9 +0,0 @@
export AWS_VAULT_BACKEND=secret-service
export AWS_VAULT_SECRET_SERVICE_COLLECTION_NAME=default
alias argoyp='argo --context yp:060714730522:eu-west-1/yp-dev -n argo'
function awsS3cpWithPublic {
local expires=$(date '+%a, %d %b %Y 00:00:00 GMT' -d "$(date +%Y-%m-%d) + 365 day")
aws s3 cp --acl "public-read" --expires "${expires}" --cache-control "max-age=31536000" --metadata-directive REPLACE $@
}