3
0
Fork 0
forked from mirrors/nixpkgs

dockerTools: Add example of using NixOS' etc

This commit is contained in:
Robert Hensing 2021-12-03 12:23:23 +00:00
parent 56c283e5c8
commit 9b2af8673b
2 changed files with 32 additions and 0 deletions

View file

@ -413,5 +413,10 @@ import ./make-test-python.nix ({ pkgs, ... }: {
"docker rmi layered-image-with-path",
)
with subtest("etc"):
docker.succeed("${examples.etc} | docker load")
docker.succeed("docker run --rm etc | grep localhost")
docker.succeed("docker image rm etc:latest")
'';
})

View file

@ -559,6 +559,33 @@ rec {
includeStorePaths = false;
};
etc =
let
inherit (pkgs) lib;
nixosCore = (lib.nixos.core ({ config, modules, ... }: {
imports = [ pkgs.nixosModule modules.etc ];
environment.etc."hosts" = {
text = ''
127.0.0.1 localhost
::1 localhost
'';
mode = "0456";
};
}));
in pkgs.dockerTools.streamLayeredImage {
name = "etc";
tag = "latest";
enableFakechroot = true;
fakeRootCommands = ''
mkdir -p /etc
${nixosCore.config.system.build.etcActivationCommands}
'';
config.Cmd = pkgs.writeScript "etc-cmd" ''
#!${pkgs.busybox}/bin/sh
${pkgs.busybox}/bin/cat /etc/hosts
'';
};
# Example export of the bash image
exportBash = pkgs.dockerTools.exportImage { fromImage = bash; };