Skip to content

Commit 7fa15b0

Browse files
committed
feat: add flag to disable containers tooling (#1367)
1 parent 25e48e9 commit 7fa15b0

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/modules/containers.nix

+22-14
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ let
9595
mkDerivation = cfg: nix2container.nix2container.buildImage {
9696
name = cfg.name;
9797
tag = cfg.version;
98-
initializeNixDatabase = true;
98+
initializeNixDatabase = cfg.isDev;
9999
nixUid = lib.toInt uid;
100100
nixGid = lib.toInt gid;
101101

102-
copyToRoot = [
102+
copyToRoot = lib.lists.optionals cfg.isDev [
103103
(pkgs.buildEnv {
104104
name = "devenv-container-root";
105105
paths = [
@@ -123,7 +123,7 @@ let
123123
})
124124
];
125125

126-
perms = [
126+
perms = lib.lists.optionals cfg.isDev [
127127
{
128128
path = mkTmp;
129129
regex = "/tmp";
@@ -135,17 +135,19 @@ let
135135
}
136136
];
137137

138-
config = {
139-
Entrypoint = cfg.entrypoint;
140-
User = "${user}";
141-
WorkingDir = "${homeDir}";
142-
Env = lib.mapAttrsToList
143-
(name: value:
144-
"${name}=${toString value}"
145-
)
146-
config.env ++ [ "HOME=${homeDir}" "USER=${user}" ];
147-
Cmd = [ cfg.startupCommand ];
148-
};
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+
];
149151
};
150152

151153
# <registry> <args>
@@ -239,6 +241,12 @@ let
239241
description = "Set to true when the environment is building this container.";
240242
};
241243

244+
isDev = lib.mkOption {
245+
type = types.bool;
246+
default = true;
247+
description = "Is a development containers (add tools).";
248+
};
249+
242250
derivation = lib.mkOption {
243251
type = types.package;
244252
internal = true;

0 commit comments

Comments
 (0)