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