stockholm/Makefile

108 lines
2.1 KiB
Makefile
Raw Normal View History

2015-07-19 09:50:54 +00:00
#
# usage:
# make system=foo
# make systems='foo bar'
2015-07-22 23:04:51 +00:00
# make eval system=foo get=config.networking.extraHosts
2015-07-19 09:50:54 +00:00
#
2015-07-11 14:55:22 +00:00
.ONESHELL:
.SHELLFLAGS := -eufc
2015-07-19 09:50:54 +00:00
ifdef systems
$(systems):
parallel \
--line-buffer \
-j0 \
--no-notice \
--tagstring {} \
-q make systems= system={} ::: $(systems)
else ifdef system
include 0make/$(LOGNAME)/$(system).makefile
2015-07-11 14:55:22 +00:00
.PHONY: deploy
deploy:;@
system_name=$(system)
deploy_host=$(deploy_host)
nixpkgs_url=$(nixpkgs_url)
nixpkgs_rev=$(nixpkgs_rev)
secrets_dir=$(secrets_dir)
prepush(){(
dst=$$1
src=$$2
rsync \
--exclude .git \
--exclude .graveyard \
--exclude old \
2015-07-11 14:55:22 +00:00
--rsync-path="mkdir -p \"$$dst\" && rsync" \
--usermap=\*:0 \
--groupmap=\*:0 \
--delete-excluded \
-vrLptgoD \
"$$src/" "$$deploy_host:$$dst"
)}
2015-07-24 15:34:08 +00:00
prepush /root/src/stockholm "$$PWD"
2015-07-11 14:55:22 +00:00
prepush /root/src/secrets "$$secrets_dir"
ssh -S none "$$deploy_host" -T env \
nixpkgs_url="$$nixpkgs_url" \
nixpkgs_rev="$$nixpkgs_rev" \
system_name="$$system_name" \
2015-07-24 15:34:08 +00:00
user_name="$$LOGNAME" \
2015-07-11 14:55:22 +00:00
sh -euf \
<<-\EOF
prefetch(){(
dst=$$1
url=$$2
rev=$$3
mkdir -p "$$dst"
cd "$$dst"
if ! test -e .git; then
git init
fi
if ! cur_url=$$(git config remote.origin.url 2>/dev/null); then
git remote add origin "$$url"
elif test "$$cur_url" != "$$url"; then
git remote set-url origin "$$url"
fi
if test "$$(git rev-parse --verify HEAD 2>/dev/null)" != "$$rev"; then
git fetch origin
git checkout "$$rev" -- .
git checkout -q "$$rev"
git submodule init
git submodule update
fi
git clean -dxf
)}
prefetch /root/src/nixpkgs "$$nixpkgs_url" "$$nixpkgs_rev"
echo build system...
2015-07-24 15:34:08 +00:00
NIX_PATH=/root/src \
nix-build \
-Q \
-A system \
'<stockholm>' \
--argstr user-name "$$user_name" \
--argstr system-name "$$system_name"
2015-07-11 14:55:22 +00:00
result/bin/switch-to-configuration switch
EOF
2015-07-22 23:04:51 +00:00
.PHONY: eval
eval:
2015-07-24 15:34:08 +00:00
@
NIX_PATH=stockholm=$$PWD:$$NIX_PATH \
nix-instantiate \
2015-07-22 23:04:51 +00:00
--json \
--eval \
--strict \
-A "$$get" \
2015-07-24 15:34:08 +00:00
'<stockholm>' \
--argstr user-name "$$LOGNAME" \
--argstr system-name "$$system" \
| jq -r .
2015-07-19 09:50:54 +00:00
else
$(error unbound variable: system[s])
2015-07-11 14:55:22 +00:00
endif