75 lines
2.2 KiB
Makefile
75 lines
2.2 KiB
Makefile
export MAKEFLAGS :=
|
|
|
|
HOST ?= $(shell hostname)
|
|
HOME_MANAGER_FLAGS ?=
|
|
|
|
define nix-run
|
|
@echo "$(1) $(2)"
|
|
@if hash $(1) 2>/dev/null; then $(1) $(2); else nix-shell -p $(1) --run "$(1) $(2)"; fi
|
|
endef
|
|
|
|
all:
|
|
@echo 'no default action, available actions:'
|
|
@for n in format lint build build-all deploy deploy-full deploy-standalone \
|
|
upload-secrets upload-secrets-all setup-git-hooks; do echo " - $$n"; done
|
|
@echo
|
|
@exit 1
|
|
|
|
format:
|
|
$(call nix-run,nixfmt,$(shell find . -type f -name '*.nix'))
|
|
$(call nix-run,stylua,--verify .)
|
|
|
|
lint:
|
|
$(call nix-run,deadnix,--fail)
|
|
$(call nix-run,statix,check)
|
|
$(call nix-run,stylua,--check .)
|
|
$(call nix-run,nixfmt,--check $(shell find . -type f -name '*.nix'))
|
|
$(call nix-run,shellcheck,--shell bash extra/bin/*.sh)
|
|
f() { \
|
|
local result=0; \
|
|
for h in $$(git log --format=%h | tac); do \
|
|
if ! git verify-commit $$h 2>/dev/null; then \
|
|
echo "[!] found unsigned commit: $$h"; \
|
|
result=1; \
|
|
fi; \
|
|
done; \
|
|
exit $$result; \
|
|
}; f
|
|
|
|
build:
|
|
@if [ -z "$(M)" ]; then echo 'no machine specified using M=' 2>&1; exit 1; fi
|
|
$(call nix-run,morph,build --on '$(M)' ./default.nix)
|
|
|
|
build-all:
|
|
$(MAKE) build M="{fort,name,serv,trek,zero}"
|
|
|
|
deploy:
|
|
@if [ -z "$(M)" ]; then echo 'no machine specified using M=' 2>&1; exit 1; fi
|
|
$(call nix-run,morph,deploy --passwd --on '$(M)' ./default.nix switch)
|
|
|
|
deploy-full:
|
|
@if [ -z "$(M)" ]; then echo 'no machine specified using M=' 2>&1; exit 1; fi
|
|
$(call nix-run,morph,deploy --passwd --upload-secrets --on '$(M)' ./default.nix switch)
|
|
|
|
deploy-standalone:
|
|
@if [ ! -f ./system/home-manager/standalone/$(HOST)/flake.nix ]; then \
|
|
echo 'no standalone configuration for this machine found: $(HOST)' 2>&1; \
|
|
exit 1; \
|
|
fi
|
|
$(call nix-run,home-manager,\
|
|
--flake ./system/home-manager/standalone/$(HOST) $(HOME_MANAGER_FLAGS) switch)
|
|
|
|
upload-secrets:
|
|
@if [ -z "$(M)" ]; then echo 'no machine specified using M=' 2>&1; exit 1; fi
|
|
$(call nix-run,morph,upload-secrets --passwd --on '$(M)' ./default.nix)
|
|
|
|
upload-secrets-all:
|
|
$(call nix-run,morph,upload-secrets --passwd ./default.nix)
|
|
|
|
setup-git-hooks:
|
|
echo -e '#!/usr/bin/env sh\nexec make lint' >.git/hooks/pre-commit
|
|
chmod +x .git/hooks/pre-commit
|
|
|
|
empty-out-secrets:
|
|
for f in $$(find secrets -type f -name '*.nix'); do echo '{ }' > $$f; done
|