summary refs log tree commit diff
diff options
context:
space:
mode:
authorMathias Schreck <schreck.mathias@googlemail.com>2018-06-29 19:20:55 +0200
committerProfpatsch <mail@profpatsch.de>2018-07-06 15:15:09 +0200
commit39e678e24e38f1f374eaf5463b424ebdf75df9af (patch)
tree844b2e334d4faa51c4dd7a1cd2127f02446f49b8
parent588dbd714e007dc7d71aedc20f0f658a99d472ec (diff)
downloadnixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar.gz
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar.bz2
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar.lz
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar.xz
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.tar.zst
nixpkgs-39e678e24e38f1f374eaf5463b424ebdf75df9af.zip
dockerTools.buildImage: add option to use nix output hash as tag
-rw-r--r--doc/functions.xml2
-rw-r--r--nixos/doc/manual/release-notes/rl-1809.xml6
-rw-r--r--pkgs/build-support/docker/default.nix13
3 files changed, 17 insertions, 4 deletions
diff --git a/doc/functions.xml b/doc/functions.xml
index 746ef7131f8..c23f6aa2596 100644
--- a/doc/functions.xml
+++ b/doc/functions.xml
@@ -521,7 +521,7 @@ merge:"diff3"
     <callout arearefs='ex-dockerTools-buildImage-2'>
      <para>
       <varname>tag</varname> specifies the tag of the resulting image. By
-      default it's <literal>latest</literal>.
+      default it's <literal>null</literal>, which indicates that the nix output hash will be used as tag.
      </para>
     </callout>
     <callout arearefs='ex-dockerTools-buildImage-3'>
diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml
index 51e77d24a74..13b244e12f8 100644
--- a/nixos/doc/manual/release-notes/rl-1809.xml
+++ b/nixos/doc/manual/release-notes/rl-1809.xml
@@ -127,6 +127,12 @@ $ nix-instantiate -E '(import &lt;nixpkgsunstable&gt; {}).gitFull'
      Make sure the key file is accessible to the daemon.
     </para>
    </listitem>
+   <listitem>
+    <para>
+      <varname>dockerTools.buildImage</varname> now uses <literal>null</literal> as default value for <varname>tag</varname>,
+      which indicates that the nix output hash will be used as tag.
+    </para>
+   </listitem>
   </itemizedlist>
  </section>
 
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix
index b01f0b72272..ff45cf81d7e 100644
--- a/pkgs/build-support/docker/default.nix
+++ b/pkgs/build-support/docker/default.nix
@@ -420,8 +420,8 @@ rec {
   buildImage = args@{
     # Image name.
     name,
-    # Image tag.
-    tag ? "latest",
+    # Image tag, when null then the nix output hash will be used.
+    tag ? null,
     # Parent image, to append to.
     fromImage ? null,
     # Name of the parent image; will be read from the image otherwise.
@@ -471,12 +471,19 @@ rec {
         buildInputs = [ jshon pigz coreutils findutils jq ];
         # Image name and tag must be lowercase
         imageName = lib.toLower name;
-        imageTag = lib.toLower tag;
+        imageTag = if tag == null then "" else lib.toLower tag;
         inherit fromImage baseJson;
         layerClosure = writeReferencesToFile layer;
         passthru.buildArgs = args;
         passthru.layer = layer;
       } ''
+        ${lib.optionalString (tag == null) ''
+          outName="$(basename "$out")"
+          outHash=$(echo "$outName" | cut -d - -f 1)
+
+          imageTag=$outHash
+        ''}
+
         # Print tar contents:
         # 1: Interpreted as relative to the root directory
         # 2: With no trailing slashes on directories