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