2016-02-16 07:31:37 +01:00
|
|
|
stockholm ?= .
|
|
|
|
|
2016-03-10 12:32:29 +01:00
|
|
|
export HOSTNAME ?= $(shell cat /proc/sys/kernel/hostname)
|
|
|
|
|
2016-03-05 12:40:20 +01:00
|
|
|
export STOCKHOLM_VERSION ?= $(shell \
|
|
|
|
version=git.$$(git describe --always --dirty); \
|
2016-03-10 12:32:29 +01:00
|
|
|
case $$version in (*-dirty) version=$$version@$$HOSTNAME; esac; \
|
2016-03-05 12:40:20 +01:00
|
|
|
date=$$(date +%y.%m); \
|
|
|
|
printf '%s' "$$date.$$version"; \
|
|
|
|
)
|
|
|
|
|
2016-05-20 03:21:56 +02:00
|
|
|
system ?= $(HOSTNAME)
|
2016-02-16 07:31:37 +01:00
|
|
|
$(if $(system),,$(error unbound variable: system))
|
2016-03-10 12:41:24 +01:00
|
|
|
|
2017-07-06 21:47:47 +02:00
|
|
|
nixos-config ?= $(stockholm)/$(LOGNAME)/1systems/$(system)/config.nix
|
2016-06-13 17:27:46 +02:00
|
|
|
ifneq ($(words $(wildcard $(nixos-config))),1)
|
|
|
|
$(error bad nixos-config: $(nixos-config))
|
|
|
|
endif
|
2015-12-22 20:31:21 +01:00
|
|
|
|
2016-02-16 06:20:40 +01:00
|
|
|
# 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
|
|
|
|
|
2016-07-17 02:58:20 +02:00
|
|
|
target_host ?= $(system)
|
|
|
|
target_user ?= root
|
|
|
|
target_port ?= 22
|
|
|
|
target_path ?= /var/src
|
2016-02-02 03:19:20 +01:00
|
|
|
|
2016-02-16 07:31:37 +01:00
|
|
|
$(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))
|
|
|
|
|
2017-06-27 23:28:41 +02:00
|
|
|
whatsupnix = \
|
|
|
|
if type whatsupnix >/dev/null 2>&1; then \
|
|
|
|
whatsupnix $(1); \
|
|
|
|
else \
|
|
|
|
cat; \
|
|
|
|
fi
|
|
|
|
|
2016-06-05 00:25:47 +02:00
|
|
|
build = \
|
|
|
|
nix-build \
|
2017-06-27 23:28:41 +02:00
|
|
|
-Q \
|
2016-06-05 00:25:47 +02:00
|
|
|
--no-out-link \
|
|
|
|
--show-trace \
|
|
|
|
-I nixos-config=$(nixos-config) \
|
|
|
|
-I stockholm=$(stockholm) \
|
2017-06-27 23:28:41 +02:00
|
|
|
-E "with import <stockholm>; $(1)" \
|
|
|
|
$(2) \
|
|
|
|
|& $(call whatsupnix)
|
2016-06-05 00:25:47 +02:00
|
|
|
|
2016-02-04 11:32:13 +01:00
|
|
|
evaluate = \
|
|
|
|
nix-instantiate \
|
|
|
|
--eval \
|
|
|
|
--readonly-mode \
|
|
|
|
--show-trace \
|
2016-02-16 07:31:37 +01:00
|
|
|
-I nixos-config=$(nixos-config) \
|
|
|
|
-I stockholm=$(stockholm) \
|
2017-06-27 23:29:43 +02:00
|
|
|
-E "let eval = import <stockholm>; in with eval; $(1)" \
|
|
|
|
$(2)
|
2016-02-04 11:32:13 +01:00
|
|
|
|
2016-05-20 02:52:23 +02:00
|
|
|
ifeq ($(MAKECMDGOALS),)
|
|
|
|
$(error No goals specified)
|
|
|
|
endif
|
|
|
|
|
2017-07-12 23:22:15 +02:00
|
|
|
# usage: make deploy system=foo [target=bar]
|
2017-07-23 22:48:58 +02:00
|
|
|
# usage: make install system=foo target=bar
|
2017-07-12 23:22:15 +02:00
|
|
|
# usage: make test system=foo target=bar
|
2017-07-23 22:48:58 +02:00
|
|
|
deploy install test:
|
2017-07-12 23:22:15 +02:00
|
|
|
ifdef target
|
|
|
|
nix-shell --run '$@ --system=$(system) --target=$(target)'
|
2016-07-17 02:58:20 +02:00
|
|
|
else
|
2017-07-12 23:22:15 +02:00
|
|
|
nix-shell --run '$@ --system=$(system)'
|
2016-07-17 02:58:20 +02:00
|
|
|
endif
|
2016-02-04 05:40:26 +01:00
|
|
|
|
2016-07-16 21:43:38 +02:00
|
|
|
# usage: make populate system=foo
|
2016-10-03 15:21:31 +02:00
|
|
|
populate: populate-target = \
|
|
|
|
$(target_user)@$(target_host):$(target_port)$(target_path)
|
2016-07-16 21:43:38 +02:00
|
|
|
ifeq ($(debug),true)
|
2016-07-17 02:37:46 +02:00
|
|
|
populate: populate-flags += --debug
|
2016-07-16 21:43:38 +02:00
|
|
|
endif
|
2016-07-17 01:30:11 +02:00
|
|
|
ifneq ($(ssh),)
|
|
|
|
populate: populate-flags += --ssh=$(ssh)
|
|
|
|
endif
|
2016-07-16 21:43:38 +02:00
|
|
|
populate:
|
2017-07-23 02:01:35 +02:00
|
|
|
nix-shell --run 'get-source $(LOGNAME)/1systems/$(system)/source.nix' \
|
2016-10-03 15:21:31 +02:00
|
|
|
populate $(populate-target) $(populate-flags)
|
2016-07-16 21:43:38 +02:00
|
|
|
|
2016-07-17 00:52:21 +02:00
|
|
|
# usage: make pkgs.populate
|
|
|
|
pkgs:;@$(error no package selected)
|
|
|
|
pkgs.%:;@$(call build,$@)
|
2016-06-05 00:25:47 +02:00
|
|
|
|
2017-07-14 00:17:58 +02:00
|
|
|
# usage: make LOGNAME=krebs system=wolf eval.config.krebs.build.host.name
|
2016-02-19 16:15:14 +01:00
|
|
|
eval eval.:;@$(call evaluate,$${expr-eval})
|
2016-05-20 03:02:35 +02:00
|
|
|
eval.%:;@$(call evaluate,$@)
|