51 lines
1.7 KiB
Makefile
51 lines
1.7 KiB
Makefile
$(eval HOSTNAME=$(shell hostname))
|
|
HOMEMANAGER_CONFIG := $(PWD)/machines/$(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 home-init /etc/nixos/config nvim
|
|
|
|
default:
|
|
command -v nix > /dev/null || exit 1
|
|
if [ -e /etc/nixos/ ]; then make nixos; else make home; fi
|
|
|
|
all: default nvim
|
|
bat cache --build
|
|
|
|
clean:
|
|
[ -e /etc/nixos ] && sudo rm /etc/nixos/config || rm -rf $(HOMEMANAGER_CONFIG_DIR)
|
|
|
|
nixos: /etc/nixos/config
|
|
grep -i ./config/machines/$$(hostname) /etc/nixos/configuration.nix && sudo nixos-rebuild switch
|
|
|
|
home: $(HOMEMANAGER_CONFIG_DIR)/home.nix $(CONFIG_DIR)/nixpkgs/config.nix $(HOME)/.nix-defexpr/channels/home-manager
|
|
nix-shell -p home-manager --run "home-manager switch"
|
|
|
|
home-init: $(HOMEMANAGER_CONFIG_DIR)/home.nix $(CONFIG_DIR)/nixpkgs/config.nix $(HOME)/.nix-defexpr/channels/home-manager
|
|
nix-shell '<home-manager>' -A install
|
|
|
|
/etc/nixos/config:
|
|
sudo rsync -avz --exclude-from=.rsyncignore --filter=':- .gitignore' --delete-during --delete-excluded ./ $@
|
|
|
|
nvim: $(CONFIG_DIR)/nvim
|
|
|
|
$(HOMEMANAGER_CONFIG):
|
|
touch $@
|
|
|
|
$(HOMEMANAGER_CONFIG_DIR)/home.nix: $(HOMEMANAGER_CONFIG) $(HOMEMANAGER_CONFIG_DIR) /nix
|
|
-ln -s $(HOMEMANAGER_CONFIG) $@
|
|
|
|
$(CONFIG_DIR)/nixpkgs/config.nix:
|
|
echo '{ allowUnfree = true; }' > $@
|
|
|
|
$(HOME)/.nix-defexpr/channels/home-manager:
|
|
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
nix-channel --update
|
|
|
|
$(CONFIG_DIR)/nvim: $(CONFIG_DIR)
|
|
-nix-shell -p git --run "git clone https://git.xenia.me.uk/xenia/nvim.git $@"
|
|
-nix-shell -p git --run "git -C $@ pull --ff-only"
|
|
|
|
$(CONFIG_DIR) $(HOMEMANAGER_CONFIG_DIR):
|
|
mkdir -p $@
|