diff options
| author | Caroline Larimore <caroline@larimo.re> | 2025-04-14 19:01:38 -0700 |
|---|---|---|
| committer | Caroline Larimore <caroline@larimo.re> | 2025-04-14 19:01:38 -0700 |
| commit | e8077fde966e051fc449fffcfa061c7f7edc47b0 (patch) | |
| tree | a0b1ce60f2718f90c64e924ed8df8d5d4f0d2289 /modules/nixos/tools | |
| parent | e486d896215e7ef04438809952bc7317512d5765 (diff) | |
migration: finalize
Diffstat (limited to 'modules/nixos/tools')
| -rw-r--r-- | modules/nixos/tools/bash/default.nix | 29 | ||||
| -rw-r--r-- | modules/nixos/tools/bash/prompt.sh | 84 | ||||
| -rw-r--r-- | modules/nixos/tools/git/default.nix | 16 | ||||
| -rw-r--r-- | modules/nixos/tools/misc/default.nix | 19 | ||||
| -rw-r--r-- | modules/nixos/tools/rebuild/default.nix | 16 | ||||
| -rw-r--r-- | modules/nixos/tools/vim/default.nix | 19 |
6 files changed, 183 insertions, 0 deletions
diff --git a/modules/nixos/tools/bash/default.nix b/modules/nixos/tools/bash/default.nix new file mode 100644 index 0000000..180db1f --- /dev/null +++ b/modules/nixos/tools/bash/default.nix @@ -0,0 +1,29 @@ +{ options, config, lib, namespace, ... }: + +with lib; with lib.${namespace}; let + cfg = config.${namespace}.tools.bash; +in { + options.${namespace}.tools.bash = with types; { + enable = mkEnableOption "tools"; + }; + + config = mkIf cfg.enable { + environment.localBinInPath = true; + + programs.bash = { + shellAliases = { + lsa = "ls -lAsh"; + p = "nix-shell -p"; + }; + + interactiveShellInit = '' + source "${./prompt.sh}" + + mkcd() { + mkdir -p "$1" + cd "$1" + } + ''; + }; + }; +} diff --git a/modules/nixos/tools/bash/prompt.sh b/modules/nixos/tools/bash/prompt.sh new file mode 100644 index 0000000..d4d7c69 --- /dev/null +++ b/modules/nixos/tools/bash/prompt.sh @@ -0,0 +1,84 @@ +PROMPT_CHAR='❯' + +if [[ "$TERM" == "xterm-kitty" ]]; then + function prompt.bubble { + printf '\[\e[49m\e[38;5;237m\]◖\[\e[48;5;237m\e[39m\]%s\[\e[0m\e[49m\e[38;5;237m\]◗\[\e[0m\]' "$@"; + } +elif [[ "$TERM" == "xterm-256color" ]]; then + function prompt.bubble { + printf '\[\e[38;5;237m\](\[\e[0m\]%s\[\e[0m\e[38;5;237m\])\[\e[0m\]' "$@"; + } +else + PROMPT_CHAR='>' + function prompt.bubble { + printf '\[\e[2;39m\](\[\e[0m\]%s\[\e[0m\e[2;39m\])\[\e[0m\]' "$@"; + } +fi + +function prompt.git { + GIT_PS1_STATESEPARATOR=';' + GIT_PS1_SHOWDIRTYSTATE=1 + GIT_PS1_SHOWUNTRACKEDFILES= + GIT_PS1_SHOWUPSTREAM= + + GIT_PS1_HIDE_IF_PWD_IGNORED=1 + + local git_ps1="$(__git_ps1)" + git_ps1="${git_ps1##' ('}" + git_ps1="${git_ps1%')'}" + + IFS=';' read -r branch state _ <<< "$git_ps1" + + if [[ -n "$branch" ]]; then + printf ' ' + + if [[ "$state" == '*' ]]; then + prompt.bubble "$(printf '\[\e[4;32m\]%s' "$branch")" + else + prompt.bubble "$(printf '\[\e[32m\]%s' "$branch")" + fi + fi +} + +function prompt.prepare { + local err=$? + PS1="\\[\e[0m\\]\n" + + local subshell='' + local base_shlvl=1 + local shlvl=$((SHLVL-base_shlvl)) + + if [[ -n "$IN_NIX_SHELL" ]]; then + subshell="\\[\e[33m\\]nix" + fi + if [[ $shlvl != 0 && ! ($shlvl == 1 && -n "$IN_NIX_SHELL") ]]; then + if [[ -n "$subshell" ]]; then subshell+="\\[\e[39m\\] "; fi + subshell+="\\[\e[2;37m\\]$shlvl" + fi + if [[ -n "$subshell" ]]; then + PS1+="$(prompt.bubble "$subshell") " + fi + + if [[ $EUID == 0 ]]; then + PS1+="$(prompt.bubble "\\[\e[4m\\]\u@\H")" + else + PS1+="$(prompt.bubble "\u@\H")" + fi + + PS1+=" $(prompt.bubble "\\[\e[34m\\]\w")" + PS1+="$(prompt.git)" + if [[ $err != 0 ]]; then + PS1+=" $(prompt.bubble "\\[\e[31m\\]$err")" + fi + PS1+=" $(prompt.bubble "$PROMPT_CHAR") " + + if [[ $err != 0 ]]; then + (exit "$err") + fi +} + +PROMPT_COMMAND='prompt.prepare' + +function baller { + printf '🮲🮳⚽︎ \n' +} diff --git a/modules/nixos/tools/git/default.nix b/modules/nixos/tools/git/default.nix new file mode 100644 index 0000000..f58ed62 --- /dev/null +++ b/modules/nixos/tools/git/default.nix @@ -0,0 +1,16 @@ +{ options, config, lib, namespace, ... }: + +with lib; with lib.${namespace}; let + cfg = config.${namespace}.tools.git; +in { + options.${namespace}.tools.git = with types; { + enable = mkEnableOption "git"; + }; + + config = mkIf cfg.enable { + programs.git = { + enable = true; + prompt.enable = true; + }; + }; +} diff --git a/modules/nixos/tools/misc/default.nix b/modules/nixos/tools/misc/default.nix new file mode 100644 index 0000000..a06a141 --- /dev/null +++ b/modules/nixos/tools/misc/default.nix @@ -0,0 +1,19 @@ +{ options, config, lib, pkgs, namespace, ... }: + +with lib; with lib.${namespace}; let + cfg = config.${namespace}.tools.misc; +in { + options.${namespace}.tools.misc = with types; { + enable = mkEnableOption "misc tools"; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + jq + killall + moreutils + unzip + wget + ]; + }; +} diff --git a/modules/nixos/tools/rebuild/default.nix b/modules/nixos/tools/rebuild/default.nix new file mode 100644 index 0000000..368f29f --- /dev/null +++ b/modules/nixos/tools/rebuild/default.nix @@ -0,0 +1,16 @@ +{ options, config, lib, pkgs, namespace, ... }: + +with lib; with lib.${namespace}; let + cfg = config.${namespace}.tools.rebuild; +in { + options.${namespace}.tools.rebuild = with types; { + enable = mkEnableOption "rebuild scripts"; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + (writeShellScriptBin "rb" "sudo nixos-rebuild switch --flake /etc/nixos") + (writeShellScriptBin "rbf" "sudo nixos-rebuild switch --flake path:/etc/nixos") + ]; + }; +} diff --git a/modules/nixos/tools/vim/default.nix b/modules/nixos/tools/vim/default.nix new file mode 100644 index 0000000..9aa0a2c --- /dev/null +++ b/modules/nixos/tools/vim/default.nix @@ -0,0 +1,19 @@ +{ options, config, lib, pkgs, namespace, ... }: + +with lib; with lib.${namespace}; let + cfg = config.${namespace}.tools.vim; +in { + options.${namespace}.tools.vim = with types; { + enable = mkEnableOption "vim"; + }; + + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + vim + ]; + + environment.variables = { + EDITOR = "${pkgs.vim}/bin/vim"; + }; + }; +} |