Matthias Andreas Benkard | c55bfae | 2021-01-02 07:35:21 +0100 | [diff] [blame] | 1 | RM_F = rm -f |
| 2 | |
| 3 | DOCKER = docker |
| 4 | NIX_DOCKER = $(DOCKER) run --rm --mount source=type=volume,source=nix,target=/nix --volume $$(pwd):$$(pwd) --workdir $$(pwd) nixos/nix |
| 5 | |
| 6 | #NIX_BUILD = vctl run -it --rm --volume $$(pwd)/nix:/nix --volume $$(pwd):$$(pwd) --workdir $$(pwd) nixos/nix nix-build |
| 7 | NIX_BUILD = $(NIX_DOCKER) nix-build |
| 8 | NIX_BUILD_OUT = $(NIX_DOCKER) sh -c '$$(nix-build)' |
| 9 | |
| 10 | IMAGES = mailcow nano nextcloud prosody samba vim webcron |
| 11 | IMAGES_BIN = $(patsubst %,%.bin,$(IMAGES)) |
| 12 | IMAGES_LOAD = $(patsubst %,%.load,$(IMAGES)) |
| 13 | |
| 14 | .PHONY: all images clean #$(IMAGES_LOAD) |
| 15 | |
| 16 | all: images |
| 17 | |
| 18 | clean: |
| 19 | $(RM_F) $(IMAGES_BIN) |
| 20 | |
| 21 | images: $(IMAGES_LOAD) |
| 22 | |
| 23 | # The following approaches were all considered and discarded: |
| 24 | # |
| 25 | # Takes ~240 seconds (nextcloud image): |
| 26 | # |
| 27 | # $(IMAGES): |
| 28 | # $(NIX_DOCKER) sh -c '$$(nix-build images.nix -A $@.streamed)' | $(DOCKER) load |
| 29 | # |
| 30 | # Takes ~60 seconds (nextcloud image): |
| 31 | # |
| 32 | # $(IMAGES): |
| 33 | # $(NIX_DOCKER) sh -c 'cat $$(nix-build images.nix -A $@.layered)' | $(DOCKER) load |
| 34 | # |
| 35 | # The final approach takes ~20 seconds to build the nextcloud image. |
| 36 | |
| 37 | %.bin: images.nix |
| 38 | $(NIX_DOCKER) sh -c 'cp $$(nix-build images.nix -A $(patsubst %.bin,%,$@).layered) $@' |
| 39 | |
| 40 | %.load: %.bin |
| 41 | $(DOCKER) load --input=$< |