X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=nixops%2FMakefile;h=0bebaf8202ebaec529a9ec2c9d26e0f766fe8dd9;hp=18d48eb552c4eda3da184c2b991ba3dd8b8f69ad;hb=34abd6afa44c620a56416bd423a2438a09bd1ce4;hpb=f5cbc6f767ee234e9cdd53baa113d5ab26edb6d8 diff --git a/nixops/Makefile b/nixops/Makefile index 18d48eb..0bebaf8 100644 --- a/nixops/Makefile +++ b/nixops/Makefile @@ -2,8 +2,6 @@ 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) && \ @@ -17,100 +15,69 @@ setup: ./scripts/setup .PHONY: setup -###### Nixops regular tasks +###### Morph regular tasks +PROFILE=/nix/var/nix/profiles/per-user/immae/morph/immaeEu TARGET ?= -NIXOPS_ARGS ?= +MORPH_ARGS ?= ifdef TARGET - override NIXOPS_ARGS +=--include=$(TARGET) + # multiple targets: --on="{machine1,machine2}" (works with * glob too) + override MORPH_ARGS +=--on=$(TARGET) endif SSH_ARGS ?= edit_env: pass edit Nixops/files/environment.nix || true -nixops: - $(NIXOPS_PRIV) $(NIXOPS_ARGS) - ssh-eldiron: - $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS) + ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@eldiron $(SSH_ARGS)' ssh-dilion: - $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS) + ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@dilion $(SSH_ARGS)' ssh-backup-2: - $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS) + ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@backup-2 $(SSH_ARGS)' ssh-monitoring-1: - $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS) - -info: - $(NIXOPS_PRIV) list - $(NIXOPS_PRIV) info + ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@monitoring-1 $(SSH_ARGS)' debug: - $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS) - -dry-run: - $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS) + ./scripts/with_env morph build --show-trace default.nix $(MORPH_ARGS) build: - $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS) + ./scripts/with_env morph build default.nix $(MORPH_ARGS) upload: - $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS) + ./scripts/with_env morph push default.nix $(MORPH_ARGS) deploy: - $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS) + ./scripts/with_env morph deploy default.nix switch --keep-result --upload-secrets $(MORPH_ARGS) + nix-env -p $(PROFILE) --set .gcroots/default.nix deploy-reboot: - $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS) + ./scripts/with_env morph deploy default.nix boot --reboot --upload-secrets $(MORPH_ARGS) -reboot: - $(NIXOPS_PRIV) reboot --include=$(TARGET) -.PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot +.PHONY: ssh-eldiron ssh-dilion ssh-monitoring-1 ssh-backup-2 debug build upload deploy deploy-reboot ###### 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 - $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations + nix-env -p $(PROFILE) --list-generations + $(MAKE) ssh-eldiron SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --list-generations" .PHONY: 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) + nix-env -p $(PROFILE) --delete-generations $(GEN) + $(MAKE) ssh-eldiron SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)" + $(MAKE) ssh-dilion SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)" + $(MAKE) ssh-backup-2 SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)" + $(MAKE) ssh-monitoring-1 SSH_ARGS="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 + $(MAKE) ssh-eldiron SSH_ARGS="nix-store --gc" + $(MAKE) ssh-dilion SSH_ARGS="nix-store --gc" + $(MAKE) ssh-backup-2 SSH_ARGS="nix-store --gc" + $(MAKE) ssh-monitoring-1 SSH_ARGS="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