diff options
author | adisbladis <adisbladis@gmail.com> | 2020-05-02 15:30:43 +0100 |
---|---|---|
committer | adisbladis <adisbladis@gmail.com> | 2020-05-02 15:59:39 +0100 |
commit | fafb1279470026be3fbef5ff0a5f8413cc4aa9d1 (patch) | |
tree | cf91bdcfd7866bd101b655b1b137d1d7dc79d986 /pkgs/build-support/docker | |
parent | 0ce784464065cd288f1599d1525b998ed29f2cfc (diff) | |
download | nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar.gz nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar.bz2 nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar.lz nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar.xz nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.tar.zst nixpkgs-fafb1279470026be3fbef5ff0a5f8413cc4aa9d1.zip |
dockertools: Add a buildLayeredImageWithNixDb function
This is analogous to buildImageWithNixDb but instead uses buildLayeredImage under the hood.
Diffstat (limited to 'pkgs/build-support/docker')
-rw-r--r-- | pkgs/build-support/docker/default.nix | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 28c0d2dfcae..bee6e37cccb 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -32,7 +32,29 @@ }: # WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future. +let + + mkDbExtraCommand = contents: let + contentsList = if builtins.isList contents then contents else [ contents ]; + in '' + echo "Generating the nix database..." + echo "Warning: only the database of the deepest Nix layer is loaded." + echo " If you want to use nix commands in the container, it would" + echo " be better to only have one layer that contains a nix store." + + export NIX_REMOTE=local?root=$PWD + # A user is required by nix + # https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478 + export USER=nobody + ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration + + mkdir -p nix/var/nix/gcroots/docker/ + for i in ${lib.concatStringsSep " " contentsList}; do + ln -s $i nix/var/nix/gcroots/docker/$(basename $i) + done; + ''; +in rec { examples = callPackage ./examples.nix { @@ -874,25 +896,16 @@ rec { # contents. The main purpose is to be able to use nix commands in # the container. # Be careful since this doesn't work well with multilayer. - buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: - let contentsList = if builtins.isList contents then contents else [ contents ]; - in buildImage (args // { - extraCommands = '' - echo "Generating the nix database..." - echo "Warning: only the database of the deepest Nix layer is loaded." - echo " If you want to use nix commands in the container, it would" - echo " be better to only have one layer that contains a nix store." - - export NIX_REMOTE=local?root=$PWD - # A user is required by nix - # https://github.com/NixOS/nix/blob/9348f9291e5d9e4ba3c4347ea1b235640f54fd79/src/libutil/util.cc#L478 - export USER=nobody - ${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration - - mkdir -p nix/var/nix/gcroots/docker/ - for i in ${lib.concatStringsSep " " contentsList}; do - ln -s $i nix/var/nix/gcroots/docker/$(basename $i) - done; - '' + extraCommands; - }); + buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: ( + buildImage (args // { + extraCommands = (mkDbExtraCommand contents) + extraCommands; + }) + ); + + buildLayeredImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }: ( + buildLayeredImage (args // { + extraCommands = (mkDbExtraCommand contents) + extraCommands; + }) + ); + } |