File tree Expand file tree Collapse file tree 4 files changed +93
-1
lines changed
tests/modules/programs/docker-cli Expand file tree Collapse file tree 4 files changed +93
-1
lines changed Original file line number Diff line number Diff line change 3232 '' ;
3333 } ;
3434
35+ contexts = mkOption {
36+ type = lib . types . attrsOf (
37+ lib . types . submodule (
38+ { name , config , ... } :
39+ {
40+ freeformType = jsonFormat . type ;
41+ options = {
42+ Name = mkOption {
43+ type = lib . types . str ;
44+ defaultText = lib . literalExpression "name" ;
45+ description = "Name of the Docker context." ;
46+ } ;
47+ } ;
48+ config . Name = name ;
49+ }
50+ )
51+ ) ;
52+ default = { } ;
53+ example = lib . literalExpression ''
54+ {
55+ example = {
56+ Metadata = { Description = "example1"; };
57+ Endpoints.docker.Host = "unix://example2";
58+ };
59+ }
60+ '' ;
61+ description = ''
62+ Attrset of docker context configurations keyed by context name. See:
63+ <https://docs.docker.com/engine/manage-resources/contexts/
64+ '' ;
65+ } ;
66+
3567 settings = mkOption {
3668 type = jsonFormat . type ;
3769 default = { } ;
6294 "${ cfg . configDir } /config.json" = {
6395 source = jsonFormat . generate "config.json" cfg . settings ;
6496 } ;
65- } ;
97+ }
98+ // lib . mapAttrs' (
99+ n : ctx :
100+ let
101+ path = "${ cfg . configDir } /contexts/meta/${ builtins . hashString "sha256" ctx . Name } /meta.json" ;
102+ in
103+ {
104+ name = path ;
105+ value = {
106+ source = jsonFormat . generate "config.json" ( ctx ) ;
107+ } ;
108+ }
109+ ) cfg . contexts ;
66110 } ;
67111 } ;
68112}
Original file line number Diff line number Diff line change 11{
22 docker-cli = ./example-config.nix ;
33 docker-cli-empty-config = ./empty-config.nix ;
4+ docker-cli-contexts = ./example-contexts.nix ;
45}
Original file line number Diff line number Diff line change 1+ {
2+ "Endpoints" : {
3+ "docker" : {
4+ "Host" : " unix://example2"
5+ }
6+ },
7+ "Metadata" : {
8+ "Description" : " example1"
9+ },
10+ "Name" : " example"
11+ }
Original file line number Diff line number Diff line change 1+ {
2+ config ,
3+ ...
4+ } :
5+ {
6+ programs . docker-cli = {
7+ enable = true ;
8+
9+ configDir = ".docker2" ;
10+
11+ contexts = {
12+ example = {
13+ Metadata = {
14+ Description = "example1" ;
15+ } ;
16+ Endpoints = {
17+ docker = {
18+ Host = "unix://example2" ;
19+ } ;
20+ } ;
21+ } ;
22+ } ;
23+ } ;
24+
25+ nmt . script =
26+ let
27+ cfgDocker = config . programs . docker-cli ;
28+ configTestPath = "home-files/${ cfgDocker . configDir } /contexts/meta/50d858e0985ecc7f60418aaf0cc5ab587f42c2570a884095a9e8ccacd0f6545c/meta.json" ;
29+ in
30+ ''
31+ assertPathNotExists home-files/.docker/config.json
32+ assertFileExists ${ configTestPath }
33+ assertFileContent ${ configTestPath } \
34+ ${ ./example-contexts.json }
35+ '' ;
36+ }
You can’t perform that action at this time.
0 commit comments