New Nix config

This commit is contained in:
2025-12-16 14:55:04 -07:00
parent b475d40718
commit 10233a29ca
15 changed files with 152 additions and 93 deletions

99
Makefile Normal file
View File

@@ -0,0 +1,99 @@
.PHONY: init install link unlink rebuild update purge edit help
NIXOS_DIR := /etc/nixos
REPO_DIR := $(shell pwd)
SETTINGS := settings.nix
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
help:
@echo "NixOS Config"
@echo ""
@echo " make init - first time setup"
@echo " make rebuild - rebuild nixos"
@echo " make update - upgrade + rebuild"
@echo " make purge - garbage collect"
@echo " make link - symlink to /etc/nixos"
@echo " make unlink - remove symlink"
@echo " make edit - edit settings.nix"
init:
@if [ -f "$(SETTINGS)" ]; then \
echo "$(YELLOW)settings.nix exists. overwrite? [y/N]$(NC)"; \
read -r confirm; \
if [ "$$confirm" != "y" ] && [ "$$confirm" != "Y" ]; then \
echo "keeping existing settings"; \
exit 0; \
fi; \
fi
@username=$$(whoami); \
userdesc=$$(getent passwd $$username | cut -d: -f5 | cut -d, -f1); \
userdesc=$${userdesc:-$$username}; \
echo "user: $$username ($$userdesc)"; \
echo ""; \
echo "hostname:"; \
read -r hostname; \
echo "timezone [America/Edmonton]:"; \
read -r tz; \
tz=$${tz:-America/Edmonton}; \
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.nix"
@if [ -f "/etc/nixos/hardware-configuration.nix" ]; then \
cp /etc/nixos/hardware-configuration.nix $(REPO_DIR)/hardware-configuration.nix; \
echo "copied hardware-configuration.nix"; \
else \
echo "$(YELLOW)no hardware-configuration.nix found - run nixos-generate-config first$(NC)"; \
fi
@$(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:
sudo nixos-rebuild switch
update:
sudo nixos-rebuild switch --upgrade
purge:
sudo nix-collect-garbage -d
sudo /run/current-system/bin/switch-to-configuration boot
check:
nix-instantiate '<nixpkgs/nixos>' -A system --dry-run
edit:
@$${EDITOR:-nano} $(SETTINGS)