2019-03-13 18:00:58 +01:00
|
|
|
{ config, lib, pkgs, docker, ... }:
|
2019-03-05 21:26:00 +01:00
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
2019-03-05 22:08:26 +01:00
|
|
|
let
|
2019-03-12 20:33:56 +01:00
|
|
|
cfg = config.docker;
|
2019-03-05 22:08:26 +01:00
|
|
|
in {
|
2019-03-12 20:33:56 +01:00
|
|
|
options.docker = {
|
|
|
|
|
registry.url = mkOption {
|
|
|
|
|
description = "Default registry url where images are published";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "";
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
images = mkOption {
|
|
|
|
|
description = "Attribute set of docker images that should be published";
|
|
|
|
|
type = types.attrsOf (types.submodule ({ name, config, ... }: {
|
|
|
|
|
options = {
|
|
|
|
|
image = mkOption {
|
|
|
|
|
description = "Docker image to publish";
|
|
|
|
|
type = types.nullOr types.package;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
name = mkOption {
|
|
|
|
|
description = "Desired docker image name";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = builtins.unsafeDiscardStringContext config.image.imageName;
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
tag = mkOption {
|
|
|
|
|
description = "Desired docker image tag";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = builtins.unsafeDiscardStringContext config.image.imageTag;
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
registry = mkOption {
|
|
|
|
|
description = "Docker registry url where image is published";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = cfg.registry.url;
|
|
|
|
|
};
|
2019-03-05 22:08:26 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
path = mkOption {
|
|
|
|
|
description = "Full docker image path";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default =
|
|
|
|
|
if config.registry != ""
|
|
|
|
|
then "${config.registry}/${config.name}:${config.tag}"
|
|
|
|
|
else "${config.name}:${config.tag}";
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
};
|
2019-03-12 20:33:56 +01:00
|
|
|
}));
|
|
|
|
|
default = {};
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
export = mkOption {
|
|
|
|
|
description = "List of images to export";
|
|
|
|
|
type = types.listOf (types.package);
|
|
|
|
|
default = [];
|
|
|
|
|
};
|
2019-03-13 18:00:58 +01:00
|
|
|
|
|
|
|
|
copyScript = mkOption {
|
|
|
|
|
description = "Image copy script";
|
|
|
|
|
type = types.package;
|
|
|
|
|
default = docker.copyDockerImages {
|
|
|
|
|
dest = "docker://${cfg.registry.url}";
|
|
|
|
|
images = cfg.export;
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
};
|
|
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
config = {
|
|
|
|
|
_module.features = ["docker"];
|
|
|
|
|
|
2019-03-13 18:00:58 +01:00
|
|
|
_module.args.docker = import ../lib/docker.nix { inherit lib pkgs; };
|
|
|
|
|
|
2019-03-13 18:01:33 +01:00
|
|
|
submodules.defaults = [{
|
|
|
|
|
features = [ "docker" ];
|
|
|
|
|
default = { config, name, ... }: {
|
|
|
|
|
# propagate registry options
|
|
|
|
|
docker.registry = cfg.registry;
|
|
|
|
|
};
|
|
|
|
|
}];
|
|
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
docker.export = mkMerge [
|
|
|
|
|
(mapAttrsToList (_: i: i.image)
|
|
|
|
|
(filterAttrs (_: i: i.registry != null) config.docker.images))
|
|
|
|
|
|
|
|
|
|
# passthru of docker exported images if passthru is enabled on submodule
|
|
|
|
|
# and submodule has docker module loaded
|
|
|
|
|
(flatten (mapAttrsToList (_: submodule:
|
|
|
|
|
optionals
|
|
|
|
|
(submodule.passthru.enable && (elem "docker" submodule.config._module.features))
|
|
|
|
|
submodule.config.docker.export
|
|
|
|
|
) config.submodules.instances))
|
|
|
|
|
];
|
|
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
}
|