]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/Makefile
Simplify management of secrets in nixops
[perso/Immae/Config/Nix.git] / nixops / Makefile
CommitLineData
4506dbe5 1export
1052bfda 2PASSWORD_STORE_DIR = $(shell pwd)/secrets
4506dbe5
IB
3NIXOPS_STATE ?= ./state/eldiron.nixops
4NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
ccda44f3
IB
5nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url')
6nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url')
7nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url')
8NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious}
4506dbe5
IB
9
10NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
11NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
12
13###### Current channel information
14nix-info:
15 @version=$$(nix eval --raw nixpkgs.lib.version) && \
16 mainversion=$$(echo $$version | cut -d"." -f -2) && \
17 echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \
af3aeef2 18 nix-instantiate --find-file nixpkgs
4506dbe5
IB
19.PHONY: nix-info
20
21###### Initial setup
c79bb682
IB
22setup:
23 ./scripts/setup
4506dbe5 24.PHONY: setup
c79bb682 25
4506dbe5 26###### Nixops regular tasks
7ff0f7be 27TARGET ?=
4506dbe5 28NIXOPS_ARGS ?=
7ff0f7be
IB
29ifdef TARGET
30 override NIXOPS_ARGS +=--include=$(TARGET)
31endif
32SSH_ARGS ?=
33
1052bfda
IB
34edit_env:
35 pass edit Nixops/files/environment.nix || true
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
4506dbe5
IB
104pull_deployment:
105 @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
106 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
107 read y && \
108 [ "$$y" = "y" -o "$$y" = "Y" ] && \
109 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
110 fi
1052bfda 111 pass show Nixops/Deployment | $(NIXOPS) import
4506dbe5
IB
112 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
113.PHONY: pull_deployment
114
115deployment_is_set:
116 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
117.PHONY: deployment_is_set
118
1052bfda 119###### Push deployment information to password store
4506dbe5 120push_deployment:
1052bfda
IB
121 $(NIXOPS) export | pass insert -m Nixops/Deployment
122.PHONY: push