diff --git a/docs/reference/options.md b/docs/reference/options.md index 8589dcbf7..97c04cc36 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -163,6 +163,21 @@ boolean +## containers.\.maxLayers + +The maximum number of layers created when the container is created. + +*Type:* +int + +*Default:* +` 1 ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/containers.nix](https://github.com/cachix/devenv/blob/main/src/modules/containers.nix) + + + ## containers.\.name Name of the container. diff --git a/src/modules/containers.nix b/src/modules/containers.nix index d7a8a51f0..b98bd42c5 100644 --- a/src/modules/containers.nix +++ b/src/modules/containers.nix @@ -21,8 +21,9 @@ let attribute = "containers"; }; shell = mk-shell-bin.lib.mkShellBin { drv = config.shell; nixpkgs = pkgs; }; + bash = "${pkgs.bashInteractive}/bin/bash"; mkEntrypoint = cfg: pkgs.writeScript "entrypoint" '' - #!${pkgs.bash}/bin/bash + #!${bash} export PATH=/bin @@ -31,31 +32,119 @@ let # expand any envvars before exec cmd="`echo "$@"|${pkgs.envsubst}/bin/envsubst`" - ${pkgs.bash}/bin/bash -c "$cmd" + ${bash} -c "$cmd" ''; + user = "user"; + group = "user"; + uid = "1000"; + gid = "1000"; + homeDir = "/env"; + + mkHome = path: (pkgs.runCommand "devenv-container-home" { } '' + mkdir -p $out${homeDir} + cp -R ${path}/* $out${homeDir}/ + ''); + + mkMultiHome = paths: map mkHome paths; + + homeRoots = cfg: ( + if (builtins.typeOf cfg.copyToRoot == "list") + then cfg.copyToRoot + else [ cfg.copyToRoot ] + ); + + mkTmp = (pkgs.runCommand "devenv-container-tmp" { } '' + mkdir -p $out/tmp + ''); + + mkEtc = (pkgs.runCommand "devenv-container-etc" { } '' + mkdir -p $out/etc/pam.d + + echo "root:x:0:0:System administrator:/root:${bash}" > \ + $out/etc/passwd + echo "${user}:x:${uid}:${gid}::${homeDir}:${bash}" >> \ + $out/etc/passwd + + echo "root:!x:::::::" > $out/etc/shadow + echo "${user}:!x:::::::" >> $out/etc/shadow + + echo "root:x:0:" > $out/etc/group + echo "${group}:x:${gid}:" >> $out/etc/group + + cat > $out/etc/pam.d/other <