2021-05-13 17:27:08 -04:00
|
|
|
{
|
2022-04-02 12:40:35 -07:00
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
docker,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
with lib; let
|
|
|
|
|
cfg = config.docker;
|
|
|
|
|
in {
|
|
|
|
|
imports = [./base.nix];
|
2019-10-06 21:30:20 +02:00
|
|
|
|
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";
|
2022-04-02 12:40:35 -07:00
|
|
|
type = types.attrsOf (types.submodule ({
|
|
|
|
|
name,
|
|
|
|
|
config,
|
|
|
|
|
...
|
|
|
|
|
}: {
|
2019-03-12 20:33:56 +01:00
|
|
|
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
|
|
|
}));
|
2022-04-02 12:40:35 -07:00
|
|
|
default = {};
|
2019-03-12 20:33:56 +01:00
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
export = mkOption {
|
|
|
|
|
description = "List of images to export";
|
2019-03-13 18:02:31 +01:00
|
|
|
type = types.listOf types.package;
|
2022-04-02 12:40:35 -07:00
|
|
|
default = [];
|
2019-03-12 20:33:56 +01:00
|
|
|
};
|
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 = {
|
2019-10-06 21:30:20 +02:00
|
|
|
# define docker feature
|
2022-04-02 12:40:35 -07:00
|
|
|
_m.features = ["docker"];
|
2019-03-13 18:00:58 +01:00
|
|
|
|
2019-10-06 21:30:20 +02:00
|
|
|
# propagate docker options if docker feature is enabled
|
2022-04-02 12:40:35 -07:00
|
|
|
_m.propagate = [
|
|
|
|
|
{
|
|
|
|
|
features = ["docker"];
|
2022-04-02 13:43:57 -07:00
|
|
|
module = _: {
|
2022-04-02 12:40:35 -07:00
|
|
|
# propagate registry options
|
|
|
|
|
docker.registry = cfg.registry;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
];
|
2019-03-13 18:01:33 +01:00
|
|
|
|
2020-04-04 18:23:25 +07:00
|
|
|
# pass docker library as param
|
2022-04-02 12:40:35 -07:00
|
|
|
_module.args.docker = import ../lib/docker {inherit lib pkgs;};
|
2020-04-04 18:23:25 +07:00
|
|
|
|
2019-10-06 21:36:13 +02:00
|
|
|
# list of exported docker images
|
2022-04-02 12:40:35 -07:00
|
|
|
docker.export =
|
|
|
|
|
mapAttrsToList (_: i: i.image)
|
2019-10-06 21:36:13 +02:00
|
|
|
(filterAttrs (_: i: i.registry != null) config.docker.images);
|
2019-03-12 20:33:56 +01:00
|
|
|
};
|
2019-03-05 21:26:00 +01:00
|
|
|
}
|