X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=nixops%2FMakefile;h=3f29e5253fcde42e4a645690fbdc3b59a29008c1;hb=53fa9f9e7d87835d6137a029fe80b3195e635797;hp=1d76a9c6e90b2f0af897e4f4c29ffe43f0715e27;hpb=c79bb68270abd6e5a59e36bf09d64b2eb0d23fb8;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/nixops/Makefile b/nixops/Makefile index 1d76a9c..3f29e52 100644 --- a/nixops/Makefile +++ b/nixops/Makefile @@ -1,51 +1,121 @@ +export +ifndef NIXOPS_CONFIG_PASS_SUBTREE_PATH + $(error Please set NIXOPS_CONFIG_PASS_SUBTREE_PATH to the password-store subtree path) +endif + +NIXOPS_STATE ?= ./state/eldiron.nixops +NIXOPS_DEPLOYMENT = cef694f3-081d-11e9-b31f-0242ec186adf +nixpkgs ?= https://releases.nixos.org/nixos/19.03/nixos-19.03.173009.2516c454c35/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) + +###### 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 +NIXOPS_ARGS ?= +nixops: + $(NIXOPS_PRIV) $(NIXOPS_ARGS) +SSH_ARGS ?= ssh-eldiron: - ./scripts/nixops_wrap ssh eldiron + $(NIXOPS_PRIV) ssh eldiron -- $(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 dry-run: - ./scripts/nixops_wrap deploy --dry-run + $(NIXOPS_PRIV) deploy --dry-run build: - ./scripts/nixops_wrap deploy --build-only + $(NIXOPS_PRIV) deploy --build-only upload: - ./scripts/nixops_wrap deploy --copy-only + $(NIXOPS_PRIV) deploy --copy-only deploy: - ./scripts/nixops_wrap deploy - -push: - ./scripts/push_deployment - ./scripts/push_environment + $(NIXOPS_PRIV) deploy -pull: - ./scripts/pull_environment +deploy-reboot: + $(NIXOPS_PRIV) deploy --force-reboot -pull-deployment: - ./scripts/pull_deployment +reboot: + $(NIXOPS_PRIV) reboot --include=eldiron +.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) +.PHONY: delete-generations cleanup: delete-generations nix-store --gc - ./scripts/nixops_wrap ssh eldiron -- nix-store --gc + $(NIXOPS_PRIV) ssh eldiron -- 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 \ + 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_CONFIG_PASS_SUBTREE_PATH)/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 environment and deployment information to password store +push: push_deployment push_environment; +.PHONY: push + +push_deployment: + $(NIXOPS) export | pass insert -m $(NIXOPS_CONFIG_PASS_SUBTREE_PATH)/Nixops/Deployment +.PHONY: push_deployment -.PHONY: setup ssh-eldiron info debug dry-run build upload deploy push pull pull-deployment list-generations delete-generations cleanup +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