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