From cca1f68a4f018f913cbd33f657f84af799cf827b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 27 Mar 2019 22:03:50 +0100 Subject: [PATCH 1/2] By default only build an image if service.image is set --- src/nix/modules/service/image.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/nix/modules/service/image.nix b/src/nix/modules/service/image.nix index f530165..a3b91b5 100644 --- a/src/nix/modules/service/image.nix +++ b/src/nix/modules/service/image.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, config, ... }: +{ pkgs, lib, config, options, ... }: let inherit (lib) types mkOption; inherit (types) attrsOf listOf nullOr package str unspecified bool; @@ -32,6 +32,8 @@ let done; ''; }; + + priorityIsDefault = option: option.highestPrio >= (lib.mkDefault true).priority; in { options = { @@ -58,8 +60,11 @@ in Whether to build this image with Nixpkgs' dockerTools.buildLayeredImage and then load it with docker load. + + By default, an image will be built with Nix unless + is set. See also , which defaults to + the service name. ''; - default = true; }; image.name = mkOption { type = str; @@ -111,5 +116,7 @@ in service.image = lib.mkDefault "${config.build.imageName}:${config.build.imageTag}"; image.rawConfig.Cmd = config.image.command; + + image.nixBuild = lib.mkDefault (priorityIsDefault options.service.image); }; } From f789d163ccdb4a46e3e80ff38ed4f793e92a922b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 27 Mar 2019 22:04:31 +0100 Subject: [PATCH 2/2] Add error context to image building functions --- src/nix/modules/composition/images.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/nix/modules/composition/images.nix b/src/nix/modules/composition/images.nix index 9a9b04c..bedf8e8 100644 --- a/src/nix/modules/composition/images.nix +++ b/src/nix/modules/composition/images.nix @@ -7,11 +7,13 @@ let lib.filterAttrs filterFunction config.docker-compose.evaluatedServices ); - filterFunction = _serviceName: service: - service.config.image.nixBuild; + filterFunction = serviceName: service: + builtins.addErrorContext "while evaluating whether the service ${serviceName} defines an image" + service.config.image.nixBuild; - addDetails = _serviceName: service: - let + addDetails = serviceName: service: + builtins.addErrorContext "while evaluating the image for service ${serviceName}" + (let inherit (service.config) build; in { image = build.image.outPath; @@ -20,7 +22,7 @@ let if build.image.imageTag != "" then build.image.imageTag else lib.head (lib.strings.splitString "-" (baseNameOf build.image.outPath)); - }; + }); in { options = {