This commit is contained in:
2026-01-22 11:10:21 -07:00
parent f918c336fe
commit 285b8f3799
3 changed files with 60 additions and 87 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -1,63 +1,31 @@
.PHONY: init install link unlink rebuild update purge edit help .PHONY: init rebuild update purge help
NIXOS_DIR := /etc/nixos
REPO_DIR := $(shell pwd) REPO_DIR := $(shell pwd)
SETTINGS := settings.nix
# Colors for output
GREEN := \033[0;32m GREEN := \033[0;32m
YELLOW := \033[0;33m YELLOW := \033[0;33m
RED := \033[0;31m RED := \033[0;31m
NC := \033[0m # No Color NC := \033[0m
help: help:
@echo "NixOS Config" @echo "NixOS Config"
@echo "" @echo ""
@echo " make init - first time setup" @echo " make init - first time setup"
@echo " make rebuild - rebuild nixos" @echo " make rebuild - rebuild nixos with flakes"
@echo " make update - upgrade + rebuild" @echo " make update - update flake inputs and rebuild"
@echo " make purge - garbage collect" @echo " make purge - garbage collect"
@echo " make link - symlink to /etc/nixos"
@echo " make unlink - remove symlink"
@echo " make edit - edit settings.nix"
init: init:
@./scripts/init.sh @./scripts/init.sh
@$(MAKE) --no-print-directory link
@echo ""
@echo "done. run 'make rebuild' when ready"
link:
@if [ -L "$(NIXOS_DIR)" ]; then \
sudo rm $(NIXOS_DIR); \
elif [ -d "$(NIXOS_DIR)" ]; then \
sudo mv $(NIXOS_DIR) $(NIXOS_DIR).bak; \
echo "backed up /etc/nixos to /etc/nixos.bak"; \
fi
@sudo ln -sf $(REPO_DIR) $(NIXOS_DIR)
@echo "linked $(REPO_DIR) -> $(NIXOS_DIR)"
unlink:
@if [ -L "$(NIXOS_DIR)" ]; then \
sudo rm $(NIXOS_DIR); \
sudo mkdir -p $(NIXOS_DIR); \
echo "unlinked"; \
else \
echo "/etc/nixos is not a symlink"; \
fi
rebuild: rebuild:
sudo nixos-rebuild switch git add .
sudo nixos-rebuild switch --flake .#lavitz
update: update:
sudo nixos-rebuild switch --upgrade nix flake update
@$(MAKE) --no-print-directory rebuild
purge: purge:
sudo nix-collect-garbage -d sudo nix-collect-garbage -d
sudo /run/current-system/bin/switch-to-configuration boot sudo /run/current-system/bin/switch-to-configuration boot
check:
nix-instantiate '<nixpkgs/nixos>' -A system --dry-run
edit:
@$${EDITOR:-nano} $(SETTINGS)

View File

@@ -1,60 +1,65 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SETTINGS="settings.nix" set -e
REPO_DIR=$(pwd)
TARGET_DIR="$HOME/Development/lavitz"
NIXOS_DIR="/etc/nixos"
CURRENT_DIR=$(pwd)
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[0;33m' YELLOW='\033[0;33m'
RED='\033[0;31m' RED='\033[0;31m'
NC='\033[0m' # No Color NC='\033[0m'
# 1. Generate settings.nix echo -e "${GREEN}NixOS Configuration Setup${NC}"
if [ -f "$SETTINGS" ]; then
echo -e "${YELLOW}settings.nix exists. overwrite? [y/N]${NC}"
read -r confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
echo "keeping existing settings"
else
GENERATE=true
fi
else
GENERATE=true
fi
if [ "$GENERATE" = true ]; then
username=$(whoami)
userdesc=$(getent passwd "$username" | cut -d: -f5 | cut -d, -f1)
userdesc=${userdesc:-$username}
echo "user: $username ($userdesc)"
echo "" echo ""
echo "hostname:" if [ "$CURRENT_DIR" != "$TARGET_DIR" ]; then
read -r hostname echo -e "${YELLOW}Repository is not in $TARGET_DIR${NC}"
echo "timezone [America/Edmonton]:" if [ -d "$TARGET_DIR" ]; then
read -r tz echo -e "${RED}$TARGET_DIR already exists!${NC}"
tz=${tz:-America/Edmonton} echo "Please remove it or move this repo manually."
exit 1
echo "locale [en_CA.UTF-8]:"
read -r locale
locale=${locale:-en_CA.UTF-8}
echo ""
echo "{" > "$SETTINGS"
echo " hostname = \"$hostname\";" >> "$SETTINGS"
echo " username = \"$username\";" >> "$SETTINGS"
echo " userDescription = \"$userdesc\";" >> "$SETTINGS"
echo " timezone = \"$tz\";" >> "$SETTINGS"
echo " locale = \"$locale\";" >> "$SETTINGS"
echo " userGroups = [ \"networkmanager\" \"wheel\" \"docker\" \"plugdev\" ];" >> "$SETTINGS"
echo "}" >> "$SETTINGS"
echo "wrote $SETTINGS"
fi fi
# 2. Copy hardware-configuration.nix echo "Creating ~/Development directory..."
mkdir -p "$HOME/Development"
echo "Moving repository to $TARGET_DIR..."
mv "$CURRENT_DIR" "$TARGET_DIR"
echo -e "${GREEN}Repository moved to $TARGET_DIR${NC}"
echo ""
echo -e "${YELLOW}Please cd to $TARGET_DIR and run 'make init' again${NC}"
exit 0
fi
echo -e "${GREEN}Repository is in correct location: $TARGET_DIR${NC}"
echo ""
if [ -f "/etc/nixos/hardware-configuration.nix" ]; then if [ -f "/etc/nixos/hardware-configuration.nix" ]; then
cp /etc/nixos/hardware-configuration.nix "$REPO_DIR/hardware-configuration.nix" cp /etc/nixos/hardware-configuration.nix "$TARGET_DIR/hardware-configuration.nix"
echo "copied hardware-configuration.nix" echo -e "${GREEN}Copied hardware-configuration.nix${NC}"
else else
echo -e "${YELLOW}no hardware-configuration.nix found - run nixos-generate-config first${NC}" echo -e "${YELLOW}No hardware-configuration.nix found${NC}"
echo "Run 'sudo nixos-generate-config' first if this is a fresh install"
fi fi
if [ -L "$NIXOS_DIR" ]; then
echo -e "${YELLOW}/etc/nixos is already a symlink${NC}"
sudo rm "$NIXOS_DIR"
elif [ -d "$NIXOS_DIR" ]; then
echo -e "${YELLOW}Backing up existing /etc/nixos to /etc/nixos.bak${NC}"
sudo mv "$NIXOS_DIR" "${NIXOS_DIR}.bak"
fi
echo "Creating symlink: $TARGET_DIR -> $NIXOS_DIR"
sudo ln -sf "$TARGET_DIR" "$NIXOS_DIR"
echo ""
echo -e "${GREEN}Setup complete!${NC}"
echo ""
echo "Next steps:"
echo " 1. Ensure hardware-configuration.nix exists in $TARGET_DIR"
echo " 2. Run 'git add .' to track files (required for flakes)"
echo " 3. Run 'sudo nixos-rebuild switch --flake .#lavitz'"