install script

This commit is contained in:
Bryan Ramos 2024-05-13 15:03:30 -04:00
parent 27c2207f85
commit 4368228862
Signed by: bryan
GPG key ID: 6ABDCD144D6643C8
2 changed files with 154 additions and 85 deletions

111
install.sh Normal file
View file

@ -0,0 +1,111 @@
#!/usr/bin/env bash
set -euo pipefail
arg="${1:-nixos}"
isNixOS=$(grep -q 'ID=nixos' /etc/os-release)
case "$arg" in
"nixos")
if ! isNixOS; then
echo "⚠️ - Requires NixOS & sudo priveledge"
fi
echo "Install this NixOS Configuration? (y/n)"
while true; do
read res;
if [ "$res" = "y" ] || [ "$res" = "Y" ]; then
echo "Installing...";
if [ "$EUID" -ne 0 ]; then
echo "Allow sudo access? (y/n)"
while true; do
read -r res
case "$res" in
[yY])
exec sudo bash "$0" "$@"
exit 0
;;
[nN])
echo "Aborting..."
exit 1
;;
*)
echo "Please enter a valid response (y/n)"
;;
esac
done
fi
if [ -d "/etc/nixos" ]; then
echo "The /etc/nixos directory exists."
echo "Would you like to back up and proceed? (y/n)"
while true; do
read -r res
case "$res" in
[yY])
mkdir -p $(git rev-parse --show-toplevel)/bkup
cp -r /etc/nixos $(git rev-parse --show-toplevel)/bkup.nixos_$(date +%Y%m%d%H%M%S)
break
;;
[nN])
echo "Cancelled. Aborting..."
exit 1
;;
*)
echo "Error: Please enter a valid response (y/n)"
;;
esac
done
else
ln -s /etc/nixos $(git rev-parse --show-toplevel)
fi
fi
elif [ "{{TYPE}}" = "home" ]; then
echo "Install this Home-Manager Configuration?"
echo "⚠️ - If you don't have nix + home-manager installed, this will install them both"
echo "Proceed? (y/n)"
while true; do
read -r res
case "$res" in
[yY])
echo "Installing..."
if grep -q
if [ -d "$HOME/.config/home-manager" ]; then
echo "The ~/.config/home-manager directory exists."
echo "Would you like to back up and proceed? (y/n)"
while true; do
read -r res
case "$res" in
[yY])
mkdir -p $(git rev-parse --show-toplevel)/bkup
mv $HOME/.config/home-manager $(git rev-parse --show-toplevel)/bkup/home-manager_$(date +%Y%m%d%H%M%S)
ln -s $HOME/.config/home-manager $(git rev-parse --show-toplevel)
break
;;
[nN])
echo "Cancelled. Aborting..."
exit 1
;;
*)
echo "Error: Please enter a valid response (y/n)"
;;
esac
done
else
ln -s $HOME/.config/home-manager $(git rev-parse --show-toplevel)
fi
;;
[nN])
echo "Cancelled. Aborting..."
exit 1
;;
*)
echo "Error: Please enter a valid response (y/n)"
;;
esac
done
flake_config="experimental-features = nix-command flakes"
if [ -f "/etc/nix/nix.conf" ] || [ -f "$HOME/.config/nix/nix.conf" ]; then
if grep -q "^$flake_config" ""

124
justfile
View file

@ -1,89 +1,47 @@
# Run a dry-build # Output what derivations will be built
test TYPE="nix" SYSTEM="": test TYPE="nixos" SYSTEM="desktop":
@if [ "{{TYPE}}" = "home" ]; then \ #!/usr/bin/env bash
if [ -n "{{SYSTEM}}" ]; then \ set -euo pipefail
echo "Error: Undefined argument"; \ if [ "{{TYPE}}" = "home" ]; then
exit 1; \ if [ -n "{{SYSTEM}}" ]; then
fi; \ echo "Error: Undefined argument"
echo "Testing home configuration..."; \ exit 1
nix build --dry-run .#homeConfigurations."workstation".config.system.build.toplevel -L; \ fi
elif [ "{{TYPE}}" = "nix" ]; then \ echo "Testing home configuration..."
if [ -z "{{SYSTEM}}" ]; then \ nix build --dry-run .#homeConfigurations."workstation".config.system.build.toplevel -L
SYSTEM="desktop"; \ elif [ "{{TYPE}}" = "nixos" ]; then
fi; \ if [ "{{SYSTEM}}" = "desktop" ] || [ "{{SYSTEM}}" = "server" ] || [ "{{SYSTEM}}" = "wsl" ] || [ "{{SYSTEM}}" = "laptop" ]; then
if [ "{{SYSTEM}}" = "desktop" ] || [ "{{SYSTEM}}" = "server" ] || [ "{{SYSTEM}}" = "wsl" ] || [ "{{SYSTEM}}" = "laptop" ]; then \ echo "Testing NixOS configuration for {{SYSTEM}}..."
echo "Testing NixOS configuration for {{SYSTEM}}..."; \ nix build --dry-run .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L
nix build --dry-run .#nixosConfigurations."{{SYSTEM}}".config.system.build.toplevel -L; \ else
else \ echo "Error: Unknown argument - '{{SYSTEM}}'"
echo "Error: Unknown argument - '{{SYSTEM}}'"; \ echo "Use one of:"
echo "Use one of:"; \ echo " desktop"
echo " desktop"; \ echo " server"
echo " server"; \ echo " laptop"
echo " laptop"; \ echo " wsl"
echo " wsl"; \ exit 1
exit 1; \ fi
fi; \ else
else \ echo "Invalid usage: {{TYPE}}.";
echo "Invalid usage: {{TYPE}}. Use 'home' or 'nix'."; \ echo "Use one of:"
exit 1; \ echo " nixos"
echo " home"
exit 1
fi fi
# Install this repo # Symlinks /etc/nixos or ~/.config/home-manager to this repo
install TYPE="nixos": install:
if [ "${{TYPE}}" = "nixos" ]; then \ source ./install
echo "Install this NixOS Configuration? (y/n)" \
read res; \
if [ "$res" = "y"] || [ "$res" = "Y"]; then \
echo "Installing..."; \
if [ -d "/etc/nixos" ]; then \
echo "The /etc/nixos directory exists. Would you like to back up and proceed? (y/n)"; \
read answer; \
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then \
sudo cp -r /etc/nixos $(git rev-parse --show-toplevel)/nixos.bkup.$(date +%Y%m%d%H%M%S); \
elif [ "$answer" = "n" ] || [ "$answer" = "N" ]; then \
echo "Cancelled. Aborting..."; \
exit 1; \
else \
echo "Error: Please enter a valid response (y/n)" \
fi \
else \
sudo ln -s /etc/nixos $(git rev-parse --show-toplevel) \
fi \
elif [ "$res" = "n"] || [ "$res" = "N"]; then \
echo "Cancelled. Aborting..."; \
else \
echo "Error: Please enter a valid response (y/n)" \
fi
if [ "${{TYPE}}" = "home" ]; then \
echo "Install this Home-Manager Configuration? (y/n)" \
read res; \
if [ "$res" = "y"] || [ "$res" = "Y"]; then \
echo "Installing..."; \
if [ -d "~/.config/home-manager" ]; then \
echo "The ~/.config/home-manager directory exists. Would you like to back up and proceed? (y/n)"; \
read answer; \
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then \
sudo cp -r ~/.config/home-manager $(git rev-parse --show-toplevel)/home-manager.bkup.$(date +%Y%m%d%H%M%S); \
elif [ "$answer" = "n" ] || [ "$answer" = "N" ]; then \
echo "Cancelled. Aborting..."; \
exit 1; \
else \
echo "Error: Please enter a valid response (y/n)" \
fi \
else \
sudo ln -s ~/.config/home-manager $(git rev-parse --show-toplevel) \
fi \
elif [ "$res" = "n"] || [ "$res" = "N"]; then \
echo "Cancelled. Aborting..."; \
else \
echo "Error: Please enter a valid response (y/n)" \
fi
fi
# Commit all changes and push to upstream # Commit all changes and push to upstream
gh: gh MESSAGE="":
@echo "Commit message:" #!/usr/bin/env bash
@read message set -euo pipefail
if [ -n "{{MESSAGE}}" ]; then
git add -A git add -A
git commit -m "$$message" git commit -m "{{MESSAGE}}"
git push git push
else
echo "Error: Empty commit message"
fi