Skip to content

Commit dc299a3

Browse files
committed
feat: add flag to disable containers tooling (#1367)
1 parent 26fd708 commit dc299a3

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/modules/containers.nix

+22-11
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ let
101101
nix2container.nix2container.buildImage {
102102
name = cfg.name;
103103
tag = cfg.version;
104-
initializeNixDatabase = true;
104+
initializeNixDatabase = cfg.isDev;
105105
nixUid = lib.toInt uid;
106106
nixGid = lib.toInt gid;
107107

108-
copyToRoot = [
108+
copyToRoot = lib.lists.optionals cfg.isDev [
109109
(pkgs.buildEnv {
110110
name = "devenv-container-root";
111111
paths =
@@ -125,7 +125,7 @@ let
125125
})
126126
];
127127

128-
perms = [{
128+
perms = lib.lists.optionals cfg.isDev [{
129129
path = mkTmp;
130130
regex = "/tmp";
131131
mode = "1777";
@@ -135,14 +135,19 @@ let
135135
gname = "root";
136136
}];
137137

138-
config = {
139-
Entrypoint = cfg.entrypoint;
140-
User = "${user}";
141-
WorkingDir = "${homeDir}";
142-
Env = lib.mapAttrsToList (name: value: "${name}=${toString value}")
143-
config.env ++ [ "HOME=${homeDir}" "USER=${user}" ];
144-
Cmd = [ cfg.startupCommand ];
145-
};
138+
config = lib.attrsets.mergeAttrsList [
139+
{
140+
User = "${user}";
141+
WorkingDir = "${homeDir}";
142+
}
143+
(if cfg.isDev then {
144+
Env = lib.mapAttrsToList (name: value: "${name}=${toString value}")
145+
config.env ++ [ "HOME=${homeDir}" "USER=${user}" ];
146+
Entrypoint = cfg.entrypoint;
147+
Cmd = [ cfg.startupCommand ];
148+
} else
149+
{ })
150+
];
146151
};
147152

148153
# <registry> <args>
@@ -243,6 +248,12 @@ let
243248
"Set to true when the environment is building this container.";
244249
};
245250

251+
isDev = lib.mkOption {
252+
type = types.bool;
253+
default = true;
254+
description = "Is a development containers (add tools).";
255+
};
256+
246257
derivation = lib.mkOption {
247258
type = types.package;
248259
internal = true;

0 commit comments

Comments
 (0)