From 638c4b8e552a86c315acbe32fd6cbd399885d1d0 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sat, 19 Aug 2023 22:13:18 +0200 Subject: [PATCH] fix: services..service.build.context One could declare it, but it was unceremoniously ignored. A "localhost/" image was created with pretty much nothing in it and it couldn't be launched. The cause was services..service.image being always set and subsequently thugs services..image.nixBuild being truthy. That would build an image and write the services..image field in the docker-compose.json. It leads to the build.context being ignored and the service failing. This was solved by only writing services..service.image when services..service.build.context is not set. services..image.nixBuild is additionally set to false when the context is set. Related to #208 --- .../service/docker-compose-service.nix | 6 ++-- src/nix/modules/service/image.nix | 28 ++++++++++--------- tests/arion-test/default.nix | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/nix/modules/service/docker-compose-service.nix b/src/nix/modules/service/docker-compose-service.nix index 061ae8b..c038ac6 100644 --- a/src/nix/modules/service/docker-compose-service.nix +++ b/src/nix/modules/service/docker-compose-service.nix @@ -86,7 +86,8 @@ in description = serviceRef "environment"; }; service.image = mkOption { - type = str; + type = nullOr str; + default = null; description = serviceRef "image"; }; service.command = mkOption { @@ -328,8 +329,9 @@ in volumes environment sysctls - image ; + } // lib.optionalAttrs (config.service.image != null) { + inherit (config.service) image; } // lib.optionalAttrs (config.service.build.context != null) { inherit (config.service) build; } // lib.optionalAttrs (cap_add != []) { diff --git a/src/nix/modules/service/image.nix b/src/nix/modules/service/image.nix index 706a5c1..ae5d214 100644 --- a/src/nix/modules/service/image.nix +++ b/src/nix/modules/service/image.nix @@ -163,17 +163,19 @@ in ''; }; }; - config = { - build.image = builtImage; - build.imageName = config.build.image.imageName; - build.imageTag = - if config.build.image.imageTag != "" - then config.build.image.imageTag - else lib.head (lib.strings.splitString "-" (baseNameOf config.build.image.outPath)); - - service.image = lib.mkDefault "${config.build.imageName}:${config.build.imageTag}"; - image.rawConfig.Cmd = config.image.command; - - image.nixBuild = lib.mkDefault (priorityIsDefault options.service.image); - }; + config = lib.mkMerge [{ + build.image = builtImage; + build.imageName = config.build.image.imageName; + build.imageTag = + if config.build.image.imageTag != "" + then config.build.image.imageTag + else lib.head (lib.strings.splitString "-" (baseNameOf config.build.image.outPath)); + image.rawConfig.Cmd = config.image.command; + image.nixBuild = lib.mkDefault (priorityIsDefault options.service.image); + } + ( lib.mkIf (config.service.build.context == null) + { + service.image = lib.mkDefault "${config.build.imageName}:${config.build.imageTag}"; + }) + ]; } diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix index 75f940d..f8ba4c3 100644 --- a/tests/arion-test/default.nix +++ b/tests/arion-test/default.nix @@ -29,7 +29,7 @@ in enable = true; dockerSocket.enable = true; }; - + # no caches, because no internet nix.settings.substituters = lib.mkForce [];