summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2016-02-17 15:02:45 +0100
committerlassulus <lass@aidsballs.de>2016-02-17 15:02:45 +0100
commitf48e90915f9c1477a7068050e06a8686ceb03427 (patch)
tree7f3cb5987b2f962fa7f93ffab0c8d47267f70764 /Makefile
parent5c8606e6f6b9337d6f9c1241bf0af84af9db0bdf (diff)
parentd923ede6e33c57901039da59d50c45938228fd7a (diff)
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile61
1 files changed, 56 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 384c872ab..60dfe8030 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,32 @@
-ifndef system
-$(error unbound variable: system)
+stockholm ?= .
+
+ifndef nixos-config
+$(if $(system),,$(error unbound variable: system))
+nixos-config = ./$(LOGNAME)/1systems/$(system).nix
+endif
+
+# target = [target_user@]target_host[:target_port][/target_path]
+ifdef target
+_target_user != echo $(target) | sed -n 's/@.*//p'
+_target_path != echo $(target) | sed -n 's/^[^/]*//p'
+_target_port != echo $(target) | sed -En 's|^.*:([^/]*)(/.*)?$$|\1|p'
+_target_host != echo $(target) | sed -En 's/^(.*@)?([^:/]*).*/\2/p'
+ifneq ($(_target_host),)
+$(if $(target_host),$(error cannot define both, target_host and host in target))
+target_host ?= $(_target_host)
+endif
+ifneq ($(_target_user),)
+$(if $(target_user),$(error cannot define both, target_user and user in target))
+target_user ?= $(_target_user)
+endif
+ifneq ($(_target_port),)
+$(if $(target_port),$(error cannot define both, target_port and port in target))
+target_port ?= $(_target_port)
+endif
+ifneq ($(_target_path),)
+$(if $(target_path),$(error cannot define both, target_path and path in target))
+target_path ?= $(_target_path)
+endif
endif
export target_host ?= $(system)
@@ -7,13 +34,18 @@ export target_user ?= root
export target_port ?= 22
export target_path ?= /var/src
+$(if $(target_host),,$(error unbound variable: target_host))
+$(if $(target_user),,$(error unbound variable: target_user))
+$(if $(target_port),,$(error unbound variable: target_port))
+$(if $(target_path),,$(error unbound variable: target_path))
+
evaluate = \
nix-instantiate \
--eval \
--readonly-mode \
--show-trace \
- -I nixos-config=./$(LOGNAME)/1systems/$(system).nix \
- -I stockholm=. \
+ -I nixos-config=$(nixos-config) \
+ -I stockholm=$(stockholm) \
$(1)
execute = \
@@ -22,9 +54,10 @@ execute = \
echo "$$script" | sh
# usage: make deploy system=foo [target_host=bar]
+deploy: ssh ?= ssh
deploy:
$(call execute,populate)
- ssh $(target_user)@$(target_host) -p $(target_port) \
+ $(ssh) $(target_user)@$(target_host) -p $(target_port) \
nixos-rebuild switch --show-trace -I $(target_path)
# usage: make LOGNAME=shared system=wolf eval.config.krebs.build.host.name
@@ -41,3 +74,21 @@ install:
$(ssh) $(target_user)@$(target_host) -p $(target_port) \
env NIXOS_CONFIG=$(target_path)/nixos-config \
nixos-install
+
+# usage: make test system=foo [target=bar] [method={eval,build}]
+method ?= eval
+ifeq ($(method),build)
+test: command = nix-build --no-out-link
+else
+ifeq ($(method),eval)
+test: command ?= nix-instantiate --eval --json --readonly-mode --strict
+else
+$(error bad method: $(method))
+endif
+endif
+test: ssh ?= ssh
+test:
+ $(call execute,populate)
+ $(ssh) $(target_user)@$(target_host) -p $(target_port) \
+ $(command) --show-trace -I $(target_path) \
+ -A config.system.build.toplevel $(target_path)/stockholm