File tree Expand file tree Collapse file tree 4 files changed +83
-1
lines changed
tests/modules/programs/docker-cli Expand file tree Collapse file tree 4 files changed +83
-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+ freeformType = jsonFormat . type ;
39+ }
40+ ) ;
41+ default = { } ;
42+ example = lib . literalExpression ''
43+ {
44+ example = {
45+ Metadata = { Description = "example1"; };
46+ Endpoints.docker.Host = "unix://example2";
47+ };
48+ }
49+ '' ;
50+ description = ''
51+ Attrset of docker context configurations keyed by context name. See:
52+ <https://docs.docker.com/engine/manage-resources/contexts/
53+ '' ;
54+ } ;
55+
3556 settings = mkOption {
3657 type = jsonFormat . type ;
3758 default = { } ;
6283 "${ cfg . configDir } /config.json" = {
6384 source = jsonFormat . generate "config.json" cfg . settings ;
6485 } ;
65- } ;
86+ }
87+ // lib . mapAttrs' (
88+ n : ctx :
89+ let
90+ name = if ctx ? Name then ctx . Name else n ;
91+ path = "${ cfg . configDir } /contexts/meta/${ builtins . hashString "sha256" name } /meta.json" ;
92+ in
93+ {
94+ name = path ;
95+ value = {
96+ source = jsonFormat . generate "config.json" ( ctx // { Name = name ; } ) ;
97+ } ;
98+ }
99+ ) cfg . contexts ;
66100 } ;
67101 } ;
68102}
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