Add options below networks

This commit is contained in:
Robert Hensing 2022-06-09 01:21:53 +02:00
parent c8944a2871
commit ca785e548b
6 changed files with 332 additions and 0 deletions

View file

@ -17,6 +17,7 @@ extra-source-files: CHANGELOG.md, README.asciidoc,
src/haskell/testdata/**/*.json
data-files: nix/*.nix
, nix/modules/composition/*.nix
, nix/modules/networks/*.nix
, nix/modules/nixos/*.nix
, nix/modules/service/*.nix
, nix/modules/lib/*.nix

View file

@ -70,6 +70,169 @@ No Default:: {blank}
No Example:: {blank}
== networks
See link:https://docs.docker.com/compose/compose-file/#networks-top-level-element[Docker Compose#networks-top-level-element]
[discrete]
=== details
Type:: lazy attribute set of submodules
Default::
+
----
{}
----
No Example:: {blank}
== networks.<name>.attachable
See link:https://docs.docker.com/compose/compose-file/#attachable[Docker Compose#attachable]
[discrete]
=== details
Type:: boolean
No Default:: {blank}
Example::
+
----
true
----
== networks.<name>.driver
`"none"`, `"host"`, or a platform-specific value.
See link:https://docs.docker.com/compose/compose-file/#driver[Docker Compose#driver]
[discrete]
=== details
Type:: string
No Default:: {blank}
No Example:: {blank}
== networks.<name>.driver_opts
See link:https://docs.docker.com/compose/compose-file/#driver_opts[Docker Compose#driver_opts]
[discrete]
=== details
Type:: lazy attribute set of raw values
No Default:: {blank}
No Example:: {blank}
== networks.<name>.enable_ipv6
Whether we've entered the 21st century yet.
See link:https://docs.docker.com/compose/compose-file/#enable_ipv6[Docker Compose#enable_ipv6]
[discrete]
=== details
Type:: boolean
No Default:: {blank}
No Example:: {blank}
== networks.<name>.external
When `true`, don't create or destroy the network, but assume that it
exists.
See link:https://docs.docker.com/compose/compose-file/#external[Docker Compose#external]
[discrete]
=== details
Type:: boolean
No Default:: {blank}
No Example:: {blank}
== networks.<name>.internal
Achieves "external isolation".
See link:https://docs.docker.com/compose/compose-file/#internal[Docker Compose#internal]
[discrete]
=== details
Type:: boolean
Default::
+
----
false
----
No Example:: {blank}
== networks.<name>.ipam
Manage IP addresses.
See link:https://docs.docker.com/compose/compose-file/#ipam[Docker Compose#ipam]
[discrete]
=== details
Type:: raw value
No Default:: {blank}
No Example:: {blank}
== networks.<name>.labels
Metadata.
See link:https://docs.docker.com/compose/compose-file/#labels[Docker Compose#labels]
[discrete]
=== details
Type:: attribute set of strings
No Default:: {blank}
No Example:: {blank}
== networks.<name>.name
Set a custom name for the network.
It shares a namespace with other projects' networks. `name` is used as-is.
Note the `default` network's default `name` is set to `project.name` by Arion.
See link:https://docs.docker.com/compose/compose-file/#name[Docker Compose#name]
[discrete]
=== details
Type:: string
No Default:: {blank}
No Example:: {blank}
== out.dockerComposeYaml
A derivation that produces a docker-compose.yaml file for this composition.

View file

@ -1,4 +1,5 @@
{
"networks": {},
"services": {
"webserver": {
"command": [

View file

@ -2,6 +2,7 @@
./modules/composition/docker-compose.nix
./modules/composition/host-environment.nix
./modules/composition/images.nix
./modules/composition/networks.nix
./modules/composition/service-info.nix
./modules/composition/composition.nix
]

View file

@ -0,0 +1,35 @@
{ config, lib, ... }:
let
inherit (lib)
mkOption
optionalAttrs
types
;
inherit (import ../../lib.nix { inherit lib; })
dockerComposeRef
;
in
{
options = {
networks = mkOption {
type = types.lazyAttrsOf (types.submoduleWith {
modules = [
../networks/network.nix
];
});
description = ''
${dockerComposeRef "networks-top-level-element"}
'';
default = {};
};
};
config = {
docker-compose.raw.networks =
lib.mapAttrs (k: v: v.out) config.networks;
};
}

View file

@ -0,0 +1,131 @@
{ config, lib, options, ... }:
let
inherit (lib)
mkOption
optionalAttrs
types
;
inherit (import ../../lib.nix { inherit lib; })
dockerComposeRef
;
in
{
options = {
driver = mkOption {
description = ''
`"none"`, `"host"`, or a platform-specific value.
${dockerComposeRef "driver"}
'';
type = types.str;
};
driver_opts = mkOption {
description = ''
${dockerComposeRef "driver_opts"}
'';
type = types.lazyAttrsOf types.raw or types.unspecified;
};
attachable = mkOption {
description = ''
${dockerComposeRef "attachable"}
'';
type = types.bool;
example = true;
};
enable_ipv6 = mkOption {
description = ''
Whether we've entered the 21st century yet.
${dockerComposeRef "enable_ipv6"}
'';
type = types.bool;
};
ipam = mkOption {
# TODO model sub-options
description = ''
Manage IP addresses.
${dockerComposeRef "ipam"}
'';
type = types.raw or types.unspecified;
};
internal = mkOption {
description = ''
Achieves "external isolation".
${dockerComposeRef "internal"}
'';
defaultText = false;
type = types.bool;
};
labels = mkOption {
description = ''
Metadata.
${dockerComposeRef "labels"}
'';
# no list support, because less expressive wrt overriding
type = types.attrsOf types.str;
};
external = mkOption {
description = ''
When `true`, don't create or destroy the network, but assume that it
exists.
${dockerComposeRef "external"}
'';
type = types.bool;
};
name = mkOption {
description = ''
Set a custom name for the network.
It shares a namespace with other projects' networks. `name` is used as-is.
Note the `default` network's default `name` is set to `project.name` by Arion.
${dockerComposeRef "name"}
'';
type = types.str;
};
out = mkOption {
internal = true;
description = ''
This network's contribution to the docker compose yaml file
under the `networks.''${name}` key.
'';
type = lib.types.attrsOf lib.types.raw or lib.types.unspecified;
};
};
config = {
out =
lib.mapAttrs
(k: opt: opt.value)
(lib.filterAttrs
(k: opt: builtins.trace k builtins.trace opt builtins.trace "" opt.isDefined)
{
inherit (options)
driver
driver_opts
attachable
enable_ipv6
ipam
internal
labels
external
name
;
}
);
};
}