2 PASSWORD_STORE_DIR = $(shell pwd)/secrets
3 NIXOPS_STATE ?= ./state/eldiron.nixops
4 NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf
5 nixpkgs ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops".url')
6 nixpkgsNext ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-next".url')
7 nixpkgsPrevious ?= $(shell cat ../nix/sources.json | jq -r '."nixpkgs-nixops-previous".url')
8 NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgsNext}:nixpkgsPrevious=${nixpkgsPrevious}
10 NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops
11 NIXOPS_PRIV = ./scripts/with_env $(NIXOPS)
13 ###### Current channel information
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" && \
18 nix-instantiate --find-file nixpkgs
26 ###### Nixops regular tasks
30 override NIXOPS_ARGS +=--include=$(TARGET)
35 pass edit Nixops/files/environment.nix || true
38 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
41 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
44 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
47 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
50 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
57 $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS)
60 $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
63 $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS)
66 $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS)
69 $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS)
72 $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS)
75 $(NIXOPS_PRIV) reboot --include=$(TARGET)
76 .PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
78 ###### Cleanup generations and garbage collection
79 profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
83 nix-env -p $(profile) --list-generations
84 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
85 .PHONY: list-generations
88 nix-env -p $(profile) --delete-generations $(GEN)
89 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
90 $(NIXOPS_PRIV) ssh dilion -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
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)
93 .PHONY: delete-generations
95 cleanup: delete-generations
97 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
98 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
99 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
100 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
103 ###### Pull environment and deployment from remote
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]" && \
108 [ "$$y" = "y" -o "$$y" = "Y" ] && \
109 $(NIXOPS) delete --force -d $(NIXOPS_DEPLOYMENT); \
111 pass show Nixops/Deployment | $(NIXOPS) import
112 $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
113 .PHONY: pull_deployment
116 $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
117 .PHONY: deployment_is_set
119 ###### Push deployment information to password store
121 $(NIXOPS) export | pass insert -m Nixops/Deployment