Add build.extendedInfo to service
To let services write to the x-arion section.
This commit is contained in:
parent
15386e5145
commit
7cf74389ad
6 changed files with 53 additions and 2 deletions
|
@ -21,6 +21,7 @@ let
|
||||||
./modules/composition/docker-compose.nix
|
./modules/composition/docker-compose.nix
|
||||||
./modules/composition/host-environment.nix
|
./modules/composition/host-environment.nix
|
||||||
./modules/composition/images.nix
|
./modules/composition/images.nix
|
||||||
|
./modules/composition/service-info.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
argsModule = {
|
argsModule = {
|
||||||
|
|
|
@ -10,6 +10,7 @@ let
|
||||||
builtinModules = [
|
builtinModules = [
|
||||||
argsModule
|
argsModule
|
||||||
./modules/service/docker-compose-service.nix
|
./modules/service/docker-compose-service.nix
|
||||||
|
./modules/service/extended-info.nix
|
||||||
./modules/service/host-store.nix
|
./modules/service/host-store.nix
|
||||||
./modules/service/host.nix
|
./modules/service/host.nix
|
||||||
./modules/service/image.nix
|
./modules/service/image.nix
|
||||||
|
|
|
@ -26,7 +26,11 @@ in
|
||||||
};
|
};
|
||||||
docker-compose.raw = lib.mkOption {
|
docker-compose.raw = lib.mkOption {
|
||||||
type = lib.types.attrs;
|
type = lib.types.attrs;
|
||||||
description = "Nested attribute set that will be turned into the docker-compose.yaml file, using Nix's toJSON builtin.";
|
description = "Attribute set that will be turned into the docker-compose.yaml file, using Nix's toJSON builtin.";
|
||||||
|
};
|
||||||
|
docker-compose.extended = lib.mkOption {
|
||||||
|
type = lib.types.attrs;
|
||||||
|
description = "Attribute set that will be turned into the x-arion section of the docker-compose.yaml file.";
|
||||||
};
|
};
|
||||||
docker-compose.services = lib.mkOption {
|
docker-compose.services = lib.mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
|
@ -47,6 +51,7 @@ in
|
||||||
docker-compose.raw = {
|
docker-compose.raw = {
|
||||||
version = "3.4";
|
version = "3.4";
|
||||||
services = lib.mapAttrs (k: c: c.config.build.service) config.docker-compose.evaluatedServices;
|
services = lib.mapAttrs (k: c: c.config.build.service) config.docker-compose.evaluatedServices;
|
||||||
|
x-arion = config.docker-compose.extended;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,6 @@ in
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
build.imagesToLoad = lib.attrValues serviceImages;
|
build.imagesToLoad = lib.attrValues serviceImages;
|
||||||
docker-compose.raw.x-arion.images = config.build.imagesToLoad;
|
docker-compose.extended.images = config.build.imagesToLoad;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
24
src/nix/modules/composition/service-info.nix
Normal file
24
src/nix/modules/composition/service-info.nix
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
Adds extendedInfo from services to the Docker Compose file.
|
||||||
|
|
||||||
|
This contains fields that are not in Docker Compose schema.
|
||||||
|
*/
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
serviceInfo =
|
||||||
|
lib.mapAttrs getInfo (
|
||||||
|
lib.filterAttrs filterFunction config.docker-compose.evaluatedServices
|
||||||
|
);
|
||||||
|
|
||||||
|
filterFunction = _serviceName: service:
|
||||||
|
# shallow equality suffices for emptiness test
|
||||||
|
builtins.attrNames service.config.build.extendedInfo != [];
|
||||||
|
|
||||||
|
getInfo = _serviceName: service: service.config.build.extendedInfo;
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
docker-compose.extended.serviceInfo = serviceInfo;
|
||||||
|
};
|
||||||
|
}
|
20
src/nix/modules/service/extended-info.nix
Normal file
20
src/nix/modules/service/extended-info.nix
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption;
|
||||||
|
inherit (lib.types) attrsOf unspecified;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
build.extendedInfo = mkOption {
|
||||||
|
type = attrsOf unspecified;
|
||||||
|
description = ''
|
||||||
|
Information about a service to include in the Docker Compose file,
|
||||||
|
but that will not be used by the <code>docker-compose</code> command
|
||||||
|
itself.
|
||||||
|
|
||||||
|
It will be inserted in <code>x-arion.serviceInfo.<service.name></code>.
|
||||||
|
'';
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue