mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 07:53:19 +00:00
Merge pull request #175474 from hercules-ci/issue-148456-dockerTools-example-etc
dockerTools: Add example of using NixOS' etc
This commit is contained in:
commit
9d92bee00a
@ -419,5 +419,10 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
|||||||
"docker rmi layered-image-with-path",
|
"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")
|
||||||
|
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
@ -9,6 +9,16 @@
|
|||||||
|
|
||||||
{ pkgs, buildImage, buildLayeredImage, fakeNss, pullImage, shadowSetup, buildImageWithNixDb, pkgsCross }:
|
{ pkgs, buildImage, buildLayeredImage, fakeNss, pullImage, shadowSetup, buildImageWithNixDb, pkgsCross }:
|
||||||
|
|
||||||
|
let
|
||||||
|
nixosLib = import ../../../nixos/lib {
|
||||||
|
# Experimental features need testing too, but there's no point in warning
|
||||||
|
# about it, so we enable the feature flag.
|
||||||
|
featureFlags.minimalModules = {};
|
||||||
|
};
|
||||||
|
evalMinimalConfig = module: nixosLib.evalModules { modules = [ module ]; };
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
# 1. basic example
|
# 1. basic example
|
||||||
bash = buildImage {
|
bash = buildImage {
|
||||||
@ -582,6 +592,37 @@ rec {
|
|||||||
includeStorePaths = false;
|
includeStorePaths = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
etc =
|
||||||
|
let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
nixosCore = (evalMinimalConfig ({ config, ... }: {
|
||||||
|
imports = [
|
||||||
|
pkgs.pkgsModule
|
||||||
|
../../../nixos/modules/system/etc/etc.nix
|
||||||
|
];
|
||||||
|
environment.etc."some-config-file" = {
|
||||||
|
text = ''
|
||||||
|
127.0.0.1 localhost
|
||||||
|
::1 localhost
|
||||||
|
'';
|
||||||
|
# For executables:
|
||||||
|
# mode = "0755";
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
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/some-config-file
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
# Example export of the bash image
|
# Example export of the bash image
|
||||||
exportBash = pkgs.dockerTools.exportImage { fromImage = bash; };
|
exportBash = pkgs.dockerTools.exportImage { fromImage = bash; };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user