-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
235 lines (195 loc) · 5.63 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
NIXOS_VERSION := 20.09
NIX_LOCAL_PACKAGES := $(shell nix eval --raw \
'( \
with import <nixpkgs> {}; \
with lib; \
let \
pkgs = callPackage ./nixos/pkgs/default.nix {}; \
in \
pipe pkgs [ \
attrNames \
(filter (n: ! elem n [ "override" "overrideDerivation" ])) \
(concatStringsSep " ") \
] \
)' \
)
IGNORE_PATHS := \
'./zsh/.oh-my-zsh/**' \
'./zsh/.oh-my-zsh-custom/**' \
'./vim/.vim/bundle/**' \
'./vim/.vim/plugged/**' \
'./tmux/.tmux/plugins/**' \
'**/vendor/**' \
'**/node_modules/**' \
'**/.venv/**' \
'./qmk/.qmk_firmware/**'
SHELL_FILES := \
$(shell \
find . \
\( -type f -name '*.sh' -or -name '*.bash' -or -name '*.zsh' \) \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
) \
$(shell \
filter_bash_content() { \
while read filename; do \
if head -n1 "$$filename" | grep 'bash\|zsh\|sh' > /dev/null; then \
echo "$$filename"; \
fi; \
done \
} && \
\
find ./bin/bin ./rofi/modes ./scripts ./git/.git-global/hooks \
-type f \
-and -not -path './bin/bin/neofetch' \
-and -not -path './bin/bin/styles' | \
filter_bash_content \
)
NIX_FILES := $(shell find . \
-type f -name '*.nix' \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
)
PRETTIER_FILES := $(shell find . \
-type f \( -name '*.js' -or -name '*.css' -or -name '*.json' -or -name '*.yml' -or -name '*.md' \) \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
)
LUA_FILES := $(shell find . \
-type f -name '*.lua' \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
)
FNL_FILES := $(shell find . \
-type f -name '*.fnl' \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
)
DEFAULT_NIX_FILES := $(shell find . \
-mindepth 2 -maxdepth 2 \
-type f -name 'default.nix' \
-and -not -path './nixos/default.nix' \
-and -not -path './themes/default.nix' \
-and -not -path './secrets/**/*.nix' \
$(addprefix -and -not -path , $(IGNORE_PATHS)) \
)
all: init .vscode/c_cpp_properties.json compile_commands.json
init:
# git config core.hooksPath .githooks
.PHONY: nixos
nixos: nixos-channels nixos-upgrade
.PHONY: nixos-upgrade
nixos-upgrade: nixos-update nixos-switch
.PHONY: nixos-upgrade-unstable
nixos-upgrade-unstable: nixos-update-unstable nixos-switch
.PHONY: nixos-update
nixos-update: nixos-channels
sudo nix-channel --update
.PHONY: nixos-update-unstable
nixos-update-unstable: nixos-channels
sudo nix-channel --update nixos-unstable
.PHONY: nixos-switch
nixos-switch:
sudo nixos-rebuild switch
.PHONY: nixos-build
nixos-build:
nixos-rebuild build
.PHONY: $(addprefix nixos-build-pkgs-, $(NIX_LOCAL_PACKAGES))
$(addprefix nixos-build-pkgs-, $(NIX_LOCAL_PACKAGES)): nixos-build-pkgs-%:
nix-build \
-E 'with import <nixpkgs> {}; callPackage ./nixos/pkgs/default.nix {}' \
-A $* \
--out-link "result-$*"
.PHONY: $(addprefix nixos-shell-pkgs-, $(NIX_LOCAL_PACKAGES))
$(addprefix nixos-shell-pkgs-, $(NIX_LOCAL_PACKAGES)): nixos-shell-pkgs-%:
nix-shell \
-E 'with import <nixpkgs> {}; callPackage ./nixos/pkgs/default.nix {}' \
-A $*
.PHONY: nixos-dry-build
nixos-dry-build:
nixos-rebuild dry-build
.PHONY: nixos-gc
nixos-gc:
sudo nix-collect-garbage -d
# Add NixOS channels.
# See: https://nixos.org/nixos/manual/index.html#sec-upgrading .
.PHONY: nixos-channels
nixos-channels:
sudo nix-channel --add "https://nixos.org/channels/nixos-$(NIXOS_VERSION)" nixos
sudo nix-channel --add "https://nixos.org/channels/nixos-unstable" nixos-unstable
sudo nix-channel --list
.PHONY: nixos-uninstall-users-packages
nixos-uninstall-users-packages:
nix-env --uninstall $(shell nix-env -q | grep -v 'home-manager-path')
.PHONY: qmk-moonlander
qmk-moonlander:
$(MAKE) -C qmk moonlander
.PHONY: format
format: format-shell format-nix format-prettier format-lua
.PHONY: format-shell
format-shell:
./scripts/nix-call.sh shfmt shfmt -i 4 -ci -sr -s -w $(SHELL_FILES)
.PHONY: format-nix
format-nix:
./scripts/nix-call.sh nixpkgs-fmt nixpkgs-fmt $(NIX_FILES)
.PHONY: format-nix
format-prettier:
npx prettier --config ./prettier/.prettierrc.js --write $(PRETTIER_FILES)
.PHONY: format-lua
format-lua:
./scripts/lua-format.sh --config=./.lua-format -i $(LUA_FILES)
.PHONY: format-fnl
format-fnl:
fnlfmt --fix $(FNL_FILES)
.PHONY: generate
generate: generate-configs generate-vscode-extensions
.PHONY: generate-configs
generate-configs:
./scripts/generate-configs
.PHONY: generate-vscode-extensions
generate-vscode-extensions:
./scripts/generate-vscode-extensions
.PHONY: generate-install-sh
generate-install-sh:
$(foreach name,$(DEFAULT_NIX_FILES:./%/default.nix=%),./scripts/generate-install-sh $(name) ; )
.PHONY: test
test: test-lua test-nix
.PHONY: test-lua
test-lua:
./scripts/nix-call.sh busted lua52Packages.busted \
--verbose \
--directory=./awesome \
'--lpath="./?.lua;./?/?.lua;./?/init.lua"' \
./
.PHONY: test-nix
test-nix:
./nixos/test/run.sh
# Autocomplete.
qmk/compile_commands.json:
$(MAKE) -C qmk compile_commands.json
compile_commands.json: qmk/compile_commands.json
jq -s '. | flatten' $^ > compile_commands.json
.vscode:
mkdir -p .vscode
.ONESHELL:
.vscode/c_cpp_properties.json: .vscode
PWD="$(shell pwd)"
cat <<EOF | jq . > .vscode/c_cpp_properties.json
{
"configurations": [
{
"name": "Auto-generated",
"compileCommands": "$$PWD/compile_commands.json"
}
],
"version": 4
}
EOF
# Secrets.
secrets:
git clone https://github.com/SuperPaintman/dotfiles-secrets ~/Projects/github.com/SuperPaintman/dotfiles-secrets
ln -s ~/Projects/github.com/SuperPaintman/dotfiles-secrets ./secrets
.PHONY: clean-nixos-builds
clean-nixos-builds:
rm -f result
rm -f result-*
.PHONY: clean
clean: clean-nixos-builds
rm -f compile_commands.json
rm -f .vscode/c_cpp_properties.json
$(MAKE) -C qmk clean