dockerTools.buildImageWithNixDb: populate the Nix Db of the image Nix store
Currently, the contents closure is copied to the layer but there is no nix database initialization. If pkgs.nix is added in the contents, nix-store doesn't work because there is no nix database. From the contents of the layer, this commit generates and loads the database in the nix store of the container. This only works if there is no parent layer that already have a nix store (to support several nix layers, we would have to merge nix databases of parent layers). We also add an example to play with the nix store inside the container. Note it seems `more` is a missing dependency of the nix package!
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
# $ nix-build '<nixpkgs>' -A dockerTools.examples.redis
|
||||
# $ docker load < result
|
||||
|
||||
{ pkgs, buildImage, pullImage, shadowSetup }:
|
||||
{ pkgs, buildImage, pullImage, shadowSetup, buildImageWithNixDb }:
|
||||
|
||||
rec {
|
||||
# 1. basic example
|
||||
@@ -83,7 +83,7 @@ rec {
|
||||
};
|
||||
|
||||
# 4. example of pulling an image. could be used as a base for other images
|
||||
nix = pullImage {
|
||||
nixFromDockerHub = pullImage {
|
||||
imageName = "nixos/nix";
|
||||
imageTag = "1.11";
|
||||
# this hash will need change if the tag is updated at docker hub
|
||||
@@ -101,4 +101,17 @@ rec {
|
||||
pkgs.nano
|
||||
];
|
||||
};
|
||||
|
||||
# 5. nix example to play with the container nix store
|
||||
# docker run -it --rm nix nix-store -qR $(nix-build '<nixpkgs>' -A nix)
|
||||
nix = buildImageWithNixDb {
|
||||
name = "nix";
|
||||
contents = [
|
||||
# nix-store -qR uses the 'more' program which is not included in
|
||||
# the pkgs.nix dependencies. We then have to manually get it
|
||||
# from the 'eject' package:/
|
||||
pkgs.eject
|
||||
pkgs.nix
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user