From 990e5ce6791ff1f497a61280a82eb66e3789e0e9 Mon Sep 17 00:00:00 2001 From: will Date: Sun, 28 Sep 2025 09:45:58 +1000 Subject: [PATCH] docker-cli: add docker contexts support Adds docker-cli.contexts support. This allows declarative configuration of [docker contexts](https://docs.docker.com/engine/manage-resources/contexts/). --- modules/programs/docker-cli.nix | 46 ++++++++++++++++++- tests/modules/programs/docker-cli/default.nix | 1 + .../programs/docker-cli/example-contexts.json | 11 +++++ .../programs/docker-cli/example-contexts.nix | 36 +++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/modules/programs/docker-cli/example-contexts.json create mode 100644 tests/modules/programs/docker-cli/example-contexts.nix diff --git a/modules/programs/docker-cli.nix b/modules/programs/docker-cli.nix index 668ef7f7c..937b91013 100644 --- a/modules/programs/docker-cli.nix +++ b/modules/programs/docker-cli.nix @@ -32,6 +32,38 @@ in ''; }; + contexts = mkOption { + type = lib.types.attrsOf ( + lib.types.submodule ( + { name, config, ... }: + { + freeformType = jsonFormat.type; + options = { + Name = mkOption { + type = lib.types.str; + readOnly = true; + description = "Name of the Docker context. Defaults to the attribute name (the in programs.docker-cli.contexts.). Overriding requires lib.mkForce."; + }; + }; + config.Name = name; + } + ) + ); + default = { }; + example = lib.literalExpression '' + { + example = { + Metadata = { Description = "example1"; }; + Endpoints.docker.Host = "unix://example2"; + }; + } + ''; + description = '' + Attribute set of Docker context configurations. Each attribute name becomes the context Name; overriding requires lib.mkForce. See: +