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