aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: b707efb9cfdca391141c4ef29d6cbd8b4e9bce95 (plain)
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
.PHONY: install update macos-update macos-install nixos-update nixos-install fonts

# Determine the current system from its hostname.
# My university network changes my hostname on my laptop. I use the disgusting system_profiler pipeline to get the real hostname if the uname command fails
SYSTEM := $(shell uname -n)
ifeq ($(wildcard src/$(project)/*),)
	SYSTEM = $(shell system_profiler SPSoftwareDataType | grep "Computer Name" | xargs | sed 's/Computer Name: //' | sed 's/$$/.local/')
endif

# Set directories
SRCDIR = ./$(SYSTEM)
DSTDIR = $(HOME)
FONTSDIR = .local/share/fonts

# Get the list of files that need to be generated
SOURCES := $(shell find -L $(SRCDIR)/ -type f)
NOGPG := $(SOURCES:%.gpg=%)
NOORG := $(NOGPG:%.org=%)
CONFIGS := $(subst $(SRCDIR)/,$(DSTDIR)/,$(NOORG))

# Set any extra targets based on the hostname
UPDATE_TARGET :=
INSTALL_TARGET :=
ifeq ($(SYSTEM), nixos)
	UPDATE_TARGET += nixos-update
	INSTALL_TARGET += nixos-install
else ifeq ($(SYSTEM), macos.local)
	UPDATE_TARGET += macos-update
	INSTALL_TARGET += macos-install
endif

# update by default, install first
all: update
update: install $(UPDATE_TARGET)
	cp $(DSTDIR)/.flake/flake.lock $(SRCDIR)/.flake

# install configs and any additional targets
install: $(CONFIGS) $(INSTALL_TARGET)

# install encrypted org configs
$(DSTDIR)/%: $(SRCDIR)/%.org.gpg
	mkdir -p $(dir $@)
	gpg -d --batch $< 1> tmp.org
	python3 ./extract_src.py tmp.org $@
	rm tmp.org

# install org configs
$(DSTDIR)/%: $(SRCDIR)/%.org
	mkdir -p $(dir $@)
	python3 ./extract_src.py $< $@

# install generic files
$(DSTDIR)/%: $(SRCDIR)/%
	mkdir -p $(dir $@)
	cp $< $@

macos-update: install
	nix flake update --flake $(DSTDIR)/.flake
	darwin-rebuild switch --flake $(DSTDIR)/.flake

# macos install tells System Events to update the wallpaper after installation
macos-install: $(CONFIGS)
	darwin-rebuild switch --flake $(DSTDIR)/.flake
	osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"/$$HOME/.wallpaper\" as POSIX file"

nixos-update: install
	nix flake update $(DSTDIR)/.flake
	sudo nixos-rebuild switch --flake $(DSTDIR)/.flake

nixos-install: $(CONFIGS)
	sudo nixos-rebuild switch --flake $(DSTDIR)/.flake