]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/Makefile
Add environment file instead of hardcoding everything in makefiles
[perso/Immae/Config/Nix.git] / nixops / Makefile
CommitLineData
da28a4e2
IB
1ifndef NIXOPS_ENV_LOADED
2 $(error "Please load environment with direnv")
3endif
4
5NIXOPS_PRIV = ./scripts/with_env nixops
4506dbe5
IB
6
7###### Current channel information
8nix-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" && \
af3aeef2 12 nix-instantiate --find-file nixpkgs
4506dbe5
IB
13.PHONY: nix-info
14
15###### Initial setup
c79bb682
IB
16setup:
17 ./scripts/setup
4506dbe5 18.PHONY: setup
c79bb682 19
4506dbe5 20###### Nixops regular tasks
7ff0f7be 21TARGET ?=
4506dbe5 22NIXOPS_ARGS ?=
7ff0f7be
IB
23ifdef TARGET
24 override NIXOPS_ARGS +=--include=$(TARGET)
25endif
26SSH_ARGS ?=
27
1052bfda
IB
28edit_env:
29 pass edit Nixops/files/environment.nix || true
30
4506dbe5
IB
31nixops:
32 $(NIXOPS_PRIV) $(NIXOPS_ARGS)
33
c79bb682 34ssh-eldiron:
4506dbe5 35 $(NIXOPS_PRIV) ssh eldiron -- $(SSH_ARGS)
c79bb682 36
8a304ef4
IB
37ssh-dilion:
38 $(NIXOPS_PRIV) ssh dilion -- $(SSH_ARGS)
39
ddaa9caf
IB
40ssh-backup-2:
41 $(NIXOPS_PRIV) ssh backup-2 -- $(SSH_ARGS)
42
e820134d
IB
43ssh-monitoring-1:
44 $(NIXOPS_PRIV) ssh monitoring-1 -- $(SSH_ARGS)
45
c79bb682 46info:
4506dbe5
IB
47 $(NIXOPS_PRIV) list
48 $(NIXOPS_PRIV) info
c79bb682
IB
49
50debug:
7ff0f7be 51 $(NIXOPS_PRIV) deploy --build-only --show-trace $(NIXOPS_ARGS)
c79bb682
IB
52
53dry-run:
7ff0f7be 54 $(NIXOPS_PRIV) deploy --dry-run $(NIXOPS_ARGS)
c79bb682
IB
55
56build:
7ff0f7be 57 $(NIXOPS_PRIV) deploy --build-only $(NIXOPS_ARGS)
c79bb682
IB
58
59upload:
7ff0f7be 60 $(NIXOPS_PRIV) deploy --copy-only $(NIXOPS_ARGS)
c79bb682
IB
61
62deploy:
7ff0f7be 63 $(NIXOPS_PRIV) deploy $(NIXOPS_ARGS)
1618010c 64
4506dbe5 65deploy-reboot:
7ff0f7be 66 $(NIXOPS_PRIV) deploy --force-reboot $(NIXOPS_ARGS)
c79bb682 67
4506dbe5 68reboot:
7ff0f7be 69 $(NIXOPS_PRIV) reboot --include=$(TARGET)
4506dbe5 70.PHONY: nixops ssh-eldiron info debug dry-run build upload deploy deploy-reboot reboot
c79bb682 71
4506dbe5
IB
72###### Cleanup generations and garbage collection
73profile := $$($(NIXOPS_PRIV) info | grep "^Nix profile: " | sed -e "s/^Nix profile: //")
c79bb682
IB
74GEN ?= "+3"
75
76list-generations:
77 nix-env -p $(profile) --list-generations
4506dbe5
IB
78 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --list-generations
79.PHONY: list-generations
c79bb682
IB
80
81delete-generations:
82 nix-env -p $(profile) --delete-generations $(GEN)
4506dbe5 83 $(NIXOPS_PRIV) ssh eldiron -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
8a304ef4 84 $(NIXOPS_PRIV) ssh dilion -- nix-env -p /nix/var/nix/profiles/system --delete-generations $(GEN)
e820134d
IB
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)
4506dbe5 87.PHONY: delete-generations
c79bb682
IB
88
89cleanup: delete-generations
90 nix-store --gc
4506dbe5 91 $(NIXOPS_PRIV) ssh eldiron -- nix-store --gc
8a304ef4 92 $(NIXOPS_PRIV) ssh dilion -- nix-store --gc
e820134d
IB
93 $(NIXOPS_PRIV) ssh backup-2 -- nix-store --gc
94 $(NIXOPS_PRIV) ssh monitoring-1 -- nix-store --gc
4506dbe5
IB
95.PHONY: cleanup
96
97###### Pull environment and deployment from remote
4506dbe5 98pull_deployment:
da28a4e2 99 @if nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null ; then \
4506dbe5
IB
100 echo "This will remove your current deployment file and recreate it!. Continue? [y/N]" && \
101 read y && \
102 [ "$$y" = "y" -o "$$y" = "Y" ] && \
da28a4e2 103 nixops delete --force -d $(NIXOPS_DEPLOYMENT); \
4506dbe5 104 fi
da28a4e2
IB
105 pass show Nixops/Deployment | nixops import
106 nixops modify -d $(NIXOPS_DEPLOYMENT) "$$(pwd)/default.nix"
4506dbe5
IB
107.PHONY: pull_deployment
108
109deployment_is_set:
da28a4e2 110 nixops info -d $(NIXOPS_DEPLOYMENT) 2>/dev/null >/dev/null
4506dbe5
IB
111.PHONY: deployment_is_set
112
1052bfda 113###### Push deployment information to password store
4506dbe5 114push_deployment:
da28a4e2 115 nixops export | pass insert -m Nixops/Deployment
1052bfda 116.PHONY: push