2015-07-19 09:50:54 +00:00
|
|
|
#
|
|
|
|
# usage:
|
2015-09-30 23:48:15 +00:00
|
|
|
# make infest system=foo [target=bar]
|
|
|
|
# make [deploy] system=foo [target=bar]
|
|
|
|
# make [deploy] systems='foo bar'
|
2015-10-19 19:20:38 +00:00
|
|
|
# make eval get=users.tv.wu.config.time.timeZone [filter=json]
|
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):
|
2015-09-26 22:22:50 +00:00
|
|
|
@
|
2015-09-30 23:48:15 +00:00
|
|
|
unset target
|
2015-07-19 09:50:54 +00:00
|
|
|
parallel \
|
|
|
|
--line-buffer \
|
|
|
|
-j0 \
|
|
|
|
--no-notice \
|
|
|
|
--tagstring {} \
|
2015-09-26 22:22:50 +00:00
|
|
|
-q make -s systems= system={} ::: $(systems)
|
2015-07-19 09:50:54 +00:00
|
|
|
else ifdef system
|
2015-09-26 22:22:50 +00:00
|
|
|
.PHONY: deploy infest
|
|
|
|
deploy infest:;@
|
2015-09-30 23:48:15 +00:00
|
|
|
export get=krebs.$@
|
2015-09-26 22:22:50 +00:00
|
|
|
export filter=json
|
2016-02-01 02:08:54 +00:00
|
|
|
script=$$(make -s eval)
|
|
|
|
echo "$$script" | sh
|
2015-09-18 01:04:39 +00:00
|
|
|
|
2015-07-22 23:04:51 +00:00
|
|
|
.PHONY: eval
|
|
|
|
eval:
|
2015-07-24 15:34:08 +00:00
|
|
|
@
|
2015-07-28 19:03:49 +00:00
|
|
|
ifeq ($(filter),json)
|
2015-08-05 13:24:50 +00:00
|
|
|
extraArgs='--json --strict'
|
2015-07-28 19:03:49 +00:00
|
|
|
filter() { jq -r .; }
|
|
|
|
else
|
|
|
|
filter() { cat; }
|
|
|
|
endif
|
2015-12-22 19:31:21 +00:00
|
|
|
result=$$(nix-instantiate \
|
2015-07-28 19:03:49 +00:00
|
|
|
$${extraArgs-} \
|
2015-07-22 23:04:51 +00:00
|
|
|
--eval \
|
|
|
|
-A "$$get" \
|
2015-10-15 00:48:11 +00:00
|
|
|
-I stockholm="$$PWD" \
|
2015-07-24 15:34:08 +00:00
|
|
|
'<stockholm>' \
|
2015-09-30 23:48:15 +00:00
|
|
|
--argstr current-date "$$(date -Is)" \
|
|
|
|
--argstr current-host-name "$$HOSTNAME" \
|
|
|
|
--argstr current-user-name "$$LOGNAME" \
|
|
|
|
$${system+--argstr system "$$system"} \
|
2015-12-22 19:31:21 +00:00
|
|
|
$${target+--argstr target "$$target"})
|
|
|
|
echo "$$result" | filter
|
|
|
|
|
2016-02-02 02:51:22 +00:00
|
|
|
export target_host ?= $(system)
|
|
|
|
export target_user ?= root
|
|
|
|
export target_path ?= /var/src
|
2016-02-02 02:19:20 +00:00
|
|
|
|
2016-02-02 02:51:22 +00:00
|
|
|
# usage: make populate system=foo [target_host=bar]
|
2016-02-02 02:19:20 +00:00
|
|
|
.PHONY: populate
|
2016-02-02 02:29:42 +00:00
|
|
|
populate: export lib = \
|
|
|
|
let nlib = import <nixpkgs/lib>; in \
|
|
|
|
nlib // import krebs/4lib { lib = nlib; } // builtins
|
2016-02-02 02:19:20 +00:00
|
|
|
populate: export source = \
|
2016-02-02 02:51:22 +00:00
|
|
|
with builtins; \
|
|
|
|
with (import ./. {}).users.$${getEnv "LOGNAME"}.$${getEnv "system"}; \
|
|
|
|
assert config.krebs.build.source-version == 2; \
|
|
|
|
config.krebs.build.source
|
2016-02-02 02:19:20 +00:00
|
|
|
populate:;@
|
|
|
|
result=$$(nix-instantiate \
|
|
|
|
--eval \
|
|
|
|
--json \
|
2016-02-02 02:29:42 +00:00
|
|
|
--arg lib "$$lib" \
|
2016-02-02 02:19:20 +00:00
|
|
|
--arg source "$$source" \
|
2016-02-02 02:51:22 +00:00
|
|
|
--argstr target-user "$$target_user" \
|
|
|
|
--argstr target-host "$$target_host" \
|
|
|
|
--argstr target-path "$$target_path" \
|
2016-02-02 02:19:20 +00:00
|
|
|
-A populate \
|
|
|
|
krebs/v2)
|
|
|
|
script=$$(echo "$$result" | jq -r .)
|
|
|
|
echo "$$script" | sh
|
|
|
|
|
2016-02-02 02:51:22 +00:00
|
|
|
# usage: make rebuild system=foo [target_host=bar] [operation=switch]
|
2016-02-02 02:19:20 +00:00
|
|
|
.PHONY: rebuild
|
2016-02-02 02:20:29 +00:00
|
|
|
rebuild: populate ;@set -x
|
2016-02-02 02:51:22 +00:00
|
|
|
ssh "$$target_user@$$target_host" \
|
|
|
|
nixos-rebuild "$${operation-switch}" -I "$$target_path"
|
2016-02-02 02:19:20 +00:00
|
|
|
|
2015-07-19 09:50:54 +00:00
|
|
|
else
|
|
|
|
$(error unbound variable: system[s])
|
2015-07-11 14:55:22 +00:00
|
|
|
endif
|