2 ifndef NIXOPS_CONFIG_PASS_SUBTREE_PATH
3 $(error Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path)
6 NIXOPS_STATE ?= ./state/eldiron.nixops
7 NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
8 nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url')
9 nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url')
10 nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url')
11 NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious}
13 NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
14 NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
16 ###### Current channel information
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" && \
21 nix-instantiate --find-file nixpkgs
29 ###### Nixops regular tasks
32 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
36 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
39 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
42 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
45 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
52 $(NIXOPS_PRIV) deploy --build-only --show-trace
55 $(NIXOPS_PRIV) deploy --dry-run
58 $(NIXOPS_PRIV) deploy --build-only --max-jobs 1
61 $(NIXOPS_PRIV) deploy --copy-only
67 $(NIXOPS_PRIV) deploy --force-reboot
70 $(NIXOPS_PRIV) reboot --include=eldiron
71 .PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
73 ###### Cleanup generations and garbage collection
74 profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
78 nix-env -p $(profile) --list-generations
79 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
80 .PHONY: list-generations
83 nix-env -p $(profile) --delete-generations $(GEN)
84 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
85 $(NIXOPS_PRIV) ssh dilion -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
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)
88 .PHONY: delete-generations
90 cleanup: delete-generations
92 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
93 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
94 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
95 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
98 ###### Pull environment and deployment from remote
99 # Don't include pull_deployment by default as this should happen only rarely
100 pull: pull_environment;
104 ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
105 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
107 pass git subtree pull --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
108 .PHONY: pull_environment
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]" && \
114 [ "$$y" = "y" -o "$$y" = "Y" ] && \
115 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
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
122 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
123 .PHONY: deployment_is_set
125 ###### Push environment and deployment information to password store
126 push: push_deployment push_environment;
130 $(NIXOPS) export | pass insert -m $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment
131 .PHONY: push_deployment
134 ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE
135 $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name")
137 pass git subtree push --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master
138 .PHONY: push_environment