blob: a4ca8690476ccd8ffc7fadcba4f58e1822052317 [file] [log] [blame]
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_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)'
IMAGES = mailcow nano nextcloud prosody samba vim webcron
IMAGES_BIN = $(patsubst %,%.bin,$(IMAGES))
IMAGES_LOAD = $(patsubst %,%.load,$(IMAGES))
.PHONY: all images clean #$(IMAGES_LOAD)
all: images
clean:
$(RM_F) $(IMAGES_BIN)
images: $(IMAGES_LOAD)
# The following approaches were all considered and discarded:
#
# Takes ~240 seconds (nextcloud image):
#
# $(IMAGES):
# $(NIX_DOCKER) sh -c '$$(nix-build images.nix -A $@.streamed)' | $(DOCKER) load
#
# Takes ~60 seconds (nextcloud image):
#
# $(IMAGES):
# $(NIX_DOCKER) sh -c 'cat $$(nix-build images.nix -A $@.layered)' | $(DOCKER) load
#
# The final approach takes ~20 seconds to build the nextcloud image.
%.bin: images.nix
$(NIX_DOCKER) sh -c 'cp $$(nix-build images.nix -A $(patsubst %.bin,%,$@).layered) $@'
%.load: %.bin
$(DOCKER) load --input=$<