Update Makefile

Automatically select nixos or home-manager install using /etc/nixos
directory as test
This commit is contained in:
Evie Litherland-Smith 2023-05-04 12:29:07 +01:00
parent b3bc2ba5ce
commit 7a90a24b96

View file

@ -2,42 +2,22 @@ $(eval HOSTNAME=$(shell hostname))
NIXOS_CONFIG := $(PWD)/nixos/$(HOSTNAME).nix
HOMEMANAGER_CONFIG := $(PWD)/nixos/home/$(HOSTNAME)-$(USER).nix
CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config)
SSH_DIR := $(HOME)/.ssh
HOMEMANAGER_CONFIG_DIR := $(CONFIG_DIR)/home-manager
CONFIG_ITEMS := $(wildcard config/*)
CONFIG_TARGETS := $(CONFIG_ITEMS:config/%=$(CONFIG_DIR)/%)
SSH_ITEMS := $(wildcard ssh/*)
SSH_TARGETS := $(SSH_ITEMS:ssh/%=$(SSH_DIR)/%)
.PHONY: default all clean home nixos install test
.PHONY: default all clean link home nixos install
default:
[ -e /etc/nixos/ ] && make nixos || make home
default: install
all: nixos
all: install nixos home
clean:
rm $(SSH_DIR)/config.d
rm $(HOME)/.inputrc
rm -rf $(HOME)/.local/share/nvim
sudo rm /etc/nixos/$(HOSTNAME).nix
rm -rf $(HOME)/.local/state/nvim
[ -e $(HOMEMANAGER_CONFIG_DIR) ] && rm -rf $(HOMEMANAGER_CONFIG_DIR)
$(CONFIG_DIR) $(SSH_DIR) $(CONFIG_DIR)/home-manager:
mkdir -p $@
link: $(SSH_DIR)/config.d $(HOME)/.inputrc
$(SSH_DIR)/config.d: $(SSH_DIR)/%: ssh/%
$(HOME)/.inputrc: $(HOME)/%: %
$(SSH_DIR)/config.d $(HOME)/.inputrc:
ln -s $(PWD)/$? $@
legacy:
echo "TODO"
home: $(CONFIG_DIR)/home-manager/home.nix
$(CONFIG_DIR)/home-manager/home.nix: $(CONFIG_DIR)/home-manager
ln -s $(HOMEMANAGER_CONFIG) $@
/nix:
command -v nix > /dev/null && echo "Nix already installed" || ./scripts/install_nix.sh --daemon
nixos: /etc/nixos/$(HOSTNAME).nix
@ -45,7 +25,11 @@ nixos: /etc/nixos/$(HOSTNAME).nix
[ -f $(NIXOS_CONFIG) ] || touch $(NIXOS_CONFIG)
sudo ln -s $(NIXOS_CONFIG) $@
install: /nix
home: $(HOMEMANAGER_CONFIG_DIR)/home.nix
/nix:
command -v nix > /dev/null && echo "Nix already installed" || ./scripts/install_nix.sh --daemon
$(HOMEMANAGER_CONFIG_DIR)/home.nix: $(HOMEMANAGER_CONFIG_DIR) /nix
[ -f $(HOMEMANAGER_CONFIG) ] || touch $(HOMEMANAGER_CONFIG)
ln -s $(HOMEMANAGER_CONFIG) $@
$(CONFIG_DIR) $(HOMEMANAGER_CONFIG_DIR):
mkdir -p $@