From c58b11d229f63a85ee1d05fc9940a20fa2b73975 Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Tue, 12 Jun 2018 17:56:13 -0700 Subject: dockerTools.pullImage: control OS and architecture --- doc/functions.xml | 24 ++++++++++++++++++++++-- pkgs/build-support/docker/default.nix | 7 ++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/functions.xml b/doc/functions.xml index c23f6aa25967..2a9cc44d5c5b 100644 --- a/doc/functions.xml +++ b/doc/functions.xml @@ -649,6 +649,8 @@ merge:"diff3" imageDigest = "sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b"; finalImageTag = "1.11"; sha256 = "0mqjy3zq2v6rrhizgb9nvhczl87lcfphq9601wcprdika2jz7qh8"; + os = "linux"; + arch = "x86_64"; } @@ -664,9 +666,15 @@ merge:"diff3" imageDigest specifies the digest of the image to be - downloaded. Skopeo can be used to get the digest of an image + downloaded. Skopeo can be used to get the digest of an image, with its + inspect subcommand. Since a given imageName + may transparently refer to a manifest list of images which support + multiple architectures and/or operating systems, supply the `--override-os` + and `--override-arch` arguments to specify exactly which image you + want. By default it will match the OS and architecture of the host the + command is run on. - $ skopeo inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest' + $ nix-shell --packages skopeo jq --command "skopeo --override-os linux --override-arch x86_64 inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest'" sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b This argument is required. @@ -686,6 +694,18 @@ merge:"diff3" This argument is required. + + + os, if specified, is the operating system of the fetched image. + By default it's linux. + + + + + arch, if specified, is the cpu architecture of the fetched image. + By default it's x86_64. + + diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index 950c0c86a6e4..bc79f9ff12fd 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -36,10 +36,11 @@ rec { in { imageName # To find the digest of an image, you can use skopeo: - # skopeo inspect docker://docker.io/nixos/nix:1.11 | jq -r '.Digest' - # sha256:20d9485b25ecfd89204e843a962c1bd70e9cc6858d65d7f5fadc340246e2116b + # see doc/functions.xml , imageDigest , sha256 + , os ? "linux" + , arch ? "x86_64" # This used to set a tag to the pulled image , finalImageTag ? "latest" , name ? fixName "docker-image-${imageName}-${finalImageTag}.tar" @@ -59,7 +60,7 @@ rec { sourceURL = "docker://${imageName}@${imageDigest}"; destNameTag = "${imageName}:${finalImageTag}"; } '' - skopeo copy "$sourceURL" "docker-archive://$out:$destNameTag" + skopeo --override-os ${os} --override-arch ${arch} copy "$sourceURL" "docker-archive://$out:$destNameTag" ''; # We need to sum layer.tar, not a directory, hence tarsum instead of nix-hash. -- cgit 1.4.1