Commit 405b2f35ad85

Vincent Demeester <vincent@sbr.pm>
2020-04-04 19:47:40
Makefile: starting to merge home and nixos
- Add a setup for links, … - Run home-manager or nixos-rebuild depending on the $USER Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent eb38ae8
Changed files (1)
Makefile
@@ -1,20 +1,17 @@
 # Makefile for home
 
+# Variables
 EMACS =
 ifndef EMACS
 EMACS = "emacs"
 endif
 
-DOTEMACS =
-ifndef DOTEMACS
-DOTEMACS = "~/.config/emacs"
-endif
-
-PUBLISH_FOLDER =
-ifndef PUBLISH_FOLDER
-PUBLISH_FOLDER=~/desktop/sites/beta.sbr.pm
-endif
+DOTEMACS = ~/.config/emacs
+DOTNIXPKGS = ~/.config/nixpkgs
+SYNCDIR = ~/sync/nixos
+PUBLISH_FOLDER = ~/desktop/sites/beta.sbr.pm
 
+# Targets
 .PHONY: all
 all: build
 
@@ -26,18 +23,31 @@ update:
 pull:
 	(cd overlays/emacs-overlay && git pull --rebase)
 
+# home-manager setup
 .PHONY: assets
 assets:
+	mkdir -p assets
 	cp -Rv ~/sync/nixos/machines.nix assets/
 
 .PHONY: build
 build: assets
-	home-manager build
+	@if test $(USER) = root;\
+	then\
+		nixos-rebuild build;\
+	else\
+		home-manager build;\
+	fi
 
 .PHONY: switch
 switch: assets
-	home-manager switch
+	@if test $(USER) = root;\
+	then\
+		nixos-rebuild build;\
+	else\
+		home-manager build;\
+	fi
 
+# Cleaning
 .PHONY: clean
 clean:
 	unlink result
@@ -47,6 +57,7 @@ clean-www:
 	@rm -rvf *.elc
 	@rm -rv ~/.org-timestamps/*
 
+# Documentatino build and publishing
 .PHONY: build-www
 build-www: ${HOME}/src/www/publish-common.el publish.el
 	@echo "Publishing... with current Emacs configurations."
@@ -59,3 +70,25 @@ ${HOME}/src/www/publish-common.el: ${HOME}/src/www/
 
 ${HOME}/src/www/:
 	test -d ${HOME}/src/www || git clone git@git.sr.ht:~vdemeester/www.git ${HOME}/src/www/
+
+# Setup and doctor
+.PHONY: doctor
+doctor:
+	@echo "Validate the environment"
+	@readlink $(DOTEMACS) || $(error $(DOTEMACS) is not correctly linked, you may need to run setup)
+	@readlink $(DOTNIXPKGS) || $(error $(DOTNIXPKGS) is not correctly linked, you may need to run setup)
+
+.PHONY: setup
+setup: $(DOTEMACS) $(DOTNIXPKGS) $(SYNCDIR)
+	@echo $(USER)
+
+$(DOTEMACS):
+	@echo "Link $(DOTEMACS) to $(CURDIR)/tools/emacs"
+	@ln -s $(CURDIR)/tools/emacs $(DOTEMACS)
+
+$(DOTNIXPKGS):
+	@echo "Link $(DOTNIXPKGS) to $(CURDIR)"
+	@ln -s $(CURDIR) $(DOTNIXPKGS)
+
+$(SYNCDIR):
+	$(error $(SYNCDIR) is not present, you need to configure syncthing before running this command)