+ifndef NIXOPS_ENV_LOADED
+ $(error "Please load environment with direnv")
+endif
+
+NIXOPS_PRIV = ./scripts/with_env nixops
+
+###### Current channel information
+nix-info:
+ @version=$$(nix eval --raw nixpkgs.lib.version) && \
+ mainversion=$$(echo $$version | cut -d"." -f -2) && \
+ echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \
+ nix-instantiate --find-file nixpkgs
+.PHONY: nix-info
+
+###### Initial setup
setup:
./scripts/setup
+.PHONY: setup
+
+###### Nixops regular tasks
+TARGET ?=
+NIXOPS_ARGS ?=
+ifdef TARGET
+ override NIXOPS_ARGS +=--include=$(TARGET)
+endif
+SSH_ARGS ?=
+
+edit_env:
+ pass edit Nixops/files/environment.nix || true
+
+nixops:
+ $(NIXOPS_PRIV) $(NIXOPS_ARGS)
ssh-eldiron:
- ./scripts/nixops_wrap ssh eldiron
+ $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
+
+ssh-dilion:
+ $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
+
+ssh-backup-2:
+ $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
+
+ssh-monitoring-1:
+ $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
info:
- ./scripts/nixops_wrap list
- ./scripts/nixops_wrap info
+ $(NIXOPS_PRIV) list
+ $(NIXOPS_PRIV) info
debug:
- ./scripts/nixops_wrap deploy --build-only --show-trace
+ $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS)
dry-run:
- ./scripts/nixops_wrap deploy --dry-run
+ $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
build:
- ./scripts/nixops_wrap deploy --build-only
+ $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS)
upload:
- ./scripts/nixops_wrap deploy --copy-only
+ $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS)
deploy:
- ./scripts/nixops_wrap deploy
-
-reboot:
- ./scripts/nixops_wrap reboot --include=eldiron
+ $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS)
-push:
- ./scripts/push_deployment
- ./scripts/push_environment
+deploy-reboot:
+ $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS)
-pull:
- ./scripts/pull_environment
-
-pull-deployment:
- ./scripts/pull_deployment
+reboot:
+ $(NIXOPS_PRIV) reboot --include=$(TARGET)
+.PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
-profile = $(shell ./scripts/nixops_wrap info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
+###### Cleanup generations and garbage collection
+profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
GEN ?= "+3"
list-generations:
nix-env -p $(profile) --list-generations
- ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
+ $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
+.PHONY: list-generations
delete-generations:
nix-env -p $(profile) --delete-generations $(GEN)
- ./scripts/nixops_wrap ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
+ $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
+ $(NIXOPS_PRIV) ssh dilion -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
+ $(NIXOPS_PRIV) ssh backup-2 -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
+ $(NIXOPS_PRIV) ssh monitoring-1 -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
+.PHONY: delete-generations
cleanup: delete-generations
nix-store --gc
- ./scripts/nixops_wrap ssh eldiron -- nix-store --gc
-
-.PHONY: setup ssh-eldiron info debug dry-run build upload deploy push pull pull-deployment list-generations delete-generations cleanup
+ $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
+ $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
+ $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
+ $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
+.PHONY: cleanup
+
+###### Pull environment and deployment from remote
+pull_deployment:
+ @if nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
+ echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
+ read y && \
+ [ "$$y" = "y" -o "$$y" = "Y" ] && \
+ nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
+ fi
+ pass show Nixops/Deployment | nixops import
+ nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
+.PHONY: pull_deployment
+
+deployment_is_set:
+ nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
+.PHONY: deployment_is_set
+
+###### Push deployment information to password store
+push_deployment:
+ nixops export | pass insert -m Nixops/Deployment
+.PHONY: push