X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=nixops%2FMakefile;h=18d48eb552c4eda3da184c2b991ba3dd8b8f69ad;hb=5dda316b382211733cda7163b33bf388dd052671;hp=5e654ee23d8542358fa14142ec041fd82d9216a7;hpb=b22ce4895ef1e9723a02061f7293e528cfbf9754;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/nixops/Makefile b/nixops/Makefile index 5e654ee..18d48eb 100644 --- a/nixops/Makefile +++ b/nixops/Makefile @@ -1,15 +1,8 @@ -export -ifndef NIXOPS_CONFIG_PASS_SUBTREE_PATH - $(error Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path) +ifndef NIXOPS_ENV_LOADED + $(error "Please load environment with direnv") endif -NIXOPS_STATE ?= ./state/eldiron.nixops -NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf -nixpkgs ?= https://releases.nixos.org/nixos/19.03/nixos-19.03.173677.daf861a810d/nixexprs.tar.xz -NIX_PATH = nixpkgs=${nixpkgs}:nixpkgsNext=${nixpkgs}:nixpkgsPrevious=${nixpkgs} - -NIXOPS := $(shell NIX_PATH=$(NIX_PATH) nix-build --no-out-link -E "with import { overlays = builtins.attrValues (import ../overlays); }; nixops")/bin/nixops -NIXOPS_PRIV = ./scripts/with_env $(NIXOPS) +NIXOPS_PRIV = ./scripts/with_env nixops ###### Current channel information nix-info: @@ -25,41 +18,55 @@ 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_ARGS ?= 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: $(NIXOPS_PRIV) list $(NIXOPS_PRIV) info debug: - $(NIXOPS_PRIV) deploy --build-only --show-trace + $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS) dry-run: - $(NIXOPS_PRIV) deploy --dry-run + $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS) build: - $(NIXOPS_PRIV) deploy --build-only + $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS) upload: - $(NIXOPS_PRIV) deploy --copy-only + $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS) deploy: - $(NIXOPS_PRIV) deploy + $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS) deploy-reboot: - $(NIXOPS_PRIV) deploy --force-reboot + $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS) reboot: - $(NIXOPS_PRIV) reboot --include=eldiron + $(NIXOPS_PRIV) reboot --include=$(TARGET) .PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot ###### Cleanup generations and garbage collection @@ -74,51 +81,36 @@ list-generations: delete-generations: nix-env -p $(profile) --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 $(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 -# Don't include pull_deployment by default as this should happen only rarely -pull: pull_environment; -.PHONY: pull - -pull_environment: -ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE - $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name") -endif - pass git subtree pull --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master -.PHONY: pull_environment - pull_deployment: - @if $(NIXOPS) info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \ + @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); \ + nixops delete --force -d $(NIXOPS_DEPLOYMENT); \ fi - pass show $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment | $(NIXOPS) import - $(NIXOPS) modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix" + 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 + nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null .PHONY: deployment_is_set -###### Push environment and deployment information to password store -push: push_deployment push_environment; -.PHONY: push - +###### Push deployment information to password store push_deployment: - $(NIXOPS) export | pass insert -m $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment -.PHONY: push_deployment - -push_environment: -ifndef NIXOPS_CONFIG_PASS_SUBTREE_REMOTE - $(error "Please set NIXOPS_CONFIG_PASS_SUBTREE_REMOTE to the password-store subtree remote name") -endif - pass git subtree push --prefix=$(NIXOPS_CONFIG_PASS_SUBTREE_PATH) $(NIXOPS_CONFIG_PASS_SUBTREE_REMOTE) master -.PHONY: push_environment + nixops export | pass insert -m Nixops/Deployment +.PHONY: push