-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
233 lines (179 loc) · 6.06 KB
/
Makefile
File metadata and controls
233 lines (179 loc) · 6.06 KB
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
# make-Nix v0.1.7
# This Makefile provides targets to install and configure Nix, Nix-Darwin,
# and Nix Home-manager for MacOS and Linux systems. It can build and deploy on
# NixOS and Nix-Darwin managed systems, as well as on other Linux distributions
# using Nix Home-manager configurations.
# Please see https://github.com/pete3n/make-nix for documentation.
.DEFAULT_GOAL := help
MAKEFLAGS += --no-print-directory
SHELL := /bin/sh
UNAME_S := $(shell uname -s)
ifeq ($(shell id -u),0)
ifneq ($(filter help,$(MAKECMDGOALS)),help)
$(error Do not run make as root. Run as a normal user; sudo will be used when needed.)
endif
endif
ifeq ($(origin MAKE_NIX_TMPDIR), undefined)
MAKE_NIX_TMPDIR := $(shell TMPDIR="$${TMPDIR:-/tmp}"; mktemp -d "$$TMPDIR/make-nix.XXXXXX")
export MAKE_NIX_TMPDIR
endif
ifeq ($(origin MAKE_NIX_ENV), undefined)
MAKE_NIX_ENV := $(MAKE_NIX_TMPDIR)/env
MAKE_NIX_LOG := $(MAKE_NIX_TMPDIR)/log
MAKE_NIX_INSTALLER := $(MAKE_NIX_TMPDIR)/installer
export MAKE_NIX_ENV MAKE_NIX_LOG MAKE_NIX_INSTALLER
# Ensure the files exist before appending
$(shell : > "$(MAKE_NIX_ENV)")
$(shell : > "$(MAKE_NIX_LOG)")
$(shell : > "$(MAKE_NIX_INSTALLER)")
# Seed the env file with the other paths you want to source in common.sh
$(shell printf "MAKE_NIX_LOG=%s\n" "$(MAKE_NIX_LOG)" >> "$(MAKE_NIX_ENV)")
$(shell printf "MAKE_NIX_INSTALLER=%s\n" "$(MAKE_NIX_INSTALLER)" >> "$(MAKE_NIX_ENV)")
$(shell printf "UNAME_S=%s\n" "$(shell uname -s)" >> "$(MAKE_NIX_ENV)")
endif
#
# Utility targets.
#
.PHONY: validate-args
validate-args:
@sh "make-scripts/validate_args.sh" $(MAKECMDGOALS)
.PHONY: set-env
set-env:
@sh "make-scripts/set_env.sh"
.PHONY: check-deps
check-deps:
@sh "make-scripts/check_deps.sh" $(MAKECMDGOALS)
.PHONY: prep-goal
prep-goal: validate-args set-env check-deps
.PHONY: clean
clean: prep-goal clean-sh
.PHONY: clean-sh
clean-sh:
@sh "make-scripts/clean.sh"
.PHONY: help
help: set-env show-help
.PHONY: show-help
show-help:
@sh "make-scripts/print_help.sh"
#
# Install/uninstall targets.
#
.PHONY: install
install: prep-goal install-sh clean-sh
.PHONY: install-sh
install-sh:
@sh "make-scripts/installs.sh"
.PHONY: uninstall
uninstall: prep-goal uninstall-sh
.PHONY: uninstall-sh
uninstall-sh:
@sh "make-scripts/uninstalls.sh" $(MAKECMDGOALS)
#
# Check targets.
#
.PHONY: check
check: prep-goal check-sh clean-sh
.PHONY: check-read
check-read: prep-goal read-attrs-sh clean-sh
.PHONY: check-home
check-home: prep-goal check-home-sh clean-sh
.PHONY: check-system
check-system: prep-goal check-system-sh clean-sh
# Check previous configuration based on username and hostname
.PHONY: check-sh
check-sh:
@sh "make-scripts/attrs.sh" --check-all
# Check previous home configuration based on username and hostname
.PHONY: check-home-sh
check-home-sh:
@sh "make-scripts/attrs.sh" --check-home
# Check previous system configuration based on username and hostname
.PHONY: check-system-sh
check-system-sh:
@sh "make-scripts/attrs.sh" --check-system
# Pass imperative configuration attributes from make to flake.nix
.PHONY: write-attrs-sh
write-attrs-sh:
@sh "make-scripts/attrs.sh" --write
# Read imperative configuration attributes
.PHONY: read-attrs-sh
read-attrs-sh:
@sh "make-scripts/attrs.sh" --read
#
# Build targets.
#
.PHONY: build
build: prep-goal write-attrs-sh check-sh build-system-sh build-home-sh clean-sh
.PHONY: build-system
build-system: prep-goal write-attrs-sh check-system-sh build-system-sh clean-sh
.PHONY: build-pi
build-pi: prep-goal write-attrs-sh check-system-sh build-pi-sh clean-sh
.PHONY: build-home
build-home: prep-goal write-attrs-sh check-home-sh build-home-sh clean-sh
# Build the Pi image artifact (SD card image or PXE netboot).
.PHONY: build-pi-sh
build-pi-sh:
@sh "make-scripts/system.sh" --build
# Build flake-based system configurations for Linux or Darwin systems.
.PHONY: build-system-sh
build-system-sh:
@sh "make-scripts/system.sh" --build
# Build flake-based Home-manager configurations for Linux or Darwin systems.
.PHONY: build-home-sh
build-home-sh:
@sh "make-scripts/home.sh" --build
# Check for a dirty git tree and warn on a failed build about the confusing
# missing path error. I should not have to write this...
.PHONY: warn-if-dirty-sh
warn-if-dirty-sh-sh:
@sh "make-scripts/common.sh [warn_if_dirty]"
.PHONY: warn-test
warn-test: prep-goal warn-if-dirty-sh clean-sh
.PHONY: set-boot-sh
set-boot-sh:
@sh "make-scripts/set_boot.sh"
#
# Switch targets.
#
.PHONY: switch
switch: prep-goal write-attrs-sh check-sh switch-system-sh switch-home-sh \
set-boot-sh clean-sh
.PHONY: switch-system
switch-system: prep-goal write-attrs-sh check-system-sh switch-system-sh \
set-boot-sh clean-sh
.PHONY: switch-pi
switch-pi: prep-goal write-attrs-sh check-system-sh switch-pi-sh clean-sh
.PHONY: switch-home
switch-home: prep-goal write-attrs-sh check-home-sh switch-home-sh clean-sh
# Switch the Pi NixOS configuration (post-first-boot, over SSH).
.PHONY: switch-pi-sh
switch-pi-sh:
@sh "make-scripts/system.sh" --switch
# Build and activate flake-based system configurations for Linux or Darwin systems.
.PHONY: switch-system-sh
switch-system-sh:
@sh "make-scripts/system.sh" --switch
# Activate flake-based Home-manager configurations for Linux or Darwin systems.
.PHONY: activate-home-sh
activate-home-sh:
@sh "make-scripts/home.sh" --activate
# Build and activate flake-based Home-manager configurations for Linux or Darwin systems.
.PHONY: switch-home-sh
switch-home-sh:
@sh "make-scripts/home.sh" --switch
.PHONY: update
update: prep-goal update-sh clean-sh
.PHONY: update-sh
update-sh:
@sh "make-scripts/update.sh"
.PHONY: test
test: prep-goal check-sh warn-if-dirty-sh
# Set the default boot menu option to the first specified specialisation for a system.
.PHONY: all
all: prep-goal install-sh write-attrs-sh check-sh warn-if-dirty-sh \
switch-system-sh switch-home-sh set-boot-sh clean-sh
%:
@printf "Unknown target: '$@'\n"
@printf "Valid targets: help all install check switch update uninstall\n"
@printf "Valid sub-targets: check-system check-home build-system build-pi build-home switch-system switch-pi switch-home\n"
@false