Add default network with name = project.name

This commit is contained in:
Robert Hensing 2022-06-09 01:24:38 +02:00
parent ca785e548b
commit 037c87837f
3 changed files with 49 additions and 8 deletions

View file

@ -22,6 +22,30 @@ Attribute set that will be turned into the docker-compose.yaml file, using Nix's
Type:: attribute set Type:: attribute set
No Default:: {blank} No Default:: {blank}
No Example:: {blank}
== enableDefaultNetwork
Whether to define the default network:
```nix
networks.default = {
name = config.project.name;
};
```
[discrete]
=== details
Type:: boolean
Default::
+
----
true
----
No Example:: {blank} No Example:: {blank}
== host.nixStorePrefix == host.nixStorePrefix
@ -79,12 +103,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks-top-level-elemen
=== details === details
Type:: lazy attribute set of submodules Type:: lazy attribute set of submodules
Default:: No Default:: {blank}
+
----
{}
----
No Example:: {blank} No Example:: {blank}

View file

@ -1,5 +1,9 @@
{ {
"networks": {}, "networks": {
"default": {
"name": "unit-test-data"
}
},
"services": { "services": {
"webserver": { "webserver": {
"command": [ "command": [

View file

@ -21,13 +21,31 @@ in
description = '' description = ''
${dockerComposeRef "networks-top-level-element"} ${dockerComposeRef "networks-top-level-element"}
''; '';
default = {}; };
enableDefaultNetwork = mkOption {
type = types.bool;
description = ''
Whether to define the default network:
```nix
networks.default = {
name = config.project.name;
};
```
'';
default = true;
}; };
}; };
config = { config = {
networks = optionalAttrs config.enableDefaultNetwork {
default = {
name = config.project.name;
};
};
docker-compose.raw.networks = docker-compose.raw.networks =
lib.mapAttrs (k: v: v.out) config.networks; lib.mapAttrs (k: v: v.out) config.networks;