.PHONY: system-reconfigure system-vm system-container system-build pull home-reconfigure home-vm home-container home-build
SYSTEM_ARGS = -L ./modules ./config.scm
HOME_ARGS = -L ./home/modules ./home/home-configuration.scm
TIMEMACHINE = guix time-machine -C channels-lock.scm
EXTRA_ARGS ?=
GUIX=$(TIMEMACHINE) --
target: channels-lock.scm channels-profile.scm channels-manifest.scm
	rm -rf target
	mkdir -p target
	guix build \
    -f ./channels-profile.scm \
		-r ./target/guix
pull: channels-lock.scm channels-manifest.scm target
  # TODO: investigate what guix version to use here.
  # How to ensure it is not built twice unnecessarily?
  # The problem is that guix-for-channels actually produces
  # a different derivation if we are in different current guix.
  # Maybe it would make sense to have sort of a bootstrap guix
  # built that will not be updated so regularly, and be used
  # only to obtain the guix instances?
	guix package --profile='~/.config/guix/current' \
    --manifest=./channels-manifest.scm
system-build: channels-lock.scm target
	$(GUIX) system build $(SYSTEM_ARGS) $(EXTRA_ARGS)
system-reconfigure: channels-lock.scm target
	$(GUIX) system reconfigure $(SYSTEM_ARGS) --cores=10 --max-jobs=5 $(EXTRA_ARGS)
system-vm: channels-lock.scm target
	$(GUIX) system vm $(SYSTEM_ARGS) $(EXTRA_ARGS)
system-container: channels-lock.scm target
	$(GUIX) system container $(SYSTEM_ARGS) $(EXTRA_ARGS)
home-build: channels-lock.scm target
	$(GUIX) home build $(HOME_ARGS) $(EXTRA_ARGS)
home-reconfigure: channels-lock.scm target
	$(GUIX) home reconfigure $(HOME_ARGS) --cores=10 --max-jobs=5 $(EXTRA_ARGS)
home-container: channels-lock.scm target
	$(GUIX) home container $(HOME_ARGS) $(EXTRA_ARGS)
system-repl: channels-lock.scm target
	$(GUIX) repl -L modules -i ./repl-init.scm $(EXTRA_ARGS)
channels-lock.scm: channels.scm
	guix time-machine -C channels.scm -- describe -f channels $(EXTRA_ARGS) > channels-lock.scm