diff --git a/docs/modules/ROOT/partials/NixOSOptions.adoc b/docs/modules/ROOT/partials/NixOSOptions.adoc index 76ad2a4..131bf4f 100644 --- a/docs/modules/ROOT/partials/NixOSOptions.adoc +++ b/docs/modules/ROOT/partials/NixOSOptions.adoc @@ -22,6 +22,30 @@ Attribute set that will be turned into the docker-compose.yaml file, using Nix's Type:: attribute set 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} == host.nixStorePrefix @@ -79,12 +103,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks-top-level-elemen === details Type:: lazy attribute set of submodules -Default:: -+ ----- -{} ----- - +No Default:: {blank} No Example:: {blank} diff --git a/src/haskell/testdata/Arion/NixSpec/arion-compose.json b/src/haskell/testdata/Arion/NixSpec/arion-compose.json index 54e4c24..5f644ac 100644 --- a/src/haskell/testdata/Arion/NixSpec/arion-compose.json +++ b/src/haskell/testdata/Arion/NixSpec/arion-compose.json @@ -1,5 +1,9 @@ { - "networks": {}, + "networks": { + "default": { + "name": "unit-test-data" + } + }, "services": { "webserver": { "command": [ diff --git a/src/nix/modules/composition/networks.nix b/src/nix/modules/composition/networks.nix index 6bbb181..15435d9 100644 --- a/src/nix/modules/composition/networks.nix +++ b/src/nix/modules/composition/networks.nix @@ -21,13 +21,31 @@ in description = '' ${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 = { + networks = optionalAttrs config.enableDefaultNetwork { + default = { + name = config.project.name; + }; + }; + docker-compose.raw.networks = lib.mapAttrs (k: v: v.out) config.networks;