summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile108
1 files changed, 36 insertions, 72 deletions
diff --git a/Makefile b/Makefile
index a1559b48c..87a636e72 100644
--- a/Makefile
+++ b/Makefile
@@ -1,87 +1,51 @@
-#
-# usage:
-# make infest system=foo [target=bar]
-# make [deploy] system=foo [target=bar]
-# make [deploy] systems='foo bar'
-# make eval get=users.tv.wu.config.time.timeZone [filter=json]
-#
-
.ONESHELL:
.SHELLFLAGS := -eufc
-ifdef systems
-$(systems):
- @
- unset target
- parallel \
- --line-buffer \
- -j0 \
- --no-notice \
- --tagstring {} \
- -q make -s systems= system={} ::: $(systems)
-else ifdef system
-.PHONY: deploy infest
-deploy infest:;@
- export get=krebs.$@
- export filter=json
- script=$$(make -s eval)
- echo "$$script" | sh
-
-.PHONY: eval
-eval:
- @
-ifeq ($(filter),json)
- extraArgs='--json --strict'
- filter() { jq -r .; }
-else
- filter() { cat; }
+ifndef system
+$(error unbound variable: system)
endif
- result=$$(nix-instantiate \
- $${extraArgs-} \
- --eval \
- -A "$$get" \
- -I stockholm="$$PWD" \
- '<stockholm>' \
- --argstr current-host-name "$$HOSTNAME" \
- --argstr current-user-name "$$LOGNAME" \
- $${system+--argstr system "$$system"} \
- $${target+--argstr target "$$target"})
- echo "$$result" | filter
export target_host ?= $(system)
export target_user ?= root
export target_path ?= /var/src
+# usage: make deploy system=foo [target_host=bar]
+.PHONY: deploy
+deploy: populate ;@set -x
+ ssh "$$target_user@$$target_host" nixos-rebuild switch -I "$$target_path"
+
# usage: make populate system=foo [target_host=bar]
.PHONY: populate
-populate: export lib = \
- let nlib = import <nixpkgs/lib>; in \
- nlib // import krebs/4lib { lib = nlib; } // builtins
-populate: export source = \
- with builtins; \
- with (import ./. {}).users.$${getEnv "LOGNAME"}.$${getEnv "system"}; \
- assert config.krebs.build.source-version == 2; \
- config.krebs.build.source
populate:;@
- result=$$(nix-instantiate \
- --eval \
- --json \
- --arg lib "$$lib" \
- --arg source "$$source" \
- --argstr target-user "$$target_user" \
- --argstr target-host "$$target_host" \
- --argstr target-path "$$target_path" \
- -A populate \
- krebs/v2)
- script=$$(echo "$$result" | jq -r .)
- echo "$$script" | sh
-
-# usage: make rebuild system=foo [target_host=bar] [operation=switch]
-.PHONY: rebuild
-rebuild: populate ;@set -x
- ssh "$$target_user@$$target_host" \
- nixos-rebuild "$${operation-switch}" -I "$$target_path"
+ result=$$(make -s eval get=config.krebs.build.populate filter=json)
+ echo "$$result" | sh
+# usage: make eval system=foo get=config.krebs.build [LOGNAME=tv] [filter=json]
+.PHONY: eval
+eval:;@
+ifeq ($(filter),json)
+ extraArgs='--json --strict'
+ filter() { echo "$$1" | jq -r .; }
else
-$(error unbound variable: system[s])
+ filter() { echo "$$1"; }
endif
+ result=$$(nix-instantiate \
+ $${extraArgs-} \
+ --show-trace \
+ --readonly-mode \
+ --eval \
+ -A "$$get" \
+ --arg configuration "<stockholm/$$LOGNAME/1systems/$$system.nix>")
+ filter "$$result"
+
+## usage: make install system=foo target=
+#.PHONY: install
+#install: ssh = ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
+#install:;@set -x
+# $(ssh) "$$target_user@$$target_host" \
+# env target_path=/var/src \
+# sh -s prepare < krebs/4lib/infest/prepare.sh
+# make -s populate target_path=/mnt"$$target_path"
+# $(ssh) "$$target_user@$$target_host" \
+# env NIXOS_CONFIG=/var/src/nixos-config \
+# nixos-install