]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - nixops/Makefile
Add environment file instead of hardcoding everything in makefiles
[perso/Immae/Config/Nix.git] / nixops / Makefile
1 ifndef NIXOPS_ENV_LOADED
2 $(error "Please load environment with direnv")
3 endif
4
5 NIXOPS_PRIV = ./scripts/with_env nixops
6
7 ###### Current channel information
8 nix-info:
9 @version=$$(nix eval --raw nixpkgs.lib.version) && \
10 mainversion=$$(echo $$version | cut -d"." -f -2) && \
11 echo "https://releases.nixos.org/nixos/$$mainversion/nixos-$$version/nixexprs.tar.xz" && \
12 nix-instantiate --find-file nixpkgs
13 .PHONY: nix-info
14
15 ###### Initial setup
16 setup:
17 ./scripts/setup
18 .PHONY: setup
19
20 ###### Nixops regular tasks
21 TARGET ?=
22 NIXOPS_ARGS ?=
23 ifdef TARGET
24 override NIXOPS_ARGS +=--include=$(TARGET)
25 endif
26 SSH_ARGS ?=
27
28 edit_env:
29 pass edit Nixops/files/environment.nix || true
30
31 nixops:
32 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
33
34 ssh-eldiron:
35 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
36
37 ssh-dilion:
38 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
39
40 ssh-backup-2:
41 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
42
43 ssh-monitoring-1:
44 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
45
46 info:
47 $(NIXOPS_PRIV) list
48 $(NIXOPS_PRIV) info
49
50 debug:
51 $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS)
52
53 dry-run:
54 $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
55
56 build:
57 $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS)
58
59 upload:
60 $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS)
61
62 deploy:
63 $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS)
64
65 deploy-reboot:
66 $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS)
67
68 reboot:
69 $(NIXOPS_PRIV) reboot --include=$(TARGET)
70 .PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
71
72 ###### Cleanup generations and garbage collection
73 profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
74 GEN ?= "+3"
75
76 list-generations:
77 nix-env -p $(profile) --list-generations
78 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
79 .PHONY: list-generations
80
81 delete-generations:
82 nix-env -p $(profile) --delete-generations $(GEN)
83 $(NIXOPS_PRIV) ssh eldiron -- 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)
85 $(NIXOPS_PRIV) ssh backup-2 -- 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)
87 .PHONY: delete-generations
88
89 cleanup: delete-generations
90 nix-store --gc
91 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
92 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
93 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
94 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
95 .PHONY: cleanup
96
97 ###### Pull environment and deployment from remote
98 pull_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
109 deployment_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
114 push_deployment:
115 nixops export | pass insert -m Nixops/Deployment
116 .PHONY: push