Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 208aedb9715f
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9e4456ce49c1
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 12, 2018

  1. dockerTools.buildImageWithNixDb: simplifications and switch to closur…

    …eInfo
    
    Since Nix 2 is now the stable Nix version, we can use closureInfo
    which simplifies the Nix database initialisation (size and hash are
    included in the "dump").
    nlewo committed Nov 12, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    Mic92 Jörg Thalheim
    Copy the full SHA
    c12f756 View commit details
  2. Merge pull request #49414 from nlewo/pr/buildImageWithNixDb

    dockerTools.buildImageWithNixDb: simplifications and switch to closure info
    nlewo authored Nov 12, 2018
    Copy the full SHA
    9e4456c View commit details
Showing with 6 additions and 29 deletions.
  1. +6 −29 pkgs/build-support/docker/default.nix
35 changes: 6 additions & 29 deletions pkgs/build-support/docker/default.nix
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@
pkgs,
pigz,
nix,
perl,
runCommand,
rsync,
shadow,
@@ -23,6 +22,7 @@
referencesByPopularity,
writeScript,
writeText,
closureInfo
}:

# WARNING: this API is unstable and may be subject to backwards-incompatible changes in the future.
@@ -261,19 +261,6 @@ rec {
${text}
'';

nixRegistration = contents: runCommand "nix-registration" {
buildInputs = [ nix perl ];
# For obtaining the closure of `contents'.
exportReferencesGraph =
let contentsList = if builtins.isList contents then contents else [ contents ];
in map (x: [("closure-" + baseNameOf x) x]) contentsList;
}
''
mkdir $out
printRegistration=1 perl ${pkgs.pathsFromGraph} closure-* > $out/db.dump
perl ${pkgs.pathsFromGraph} closure-* > $out/storePaths
'';

# Create $maxLayers worth of Docker Layers, one layer per store path
# unless there are more paths than $maxLayers. In that case, create
# $maxLayers-1 for the most popular layers, and smush the remainaing
@@ -795,29 +782,19 @@ rec {
# the container.
# Be careful since this doesn't work well with multilayer.
buildImageWithNixDb = args@{ contents ? null, extraCommands ? "", ... }:
buildImage (args // {
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."
# This requires Nix 1.12 or higher
export NIX_REMOTE=local?root=$PWD
${nix}/bin/nix-store --load-db < ${nixRegistration contents}/db.dump
# We fill the store in order to run the 'verify' command that
# generates hash and size of output paths.
# Note when Nix 1.12 is be the stable one, the database dump
# generated by the exportReferencesGraph function will
# contains sha and size. See
# https://github.com/NixOS/nix/commit/c2b0d8749f7e77afc1c4b3e8dd36b7ee9720af4a
storePaths=$(cat ${nixRegistration contents}/storePaths)
echo "Copying everything to /nix/store (will take a while)..."
cp -prd $storePaths nix/store/
${nix}/bin/nix-store --verify --check-contents
${nix}/bin/nix-store --load-db < ${closureInfo {rootPaths = contentsList;}}/registration
mkdir -p nix/var/nix/gcroots/docker/
for i in ${lib.concatStringsSep " " contents}; do
for i in ${lib.concatStringsSep " " contentsList}; do
ln -s $i nix/var/nix/gcroots/docker/$(basename $i)
done;
'' + extraCommands;