nixos/Makefile

36 lines
1 KiB
Makefile

$(eval HOSTNAME=$(shell hostname))
NIXOS_CONFIG := $(PWD)/$(HOSTNAME).nix
HOMEMANAGER_CONFIG := $(PWD)/home/$(HOSTNAME)-$(USER).nix
CONFIG_DIR := $(if $(XDG_CONFIG_HOME), $(XDG_CONFIG_HOME), $(HOME)/.config)
HOMEMANAGER_CONFIG_DIR := $(CONFIG_DIR)/home-manager
.PHONY: default all clean nixos home
default:
[ -e /etc/nixos/ ] && make nixos || make home
all: install nixos home
clean:
rm -rf $(HOME)/.local/share/nvim
rm -rf $(HOME)/.local/state/nvim
[ -e $(HOMEMANAGER_CONFIG_DIR) ] && rm -rf $(HOMEMANAGER_CONFIG_DIR)
/nix:
command -v nix > /dev/null && echo "Nix already installed" || ./scripts/install_nix.sh --daemon
nixos: /etc/nixos/$(HOSTNAME).nix
/etc/nixos/$(HOSTNAME).nix: /nix
[ -f $(NIXOS_CONFIG) ] || touch $(NIXOS_CONFIG)
sudo ln -s $(NIXOS_CONFIG) $@
home: $(HOMEMANAGER_CONFIG_DIR)/home.nix
$(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 $@