commit c6d952ab49971989b7c9cc497bbb485de1894c08 Author: Marta Sokolska Date: Sat Jun 7 22:55:28 2025 +0200 Init diff --git a/nixie b/nixie new file mode 100755 index 0000000..c00341c --- /dev/null +++ b/nixie @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +# Reset +NC='\033[0m' # Text Reset +# Regular Colors +Black='\033[0;30m' # Black +Red='\033[0;31m' # Red +Green='\033[0;32m' # Green +Yellow='\033[0;33m' # Yellow +Blue='\033[0;34m' # Blue +Purple='\033[0;35m' # Purple +Cyan='\033[0;36m' # Cyan +White='\033[0;37m' # White +# Bold +BBlack='\033[1;30m' # Black +BRed='\033[1;31m' # Red +BGreen='\033[1;32m' # Green +BYellow='\033[1;33m' # Yellow +BBlue='\033[1;34m' # Blue +BPurple='\033[1;35m' # Purple +BCyan='\033[1;36m' # Cyan +BWhite='\033[1;37m' # White +# High Intensity +IBlack='\033[0;90m' # Black +IRed='\033[0;91m' # Red +IGreen='\033[0;92m' # Green +IYellow='\033[0;93m' # Yellow +IBlue='\033[0;94m' # Blue +IPurple='\033[0;95m' # Purple +ICyan='\033[0;96m' # Cyan +IWhite='\033[0;97m' # White +# Bold High Intensity +BIBlack='\033[1;90m' # Black +BIRed='\033[1;91m' # Red +BIGreen='\033[1;92m' # Green +BIYellow='\033[1;93m' # Yellow +BIBlue='\033[1;94m' # Blue +BIPurple='\033[1;95m' # Purple +BICyan='\033[1;96m' # Cyan +BIWhite='\033[1;97m' # White + +# Functions + +QUIT () { + popd + exit +} + +CHOOSE_CASE () { + echo -e -n "${IPurple}Build changes? ${Purple}Yes/Preview/Edit/Restore/Quit. (y/p/e/r/q):${NC} " + + read CHOICE + case $CHOICE in + [yY]* ) BUILD ;; + [pP]* ) PREVIEW ;; + [eE]* ) EDIT ;; + [rR]* ) RESTORE ;; + [qQ]* ) echo -e "${IPurple}Quitting nixie. ${Purple}Changes kept in /etc/nixos.${NC}" && QUIT ;; + *) echo -e -n "[ ${Red}incorrect input${NC} ] " && CHOOSE_CASE ;; + esac +} + +BUILD () { + echo -e "${IPurple}This will rebuild NixOS, and if there are no errors, commit changes to git." + echo -e -n "${IPurple}Are you sure you want to do this? ${Purple}(Y/n):${NC} " + read CHOICE + case $CHOICE in + [nN]* ) echo -e -n "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;; + *) + git add . + echo -e "${IPurple}Rebuilding NixOS...${NC}" + sudo nixos-rebuild switch + if [ $? -ne 0 ]; then + echo -e "[ ${Bred}error${NC} ] ${Red}Rebuilding NixOS failed.${NC}" + QUIT + fi + echo -e "${IPurple}Committing the changes...${NC}" + sudo git commit --no-status -am "$(sudo nixos-rebuild list-generations | grep current)" + echo -e "${IPurple}System rebuilt, configuration commited. Quitting nixie.${NC}" + QUIT + ;; + esac +} + +PREVIEW () { + sudo git diff + CHOOSE_CASE +} + +EDIT () { + sudo vim . + sudo git diff --stat + CHOOSE_CASE +} + +RESTORE () { + echo -e "[ ${Yellow}Warning${NC} ] ${Purple}This will restore /etc/nixos to the last commit.${NC}" + echo -e -n "[ ${Yellow}Warning${NC} ] ${Purple}Are you sure you want to disregard the changes? (y/N):${NC} " + read CHOICE + case $CHOICE in + [yY]* ) sudo -k git restore . && echo -e "${IPurple}Quitting nixie. ${Purple}Changes disregarded.${NC}" && QUIT ;; + *) echo -e -n "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;; + esac +} + +# Script +pushd /etc/nixos + +echo -e "${IPurple}Running pixie. You might be asked to input the root password.${NC}" +EDIT + +QUIT