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