Makefile: Add init, gc targets.

Change-Id: I36227db6f3a227b995c121ca6fc83d78eda94c47
diff --git a/makefile b/makefile
index a4ca869..ee955d7 100644
--- a/makefile
+++ b/makefile
@@ -1,9 +1,10 @@
 RM_F = rm -f
 
 DOCKER = docker
-NIX_DOCKER = $(DOCKER) run --rm --mount source=type=volume,source=nix,target=/nix --volume $$(pwd):$$(pwd) --workdir $$(pwd) nixos/nix
+NIX_DOCKER_0 = $(DOCKER) run --rm --volume $$(pwd):$$(pwd) --workdir $$(pwd)
+NIX_DOCKER_MAINT = $(NIX_DOCKER_0) --mount source=type=volume,source=nix,target=/nix2 nixos/nix
+NIX_DOCKER = $(NIX_DOCKER_0) --mount source=type=volume,source=nix,target=/nix nixos/nix
 
-#NIX_BUILD = vctl run -it --rm --volume $$(pwd)/nix:/nix --volume $$(pwd):$$(pwd) --workdir $$(pwd) nixos/nix nix-build
 NIX_BUILD = $(NIX_DOCKER) nix-build
 NIX_BUILD_OUT = $(NIX_DOCKER) sh -c '$$(nix-build)'
 
@@ -11,13 +12,25 @@
 IMAGES_BIN = $(patsubst %,%.bin,$(IMAGES))
 IMAGES_LOAD = $(patsubst %,%.load,$(IMAGES))
 
-.PHONY: all images clean #$(IMAGES_LOAD)
+.PHONY: all images clean init gc #$(IMAGES_LOAD)
 
 all: images
 
+# Deletes all build artifacts.
 clean:
 	$(RM_F) $(IMAGES_BIN)
 
+# Runs nix-collect-garbage in the Docker container.
+gc:
+	$(NIX_DOCKER) nix-collect-garbage
+
+# Initializes the Docker volume with a Nix store.
+#
+# Run this before any other target of this makefile.
+init:
+	$(NIX_DOCKER_MAINT) sh -c 'nix-env -iA nixpkgs.rsync && rsync --info=progress2 -a /nix/ /nix2/'
+
+# Builds and loads all known Docker images.
 images: $(IMAGES_LOAD)
 
 # The following approaches were all considered and discarded:
@@ -34,8 +47,11 @@
 #
 # The final approach takes ~20 seconds to build the nextcloud image.
 
+# Builds a Docker image as a .bin file that you can load with 'docker
+# load'.
 %.bin: images.nix
 	$(NIX_DOCKER) sh -c 'cp $$(nix-build images.nix -A $(patsubst %.bin,%,$@).layered) $@'
 
+# Builds and loads a Docker image into your local Docker daemon.
 %.load: %.bin
 	$(DOCKER) load --input=$<