summary refs log tree commit diff
path: root/pkgs/build-support/fetchdocker/default.nix
diff options
context:
space:
mode:
authorParnell Springmeyer <parnell@digitalmentat.com>2017-12-01 21:00:52 -0600
committerParnell Springmeyer <parnell@digitalmentat.com>2017-12-01 21:00:52 -0600
commit25865688a729d15dbb2dc21ebd9fbf74e2cffc4b (patch)
tree137ba921eb3a0eeefad4b6edab5c553c7c214a1a /pkgs/build-support/fetchdocker/default.nix
parentfdb8dea0c6440dfa8c6ffa6203ca2a6953fc2f6b (diff)
downloadnixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar.gz
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar.bz2
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar.lz
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar.xz
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.tar.zst
nixpkgs-25865688a729d15dbb2dc21ebd9fbf74e2cffc4b.zip
docker: init fetchdocker nix code for docker2nix
This change adds granular, non-docker daemon docker image fetchers and
a docker image layer compositor to be used in conjunction with the
`docker2nix` utility provided by the `haskellPackages.hocker` package.

This change includes a hackage package version bump and updated sha256
for recent fixes released to `hocker` resulting from formulating this
patch.
Diffstat (limited to 'pkgs/build-support/fetchdocker/default.nix')
-rw-r--r--pkgs/build-support/fetchdocker/default.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/pkgs/build-support/fetchdocker/default.nix b/pkgs/build-support/fetchdocker/default.nix
new file mode 100644
index 00000000000..ae3ae4185e0
--- /dev/null
+++ b/pkgs/build-support/fetchdocker/default.nix
@@ -0,0 +1,61 @@
+{ stdenv, lib, coreutils, bash, gnutar, jq, writeText }:
+let
+  stripScheme =
+    builtins.replaceStrings [ "https://" "http://" ] [ "" "" ];
+  stripNixStore =
+    s: lib.removePrefix "/nix/store/" s;
+in
+{ name
+, registry         ? "https://registry-1.docker.io/v2/"
+, repository       ? "library"
+, imageName
+, tag
+, imageLayers
+, imageConfig
+, image            ? "${stripScheme registry}/${repository}/${imageName}:${tag}"
+}:
+
+# Make sure there are *no* slashes in the repository or container
+# names since we use these to make the output derivation name for the
+# nix-store path.
+assert null == lib.findFirst (c: "/"==c) null (lib.stringToCharacters repository);
+assert null == lib.findFirst (c: "/"==c) null (lib.stringToCharacters imageName);
+
+let
+  # Abuse `builtins.toPath` to collapse possible double slashes
+  repoTag0 = builtins.toString (builtins.toPath "/${stripScheme registry}/${repository}/${imageName}");
+  repoTag1 = lib.removePrefix "/" repoTag0;
+
+  layers = builtins.map stripNixStore imageLayers;
+
+  manifest =
+    writeText "manifest.json" (builtins.toJSON [
+      { Config   = stripNixStore imageConfig;
+        Layers   = layers;
+        RepoTags = [ "${repoTag1}:${tag}" ];
+      }]);
+
+  repositories =
+    writeText "repositories" (builtins.toJSON {
+      "${repoTag1}" = {
+        "${tag}" = lib.last layers;
+      };
+    });
+
+  imageFileStorePaths =
+    writeText "imageFileStorePaths.txt"
+      (lib.concatStringsSep "\n" ((lib.unique imageLayers) ++ [imageConfig]));
+in
+stdenv.mkDerivation {
+  builder     = ./fetchdocker-builder.sh;
+  buildInputs = [ coreutils ];
+  preferLocalBuild = true;
+
+  inherit name imageName repository tag;
+  inherit bash gnutar manifest repositories;
+  inherit imageFileStorePaths;
+
+  passthru = {
+    inherit image;
+  };
+}