NixOS-Configs/justfile
2024-11-05 19:41:50 -06:00

93 lines
2.8 KiB
Makefile

HOSTNAME := `hostname -s`
# Do as test build without installing
test:
alejandra . &> nixos-switch.log || ( cat nixos-switch.log && false)
colmena build --on {{HOSTNAME}}
# Apply config on hostname
switch hostname=(HOSTNAME):
set -x
set +x
colmena exec --on {{hostname}} "locate home-manager-backup | sort -u | xargs rm -f"
colmena apply --on {{HOSTNAME}}
# Build and install the world!
world:
colmena exec "locate home-manager-backup | sort -u | xargs rm -f"
colmena apply
# Build and install the workstations
workstation:
colmena exec --on @workstation "locate home-manager-backup | sort -u | xargs rm -f"
colmena apply --on @workstation
# Build and install the servers
server:
colmena exec --on @server "locate home-manager-backup | sort -u | xargs rm -f"
colmena apply --on @server
# Build and install the webhosts
web:
colmena exec --on @web "locate home-manager-backup | sort -u | xargs rm -f"
colmena apply --on @web
# Build and run a vm FIXME
vm:
alejandra . &> nixos-switch.log || ( cat nixos-switch.log && false)
rm -f nixos-switch.log
echo Running iso build
nix build --impure ./#nixosConfigurations.vm.config.system.build.isoImage &> nixos-switch.log || ( grep -E --color '(error|For full logs)' nixos-switch.log && false)
# Stuff to do weekly
weekly: pull clean update world ci push clean-world
# Update flake.lock
update:
echo "Updating flake.lock"
nix flake update &> nixos-switch.log || ( cat nixos-switch.log && false)
rm -f nixos-switch.log
# Clean up
clean hostname=(HOSTNAME):
echo "Cleaning old entries and store"
home-manager expire-generations "-5 days"
echo "Garbage Collection"
colmena exec --on {{hostname}} nix-collect-garbage --quiet --log-format bar --no-build-output --delete-old
echo "Store optimise"
colmena exec --on {{hostname}} nix store optimise
# Clean up the world
clean-world:
echo "Cleaning old entries and store"
colmena exec 'home-manager expire-generations "-5 days"'
echo "Garbage Collection"
colmena exec 'nix-collect-garbage --quiet --log-format bar --no-build-output --delete-old'
echo "Store optimise"
colmena exec 'nix store optimise'
# Push local changes to git
push:
echo pushing to git
git push
# Pull changes from git
pull:
echo Updating from git repo
git pull &> nixos-switch.log || ( cat nixos-switch.log && false)
rm -f nixos-switch.log
doas nix-prefetch-url file://`pwd`/`ls -1 src/linuxx64* | tail -n1` &> nixos-switch.log || ( cat nixos-switch.log && false)
rm -f nixos-switch.log
# doas nix-prefetch-url file://`pwd`/`ls -1 src/linuxarm64* | tail -n1` &> nixos-switch.log || ( cat nixos-switch.log && false)
# rm -f nixos-switch.log
# Add everything to git
ci:
echo "git commit"
git commit -m"chore | Update flake.lock" flake.lock &> nixos-switch.log || ( cat nixos-switch.log && false)
rm -f nixos-switch.log
# Reboot this host
reboot:
doas reboot