aboutsummaryrefslogtreecommitdiff
path: root/nixops/Makefile
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2020-09-04 02:40:24 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2020-09-04 02:59:46 +0200
commit34abd6afa44c620a56416bd423a2438a09bd1ce4 (patch)
treeb7eef613348fcb9d8fabd19c0437430c30678152 /nixops/Makefile
parentf5cbc6f767ee234e9cdd53baa113d5ab26edb6d8 (diff)
downloadNix-34abd6afa44c620a56416bd423a2438a09bd1ce4.tar.gz
Nix-34abd6afa44c620a56416bd423a2438a09bd1ce4.tar.zst
Nix-34abd6afa44c620a56416bd423a2438a09bd1ce4.zip
Migrate to morph as a replacement to nixops
The deployment tasks are now independent of any state
Diffstat (limited to 'nixops/Makefile')
-rw-r--r--nixops/Makefile87
1 files changed, 27 insertions, 60 deletions
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
2 $(error "Please load environment with direnv") 2 $(error "Please load environment with direnv")
3endif 3endif
4 4
5NIXOPS_PRIV = ./scripts/with_env nixops
6
7###### Current channel information 5###### Current channel information
8nix-info: 6nix-info:
9 @version=$$(nix eval --raw nixpkgs.lib.version) && \ 7 @version=$$(nix eval --raw nixpkgs.lib.version) && \
@@ -17,100 +15,69 @@ setup:
17 ./scripts/setup 15 ./scripts/setup
18.PHONY: setup 16.PHONY: setup
19 17
20###### Nixops regular tasks 18###### Morph regular tasks
19PROFILE=/nix/var/nix/profiles/per-user/immae/morph/immaeEu
21TARGET ?= 20TARGET ?=
22NIXOPS_ARGS ?= 21MORPH_ARGS ?=
23ifdef TARGET 22ifdef TARGET
24 override NIXOPS_ARGS +=--include=$(TARGET) 23 # multiple targets: --on="{machine1,machine2}" (works with * glob too)
24 override MORPH_ARGS +=--on=$(TARGET)
25endif 25endif
26SSH_ARGS ?= 26SSH_ARGS ?=
27 27
28edit_env: 28edit_env:
29 pass edit Nixops/files/environment.nix || true 29 pass edit Nixops/files/environment.nix || true
30 30
31nixops:
32 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
33
34ssh-eldiron: 31ssh-eldiron:
35 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS) 32 ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@eldiron $(SSH_ARGS)'
36 33
37ssh-dilion: 34ssh-dilion:
38 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS) 35 ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@dilion $(SSH_ARGS)'
39 36
40ssh-backup-2: 37ssh-backup-2:
41 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS) 38 ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@backup-2 $(SSH_ARGS)'
42 39
43ssh-monitoring-1: 40ssh-monitoring-1:
44 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS) 41 ./scripts/with_env bash -c 'ssh -i $$SSH_IDENTITY_FILE root@monitoring-1 $(SSH_ARGS)'
45
46info:
47 $(NIXOPS_PRIV) list
48 $(NIXOPS_PRIV) info
49 42
50debug: 43debug:
51 $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS) 44 ./scripts/with_env morph build --show-trace default.nix $(MORPH_ARGS)
52
53dry-run:
54 $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
55 45
56build: 46build:
57 $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS) 47 ./scripts/with_env morph build default.nix $(MORPH_ARGS)
58 48
59upload: 49upload:
60 $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS) 50 ./scripts/with_env morph push default.nix $(MORPH_ARGS)
61 51
62deploy: 52deploy:
63 $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS) 53 ./scripts/with_env morph deploy default.nix switch --keep-result --upload-secrets $(MORPH_ARGS)
54 nix-env -p $(PROFILE) --set .gcroots/default.nix
64 55
65deploy-reboot: 56deploy-reboot:
66 $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS) 57 ./scripts/with_env morph deploy default.nix boot --reboot --upload-secrets $(MORPH_ARGS)
67 58
68reboot: 59.PHONY: ssh-eldiron ssh-dilion ssh-monitoring-1 ssh-backup-2 debug build upload deploy deploy-reboot
69 $(NIXOPS_PRIV) reboot --include=$(TARGET)
70.PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
71 60
72###### Cleanup generations and garbage collection 61###### Cleanup generations and garbage collection
73profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
74GEN ?= "+3" 62GEN ?= "+3"
75 63
76list-generations: 64list-generations:
77 nix-env -p $(profile) --list-generations 65 nix-env -p $(PROFILE) --list-generations
78 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations 66 $(MAKE) ssh-eldiron SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --list-generations"
79.PHONY: list-generations 67.PHONY: list-generations
80 68
81delete-generations: 69delete-generations:
82 nix-env -p $(profile) --delete-generations $(GEN) 70 nix-env -p $(PROFILE) --delete-generations $(GEN)
83 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN) 71 $(MAKE) ssh-eldiron SSH_ARGS="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) 72 $(MAKE) ssh-dilion SSH_ARGS="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) 73 $(MAKE) ssh-backup-2 SSH_ARGS="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) 74 $(MAKE) ssh-monitoring-1 SSH_ARGS="nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)"
87.PHONY: delete-generations 75.PHONY: delete-generations
88 76
89cleanup: delete-generations 77cleanup: delete-generations
90 nix-store --gc 78 nix-store --gc
91 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc 79 $(MAKE) ssh-eldiron SSH_ARGS="nix-store --gc"
92 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc 80 $(MAKE) ssh-dilion SSH_ARGS="nix-store --gc"
93 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc 81 $(MAKE) ssh-backup-2 SSH_ARGS="nix-store --gc"
94 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc 82 $(MAKE) ssh-monitoring-1 SSH_ARGS="nix-store --gc"
95.PHONY: cleanup 83.PHONY: cleanup
96
97###### Pull environment and deployment from remote
98pull_deployment:
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]" && \
101 read y && \
102 [ "$$y" = "y" -o "$$y" = "Y" ] && \
103 nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
104 fi
105 pass show Nixops/Deployment | nixops import
106 nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
107.PHONY: pull_deployment
108
109deployment_is_set:
110 nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
111.PHONY: deployment_is_set
112
113###### Push deployment information to password store
114push_deployment:
115 nixops export | pass insert -m Nixops/Deployment
116.PHONY: push