-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
154 lines (115 loc) · 5.45 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.DEFAULT_GOAL := nixos-deploy
.PHONY: $(shell sed -n -e '/^$$/ { n ; /^[^ .\#][^ ]*:/ { s/:.*$$// ; p ; } ; }' $(MAKEFILE_LIST))
POUND := \#
HOST ?= $(shell hostname -s)
USER ?= $(USER)
EXTRANIXFLAGS ?=
NIXFLAGS = $(strip $(strip $(if $(SYSTEM),--system $(SYSTEM) --extra-extra-platforms $(SYSTEM),) --show-trace --keep-going) $(EXTRANIXFLAGS))
# Adding `|| true` because https://stackoverflow.com/questions/12989869/calling-command-v-find-from-gnu-makefile
DEPLOY ?= $(if $(shell command -v deploy || true),deploy,nix run ".$(POUND)deploy-rs" --)
HOMEMANAGER ?= $(if $(shell command -v home-manager || true),home-manager,nix run ".$(POUND)home-manager" --)
NOROLLBACK ?=
NOFASTCONNECTION ?=
EXTRADEPLOYFLAGS ?=
DEPLOYFLAGS ?= $(strip $(strip $(strip --skip-checks --debug-logs $(if $(NOROLLBACK),--auto-rollback=false --magic-rollback=false,)) $(if $(NOFASTCONNECTION),--fast-connection=false,)) $(EXTRADEPLOYFLAGS))
GENERATE ?= $(if $(shell command -v nixos-generate || true),nixos-generate,nix run ".$(POUND)nixos-generate" --)
GENERATEFORMAT ?= iso
# To build a vm with command `make nixos-build BUILDTYPE=vmWithBootLoader`
BUILDTYPE ?= toplevel
NIXOSREBUILD.build = nix build ".$(POUND)nixosConfigurations.$(HOST).config.system.build.$(BUILDTYPE)"
NIXOSREBUILD.switch = sudo nixos-rebuild switch --flake ".$(POUND)$(HOST)"
NIXOSREBUILD.bootloader = $(NIXOSREBUILD.switch) --install-bootloader
nixos-rebuild = $(NIXOSREBUILD.$(word 2,$(subst -, ,$1)))
DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
ROOTDIR = $(DIR)/root
IGNOREDDIR = $(DIR)/ignored
DESTDIR ?= ${HOME}
DESTROOTDIR ?= /
VERBOSE ?=
# The chezmoi state directory is stored in the same directory as the config file,
# which may not be writable.
CHEZMOIFLAGS ?= $(strip $(if $(VERBOSE),-v) --keep-going)
CHEZMOI = chezmoi
CHEZMOI.home = chezmoi
CHEZMOI.root = sudo chezmoi
DESTDIR.home = $(DESTDIR)
DESTDIR.root = $(DESTROOTDIR)
SRCDIR = $(DIR)
SRCDIR.home = $(SRCDIR)
SRCDIR.root = $(ROOTDIR)
chezmoi = ${CHEZMOI.$(firstword $(subst -, ,$1))} ${CHEZMOIFLAGS}
dest = $(DESTDIR.$(firstword $(subst -, ,$1)))
src = $(SRCDIR.$(firstword $(subst -, ,$1)))
pull:
git pull --rebase --autostash
push:
git status
git commit -a -m "auto push at $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')"
git log HEAD^..HEAD
git diff HEAD^..HEAD
read -p 'Press enter to continue, C-c to exit' && git push
autopush:
git commit -a -m "auto push at $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')"
git push
upload: pull push
update: pull update-upstreams
chezmoi-init chezmoi-update chezmoi-status chezmoi-apply chezmoi-purge:
$(CHEZMOI) $(CHEZMOIFLAGS) -D $(DESTDIR) -S $(SRCDIR) $(word 2,$(subst -, ,$@)) || true
home-install root-install:
$(call chezmoi,$@) -D $(call dest,$@) -S $(call src,$@) apply || true
all-install: home-install root-install
home-uninstall root-uninstall:
$(call chezmoi,$@) -D $(call dest,$@) -S $(call src,$@) purge
all-uninstall: home-uninstall root-uninstall
update-upstreams:
nix flake update
clean:
[[ -d tmp ]] && rm -rf tmp/
if [[ "$(realpath result)" == /nix/store/* ]]; then rm -f result; fi
sops:
sops ./nix/sops/secrets.yaml
create-dirs:
mkdir -p tmp
home-manager:
$(HOMEMANAGER) switch --flake ".#$(USER)@$(HOST)" $(NIXFLAGS)
home-manager-build:
$(HOMEMANAGER) build --flake ".#$(USER)@$(HOST)" $(NIXFLAGS)
home-manager-bootstrap:
$(HOMEMANAGER) switch --flake ".#$(USER)@cicd-$(shell nix eval --raw --expr 'builtins.currentSystem')" $(NIXFLAGS)
nixos-prefs: JQ = $(or $(shell command -v jq),cat)
nixos-prefs: create-dirs
nix eval --impure --raw --expr "(builtins.getFlake (builtins.toString ./.)).nixosConfigurations.$(HOST).config.passthru.prefsJson" | $(JQ) | tee tmp/prefs.$(HOST).json
nixos-deploy:
$(DEPLOY) $(DEPLOYFLAGS) ".#$(HOST)" -- $(NIXFLAGS)
nixos-profile-path-info: create-dirs
nix path-info -sShr "$(shell $(NIXOSREBUILD.build) $(NIXFLAGS) --print-out-paths)" | tee tmp/nixos-profile-path-info.$(HOST)
sort -h -k2 < tmp/nixos-profile-path-info.$(HOST)
sort -h -k3 < tmp/nixos-profile-path-info.$(HOST)
nixos-build nixos-switch nixos-bootloader:
$(call nixos-rebuild,$@) $(NIXFLAGS)
nixos-generate:
$(GENERATE) -f $(GENERATEFORMAT) --flake ".#$(HOST)"
# Filters do not work yet, as cachix will upload the closure.
cachix-push: create-dirs
if ! make HOST=$(HOST) nixos-build; then :; fi
nix derivation show $(NIXFLAGS) -r ".#nixosConfigurations.$(HOST).config.system.build.toplevel" | jq -r '.[].outputs[].path' | xargs -i sh -c 'test -f "{}" && echo "{}"' > tmp/cachix-push.paths
grep -vE 'clion|webstorm|idea-ultimate|goland|pycharm-professional|datagrip|android-studio-dev|graalvm11-ce|lock$$|-source$$|ndk-bundle|vivaldi|sources-android|commandlinetools-linux' tmp/cachix-push.paths | cachix push contrun -m zstd -c 16 -j 1
cachix-push-all:
make HOST=cicd-x86_64-linux cachix-push
make HOST=cicd-aarch64-linux cachix-push
nixos-update-channels:
sudo nix-channel --update
nixos-vagrant-box:
$(GENERATE) -f vagrant-virtualbox --flake ".#dbx"
ansible-requirements:
cd ansible && ansible-galaxy install -r requirements.yml
ansible-diff-inventory-hosts:
cd ansible && diff <(git cat-file blob HEAD:ansible/inventory/hosts.yml | ansible-vault view -) <(ansible-vault view inventory/hosts.yml)
ansible-view-inventory-hosts:
cd ansible && ansible-vault view inventory/hosts.yml
ansible-edit-inventory-hosts:
cd ansible && ansible-vault edit inventory/hosts.yml
ansible-deploy:
cd ansible && ansible-playbook services.yml --extra-vars services=$(SERVICES)
flyctl-deploy:
flyctl deploy -c fly/$(SERVICE)/fly.toml