1 ifndef NIXOPS_ENV_LOADED
2 $(error "Please load environment with direnv")
5 NIXOPS_PRIV = ./scripts/with_env nixops
7 ###### Current channel information
9 @version=$$(nix eval --raw nixpkgs.lib.version) && \
10 mainversion=$$(echo $$version | cut -d"." -f -2) && \
11 echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \
12 nix-instantiate --find-file nixpkgs
20 ###### Nixops regular tasks
24 override NIXOPS_ARGS +=--include=$(TARGET)
29 pass edit Nixops/files/environment.nix || true
32 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
35 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
38 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
41 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
44 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
51 $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS)
54 $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
57 $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS)
60 $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS)
63 $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS)
66 $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS)
69 $(NIXOPS_PRIV) reboot --include=$(TARGET)
70 .PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
72 ###### Cleanup generations and garbage collection
73 profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
77 nix-env -p $(profile) --list-generations
78 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
79 .PHONY: list-generations
82 nix-env -p $(profile) --delete-generations $(GEN)
83 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
84 $(NIXOPS_PRIV) ssh dilion -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
85 $(NIXOPS_PRIV) ssh backup-2 -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
86 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
87 .PHONY: delete-generations
89 cleanup: delete-generations
91 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
92 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
93 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
94 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
97 ###### Pull environment and deployment from remote
99 @if nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
100 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
102 [ "$$y" = "y" -o "$$y" = "Y" ] && \
103 nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
105 pass show Nixops/Deployment | nixops import
106 nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
107 .PHONY: pull_deployment
110 nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
111 .PHONY: deployment_is_set
113 ###### Push deployment information to password store
115 nixops export | pass insert -m Nixops/Deployment