aboutsummaryrefslogtreecommitdiff
path: root/nixops/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'nixops/Makefile')
-rw-r--r--nixops/Makefile117
1 files changed, 92 insertions, 25 deletions
diff --git a/nixops/Makefile b/nixops/Makefile
index cce57ff..69603a0 100644
--- a/nixops/Makefile
+++ b/nixops/Makefile
@@ -1,54 +1,121 @@
1export
2ifndef NIXOPS_CONFIG_PASS_SUBTREE_PATH
3 $(error Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path)
4endif
5
6NIXOPS_STATE ?= ./state/eldiron.nixops
7NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
8nixpkgs ?= https://releases.nixos.org/nixos/19.03/nixos-19.03.172731.3efdf45dbd1/nixexprs.tar.xz
9NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgs}:nixpkgsPrevious=${nixpkgs}
10
11NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
12NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
13
14###### Current channel information
15nix-info:
16 @version=$$(nix eval --raw nixpkgs.lib.version) && \
17 mainversion=$$(echo $$version | cut -d"." -f -2) && \
18 echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \
19 nix eval --raw nixpkgs.bc.meta.position | cut -d"/" -f-4
20.PHONY: nix-info
21
22###### Initial setup
1setup: 23setup:
2 ./scripts/setup 24 ./scripts/setup
25.PHONY: setup
3 26
27###### Nixops regular tasks
28NIXOPS_ARGS ?=
29nixops:
30 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
31
32SSH_ARGS ?=
4ssh-eldiron: 33ssh-eldiron:
5 ./scripts/nixops_wrap ssh eldiron 34 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
6 35
7info: 36info:
8 ./scripts/nixops_wrap list 37 $(NIXOPS_PRIV) list
9 ./scripts/nixops_wrap info 38 $(NIXOPS_PRIV) info
10 39
11debug: 40debug:
12 ./scripts/nixops_wrap deploy --build-only --show-trace 41 $(NIXOPS_PRIV) deploy --build-only --show-trace
13 42
14dry-run: 43dry-run:
15 ./scripts/nixops_wrap deploy --dry-run 44 $(NIXOPS_PRIV) deploy --dry-run
16 45
17build: 46build:
18 ./scripts/nixops_wrap deploy --build-only 47 $(NIXOPS_PRIV) deploy --build-only
19 48
20upload: 49upload:
21 ./scripts/nixops_wrap deploy --copy-only 50 $(NIXOPS_PRIV) deploy --copy-only
22 51
23deploy: 52deploy:
24 ./scripts/nixops_wrap deploy 53 $(NIXOPS_PRIV) deploy
25
26reboot:
27 ./scripts/nixops_wrap reboot --include=eldiron
28 54
29push: 55deploy-reboot:
30 ./scripts/push_deployment 56 $(NIXOPS_PRIV) deploy --force-reboot
31 ./scripts/push_environment
32 57
33pull: 58reboot:
34 ./scripts/pull_environment 59 $(NIXOPS_PRIV) reboot --include=eldiron
35 60.PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
36pull-deployment:
37 ./scripts/pull_deployment
38 61
39profile = $(shell ./scripts/nixops_wrap info | grep "^Nix profile: " | sed -e "s/^Nix profile: //") 62###### Cleanup generations and garbage collection
63profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
40GEN ?= "+3" 64GEN ?= "+3"
41 65
42list-generations: 66list-generations:
43 nix-env -p $(profile) --list-generations 67 nix-env -p $(profile) --list-generations
44 ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations 68 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
69.PHONY: list-generations
45 70
46delete-generations: 71delete-generations:
47 nix-env -p $(profile) --delete-generations $(GEN) 72 nix-env -p $(profile) --delete-generations $(GEN)
48 ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN) 73 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
74.PHONY: delete-generations
49 75
50cleanup: delete-generations 76cleanup: delete-generations
51 nix-store --gc 77 nix-store --gc
52 ./scripts/nixops_wrap ssh eldiron -- nix-store --gc 78 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
53 79.PHONY: cleanup
54.PHONY: setup ssh-eldiron info debug dry-run build upload deploy push pull pull-deployment list-generations delete-generations cleanup 80
81###### Pull environment and deployment from remote
82# Don't include pull_deployment by default as this should happen only rarely
83pull: pull_environment;
84.PHONY: pull
85
86pull_environment:
87ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
88 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
89endif
90 pass git subtree pull --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
91.PHONY: pull_environment
92
93pull_deployment:
94 @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
95 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
96 read y && \
97 [ "$$y" = "y" -o "$$y" = "Y" ] && \
98 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
99 fi
100 pass show $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment | $(NIXOPS) import
101 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
102.PHONY: pull_deployment
103
104deployment_is_set:
105 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
106.PHONY: deployment_is_set
107
108###### Push environment and deployment information to password store
109push: push_deployment push_environment;
110.PHONY: push
111
112push_deployment:
113 $(NIXOPS) export | pass insert -m $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment
114.PHONY: push_deployment
115
116push_environment:
117ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
118 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
119endif
120 pass git subtree push --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
121.PHONY: push_environment