Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
github = "9p4";
githubId = 17993169;
};
"will-lol" = {
name = "William Bradshaw";
email = "[email protected]";
github = "will-lol";
githubId = 65345408;
};
aabccd021 = {
name = "Muhamad Abdurahman";
email = "[email protected]";
Expand Down
51 changes: 49 additions & 2 deletions modules/programs/docker-cli.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ let
jsonFormat = pkgs.formats.json { };
in
{
meta.maintainers = [ lib.maintainers.friedrichaltheide ];
meta.maintainers = [
lib.maintainers.friedrichaltheide
lib.hm.maintainers.will-lol
];

options.programs.docker-cli = {
enable = mkEnableOption "management of docker client config";
Expand All @@ -29,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 <name> in programs.docker-cli.contexts.<name>). 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:
<https://docs.docker.com/engine/manage-resources/contexts/
'';
};

settings = mkOption {
type = jsonFormat.type;
default = { };
Expand Down Expand Up @@ -59,7 +94,19 @@ in
"${cfg.configDir}/config.json" = {
source = jsonFormat.generate "config.json" cfg.settings;
};
};
}
// lib.mapAttrs' (
n: ctx:
let
path = "${cfg.configDir}/contexts/meta/${builtins.hashString "sha256" ctx.Name}/meta.json";
in
{
name = path;
value = {
source = jsonFormat.generate "config.json" (ctx);
};
}
) cfg.contexts;
};
};
}
1 change: 1 addition & 0 deletions tests/modules/programs/docker-cli/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
docker-cli = ./example-config.nix;
docker-cli-empty-config = ./empty-config.nix;
docker-cli-contexts = ./example-contexts.nix;
}
11 changes: 11 additions & 0 deletions tests/modules/programs/docker-cli/example-contexts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Endpoints": {
"docker": {
"Host": "unix://example2"
}
},
"Metadata": {
"Description": "example1"
},
"Name": "example"
}
36 changes: 36 additions & 0 deletions tests/modules/programs/docker-cli/example-contexts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
config,
...
}:
{
programs.docker-cli = {
enable = true;

configDir = ".docker2";

contexts = {
example = {
Metadata = {
Description = "example1";
};
Endpoints = {
docker = {
Host = "unix://example2";
};
};
};
};
};

nmt.script =
let
cfgDocker = config.programs.docker-cli;
configTestPath = "home-files/${cfgDocker.configDir}/contexts/meta/50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c/meta.json";
in
''
assertPathNotExists home-files/.docker/config.json
assertFileExists ${configTestPath}
assertFileContent ${configTestPath} \
${./example-contexts.json}
'';
}
Loading