diff --git a/src/arion b/src/arion index 27f49c0..32ec65d 100755 --- a/src/arion +++ b/src/arion @@ -163,6 +163,32 @@ do_build() { --show-trace \ --attr 'config.build.dockerComposeYaml' \ >/dev/null ; + + echo 1>&2 "Ensuring required images are loaded..." + jq -r <"$docker_compose_yaml" \ + '.["x-arion"].images | map(" - " + .imageName + ":" + .imageTag) | join("\n")' + eval "$( + jq -r '.["docker-compose"]["x-arion"].images as $images + | .["existing-images"] as $loaded + | $images + | map( + if $loaded[.imageName + ":" + .imageTag] + then "" + else "docker load <" + .image + ";" end + ) + | join("\n") + ' <docker loaded. + ''; + internal = true; + }; + build.imageName = mkOption { + type = str; + description = "Derived from build.image"; + internal = true; + }; + build.imageTag = mkOption { + type = str; + description = "Derived from build.image"; + internal = true; + }; + image.nixBuild = mkOption { + type = bool; + description = '' + Whether to build this image with Nixpkgs' + dockerTools.buildLayeredImage + and then load it with docker load. + ''; + default = true; + }; + image.name = mkOption { + type = str; + default = config.service.name; + defaultText = lib.literalExample "config.service.name"; + description = '' + A human readable name for the docker image. + + Shows up in the docker ps output in the + IMAGE column, among other places. + ''; + }; + image.contents = mkOption { + type = listOf package; + default = []; + description = '' + Top level paths in the container. + ''; + }; + image.rawConfig = mkOption { + type = attrsOf unspecified; + default = {}; + description = '' + This is a low-level fallback for when a container option has not + been modeled in the Arion module system. + + This attribute set does not have an appropriate merge function. + Please use the specific image options instead. + + Run-time configuration of the container. A full list of the + options are available at in the Docker Image Specification + v1.2.0. + ''; + }; + image.command = mkOption { + type = listOf str; + default = []; + description = '' + ''; + }; + }; + config = { + build.image = pkgs.dockerTools.buildLayeredImage { + inherit (config.image) + name + contents + ; + config = config.image.rawConfig; + }; + 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; + }; +} diff --git a/src/nix/modules/service/nixos-init.nix b/src/nix/modules/service/nixos-init.nix index 2b37db8..f248403 100644 --- a/src/nix/modules/service/nixos-init.nix +++ b/src/nix/modules/service/nixos-init.nix @@ -23,7 +23,7 @@ in ../nixos/container-systemd.nix (pkgs.path + "/nixos/modules/profiles/minimal.nix") ]; - service.command = [ "${config.nixos.build.toplevel}/init" ]; + image.command = [ "${config.nixos.build.toplevel}/init" ]; service.environment.container = "docker"; service.volumes = [ "/sys/fs/cgroup:/sys/fs/cgroup:ro"