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 11, 2024
1 parent 26fd708 commit dc299a3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/modules/containers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ let
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 @@ -125,7 +125,7 @@ let
})
];

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

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 @@ -243,6 +248,12 @@ let
"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 dc299a3

Please sign in to comment.