This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.nix
213 lines (194 loc) · 7.43 KB
/
config.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Implementing https://github.com/moby/moby/blob/master/image/spec/v1.2.md in
# NixOS modules
{ pkgs ? import <nixpkgs> {}
, configuration
}:
let
baseModule = { config, lib, ... }:
with lib;
{ options =
let
healthcheck = {
Test = mkOption {
type = types.nullOr (types.listOf types.string);
default = null;
description = ''
The test to perform to check that the container is healthy. The
options are:
- [] : inherit healthcheck from base image
- ["NONE"] : disable healthcheck
- ["CMD", arg1, arg2, ...] : exec arguments directly
- ["CMD-SHELL", command] : run command with system's default shell
The test command should exit with a status of 0 if the container
is healthy, or with 1 if it is unhealthy.
'';
};
Interval = mkOption {
type = types.nullOr (types.int);
default = null;
description = ''
Number of nanoseconds to wait between probe attempts.
'';
};
Timeout = mkOption {
type = types.nullOr (types.int);
default = null;
description = ''
Number of nanoseconds to wait before considering the check to
have hung.
'';
};
Retries = mkOption {
type = types.nullOr (types.int);
default = null;
description = ''
The number of consecutive failures needed to consider a
container as unhealthy.
'';
};
};
in
{ User = mkOption {
type = types.nullOr types.string;
default = null;
description = ''
The username or UID which the process in the container should run
as. This acts as a default value to use when the value is not
specified when creating a container.
All of the following are valid:
user
uid
user:group
uid:gid
uid:group
user:gid
If group/gid is not specified, the default group and supplementary
groups of the given user/uid in /etc/passwd from the container are
applied.
'';
};
Memory = mkOption {
type = types.nullOr types.int;
default = null;
description = ''
Memory limit (in bytes). This acts as a default value to use when
the value is not specified when creating a container.
'';
};
MemorySwap = mkOption {
type = types.nullOr types.int;
default = null;
description = ''
Total memory usage (memory + swap); set to -1 to disable swap.
This acts as a default value to use when the value is not
specified when creating a container.
'';
};
CpuShares = mkOption {
type = types.nullOr types.int;
default = null;
description = ''
CPU shares (relative weight vs. other containers). This acts as a
default value to use when the value is not specified when creating
a container.
'';
};
ExposedPorts = mkOption {
type = types.nullOr (types.listOf types.string);
default = null;
description = ''
A list of ports to expose from a container running this image.
Here is an example:
[ "8080" "53/udp" "2356/tcp" ]
Its keys can be in the format of:
"<port>/tcp" "<port>/udp" "<port>"
with the default protocol being "tcp" if not specified. These
values act as defaults and are merged with any specified when
creating a container.
'';
};
Env = mkOption {
type = types.nullOr (types.attrsOf types.str);
default = null;
description = ''
Entries are in the format of VARNAME="var value". These values act
as defaults and are merged with any specified when creating a
container.
'';
};
Entrypoint = mkOption {
type = types.nullOr (types.listOf types.string);
default = null;
description = ''
A list of arguments to use as the command to execute when the
container starts. This value acts as a default and is replaced by
an entrypoint specified when creating a container.
'';
};
Cmd = mkOption {
type = types.nullOr (types.listOf types.string);
default = null;
description = ''
Default arguments to the entry point of the container. These
values act as defaults and are replaced with any specified when
creating a container. If an Entrypoint value is not specified,
then the first entry of the Cmd array should be interpreted as the
executable to run.
'';
};
Healthcheck = mkOption {
type = types.nullOr (types.submodule { options = healthcheck; });
default = null;
description = ''
A test to perform to determine whether the container is healthy.
Here is an example:
{
"Test": [
"CMD-SHELL",
"/usr/bin/check-health localhost"
],
"Interval": 30000000000,
"Timeout": 10000000000,
"Retries": 3
}
The object has the following fields.
'';
};
Volumes = mkOption {
type = types.nullOr (types.listOf types.string);
default = null;
description = ''
A list of directories which should be created as data volumes in a
container running this image.
Here is an example:
[
"/var/my-app-data/"
"/etc/some-config.d/"
]
'';
};
WorkingDir = mkOption {
type = types.nullOr (types.string);
default = null;
description = ''
Sets the current working directory of the entry point process in
the container. This value acts as a default and is replaced by a
working directory specified when creating a container.
'';
};
};
};
eval = pkgs.lib.evalModules { modules = [ baseModule configuration ]; };
in
builtins.mapAttrs
(n: v: if n == "ExposedPorts" || n == "Volumes"
then builtins.listToAttrs (builtins.map (x: { name = x; value = {}; }) v)
else if n == "Healthcheck"
then pkgs.lib.filterAttrs (n2: v2: n2 != "_module" && v2 != null) v
else if n == "Env"
then pkgs.lib.mapAttrsToList (n: v: "${n}=${v}") v
else v)
(pkgs.lib.filterAttrs
(n: v: n != "_module" && # remove internal representation
v != null # remove unassigned values
) eval.config)