Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to disable containers tooling (#1367) #1375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 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 @@ -116,14 +116,16 @@ let

maxLayers = cfg.maxLayers;

layers = [
(nix2container.nix2container.buildLayer {
perms = map mkPerm (mkMultiHome (homeRoots cfg));
copyToRoot = mkMultiHome (homeRoots cfg);
})
];
layers =
if cfg.isDev
then [
(nix2container.nix2container.buildLayer {
perms = map mkPerm (mkMultiHome (homeRoots cfg));
copyToRoot = mkMultiHome (homeRoots cfg);
})
] else homeRoots cfg;

perms = [
perms = lib.lists.optionals cfg.isDev [
{
path = mkTmp;
regex = "/tmp";
Expand All @@ -135,17 +137,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 [
{
Entrypoint = cfg.entrypoint;
Cmd = [ cfg.startupCommand ];
Env = lib.mapAttrsToList (name: value: "${name}=${toString value}")
config.env ++ lib.lists.optionals cfg.isDev [ "HOME=${homeDir}" "USER=${user}" ];
}
(if cfg.isDev then {
User = "${user}";
WorkingDir = "${homeDir}";
} else
{ })
];
};

# <registry> <args>
Expand Down Expand Up @@ -239,6 +243,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