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