From 4fb829af7e5e9cb2837a052f34d789faf9f3cda9 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 06:20:40 +0100 Subject: Makefile: parse target --- Makefile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 384c872ab..a73a1aaf4 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,30 @@ ifndef system $(error unbound variable: system) 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) export target_user ?= root export target_port ?= 22 -- cgit v1.2.3 From 439f913348f6135e0fd99d4e580a67a602bd72df Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 07:31:37 +0100 Subject: Makefile: make nixos-config configurable --- Makefile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index a73a1aaf4..e1889fc17 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ -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] @@ -31,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 = \ -- cgit v1.2.3 From 18ac722ee6d85ba0d01f8cd3d04bca5b59843af8 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 07:41:26 +0100 Subject: make test using nix-build --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e1889fc17..7126332da 100644 --- a/Makefile +++ b/Makefile @@ -73,3 +73,10 @@ 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] +test: + $(call execute,populate) + ssh $(target_user)@$(target_host) -p $(target_port) \ + nix-build --no-out-link --show-trace -I $(target_path) \ + -A config.system.build.toplevel $(target_path)/stockholm -- cgit v1.2.3 From e8ccf0e4da1320dda3b7baca8f585f633726c755 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 08:24:08 +0100 Subject: make {deploy,test}: make ssh configurable --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 7126332da..8d1498d59 100644 --- a/Makefile +++ b/Makefile @@ -54,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 @@ -75,8 +76,9 @@ install: nixos-install # usage: make test system=foo [target=bar] +test: ssh ?= ssh test: $(call execute,populate) - ssh $(target_user)@$(target_host) -p $(target_port) \ + $(ssh) $(target_user)@$(target_host) -p $(target_port) \ nix-build --no-out-link --show-trace -I $(target_path) \ -A config.system.build.toplevel $(target_path)/stockholm -- cgit v1.2.3 From d923ede6e33c57901039da59d50c45938228fd7a Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 16 Feb 2016 12:49:04 +0100 Subject: make test [method={build,eval}] # default=eval --- Makefile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 8d1498d59..60dfe8030 100644 --- a/Makefile +++ b/Makefile @@ -75,10 +75,20 @@ install: env NIXOS_CONFIG=$(target_path)/nixos-config \ nixos-install -# usage: make test system=foo [target=bar] +# 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) \ - nix-build --no-out-link --show-trace -I $(target_path) \ + $(command) --show-trace -I $(target_path) \ -A config.system.build.toplevel $(target_path)/stockholm -- cgit v1.2.3 From 8c264139b294cbbea27a042263a4b76991910f02 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 18 Feb 2016 01:15:58 +0100 Subject: krebs.build: use $F5 to prefix verbose commands --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 60dfe8030..9dcd47548 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ evaluate = \ execute = \ result=$$($(call evaluate,-A config.krebs.build.$(1) --json)) && \ script=$$(echo "$$result" | jq -r .) && \ - echo "$$script" | sh + echo "$$script" | PS5=% sh # usage: make deploy system=foo [target_host=bar] deploy: ssh ?= ssh -- cgit v1.2.3 From c040c8f1b5fcfbd1b784c9460f4a0b78091ff2db Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 19 Feb 2016 16:15:14 +0100 Subject: make: allow evaluation of arbitrary expressions --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9dcd47548..12a60a90b 100644 --- a/Makefile +++ b/Makefile @@ -46,10 +46,12 @@ evaluate = \ --show-trace \ -I nixos-config=$(nixos-config) \ -I stockholm=$(stockholm) \ - $(1) + -E '{ eval, f }: f eval' \ + --arg eval 'import ./.' \ + --arg f "eval@{ config, ... }: $(1)" execute = \ - result=$$($(call evaluate,-A config.krebs.build.$(1) --json)) && \ + result=$$($(call evaluate,config.krebs.build.$(1))) && \ script=$$(echo "$$result" | jq -r .) && \ echo "$$script" | PS5=% sh @@ -61,8 +63,8 @@ deploy: nixos-rebuild switch --show-trace -I $(target_path) # usage: make LOGNAME=shared system=wolf eval.config.krebs.build.host.name -eval eval.:;@$(call evaluate) -eval.%:;@$(call evaluate,-A $*) +eval eval.:;@$(call evaluate,$${expr-eval}) +eval.%:;@$(call evaluate,$*) # usage: make install system=foo [target_host=bar] install: ssh ?= ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -- cgit v1.2.3