]>
Commit | Line | Data |
---|---|---|
1 | export | |
2 | PASSWORD_STORE_DIR = $(shell pwd)/secrets | |
3 | NIXOPS_STATE ?= ./state/eldiron.nixops | |
4 | NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf | |
5 | nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url') | |
6 | nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url') | |
7 | nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url') | |
8 | NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious} | |
9 | ||
10 | NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops | |
11 | NIXOPS_PRIV = ./scripts/with_env $(NIXOPS) | |
12 | ||
13 | ###### Current channel information | |
14 | nix-info: | |
15 | @version=$$(nix eval --raw nixpkgs.lib.version) && \ | |
16 | mainversion=$$(echo $$version | cut -d"." -f -2) && \ | |
17 | echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \ | |
18 | nix-instantiate --find-file nixpkgs | |
19 | .PHONY: nix-info | |
20 | ||
21 | ###### Initial setup | |
22 | setup: | |
23 | ./scripts/setup | |
24 | .PHONY: setup | |
25 | ||
26 | ###### Nixops regular tasks | |
27 | TARGET ?= | |
28 | NIXOPS_ARGS ?= | |
29 | ifdef TARGET | |
30 | override NIXOPS_ARGS +=--include=$(TARGET) | |
31 | endif | |
32 | SSH_ARGS ?= | |
33 | ||
34 | edit_env: | |
35 | pass edit Nixops/files/environment.nix || true | |
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 | pull_deployment: | |
105 | @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \ | |
106 | echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \ | |
107 | read y && \ | |
108 | [ "$$y" = "y" -o "$$y" = "Y" ] && \ | |
109 | $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \ | |
110 | fi | |
111 | pass show Nixops/Deployment | $(NIXOPS) import | |
112 | $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix" | |
113 | .PHONY: pull_deployment | |
114 | ||
115 | deployment_is_set: | |
116 | $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null | |
117 | .PHONY: deployment_is_set | |
118 | ||
119 | ###### Push deployment information to password store | |
120 | push_deployment: | |
121 | $(NIXOPS) export | pass insert -m Nixops/Deployment | |
122 | .PHONY: push |