Skip to content

Commit

Permalink
feat: add flag to disable containers tooling (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackheaven committed Aug 12, 2024
1 parent 25e48e9 commit 7fa15b0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/modules/containers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ let
mkDerivation = cfg: nix2container.nix2container.buildImage {
name = cfg.name;
tag = cfg.version;
initializeNixDatabase = true;
initializeNixDatabase = cfg.isDev;
nixUid = lib.toInt uid;
nixGid = lib.toInt gid;

copyToRoot = [
copyToRoot = lib.lists.optionals cfg.isDev [
(pkgs.buildEnv {
name = "devenv-container-root";
paths = [
Expand All @@ -123,7 +123,7 @@ let
})
];

perms = [
perms = lib.lists.optionals cfg.isDev [
{
path = mkTmp;
regex = "/tmp";
Expand All @@ -135,17 +135,19 @@ let
}
];

config = {
Entrypoint = cfg.entrypoint;
User = "${user}";
WorkingDir = "${homeDir}";
Env = lib.mapAttrsToList
(name: value:
"${name}=${toString value}"
)
config.env ++ [ "HOME=${homeDir}" "USER=${user}" ];
Cmd = [ cfg.startupCommand ];
};
config = lib.attrsets.mergeAttrsList [
{
User = "${user}";
WorkingDir = "${homeDir}";
}
(if cfg.isDev then {
Env = lib.mapAttrsToList (name: value: "${name}=${toString value}")
config.env ++ [ "HOME=${homeDir}" "USER=${user}" ];
Entrypoint = cfg.entrypoint;
Cmd = [ cfg.startupCommand ];
} else
{ })
];
};

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

isDev = lib.mkOption {
type = types.bool;
default = true;
description = "Is a development containers (add tools).";
};

derivation = lib.mkOption {
type = types.package;
internal = true;
Expand Down

0 comments on commit 7fa15b0

Please sign in to comment.