2024-06-30 08:16:52 +00:00
|
|
|
{
|
|
|
|
stdenv,
|
|
|
|
lib,
|
|
|
|
coreutils,
|
|
|
|
bash,
|
|
|
|
gnutar,
|
|
|
|
writeText,
|
|
|
|
}:
|
2024-05-02 00:46:19 +00:00
|
|
|
let
|
|
|
|
stripScheme =
|
2024-06-30 08:16:52 +00:00
|
|
|
builtins.replaceStrings
|
|
|
|
[
|
|
|
|
"https://"
|
|
|
|
"http://"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
""
|
|
|
|
""
|
|
|
|
];
|
|
|
|
stripNixStore = s: lib.removePrefix "${builtins.storeDir}/" s;
|
2024-05-02 00:46:19 +00:00
|
|
|
in
|
2024-06-30 08:16:52 +00:00
|
|
|
{
|
|
|
|
name,
|
|
|
|
registry ? "https://registry-1.docker.io/v2/",
|
|
|
|
repository ? "library",
|
|
|
|
imageName,
|
|
|
|
tag,
|
|
|
|
imageLayers,
|
|
|
|
imageConfig,
|
|
|
|
image ? "${stripScheme registry}/${repository}/${imageName}:${tag}",
|
2024-05-02 00:46:19 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# 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.
|
2024-06-30 08:16:52 +00:00
|
|
|
assert null == lib.findFirst (c: "/" == c) null (lib.stringToCharacters repository);
|
|
|
|
assert null == lib.findFirst (c: "/" == c) null (lib.stringToCharacters imageName);
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
# Abuse paths to collapse possible double slashes
|
|
|
|
repoTag0 = builtins.toString (/. + "/${stripScheme registry}/${repository}/${imageName}");
|
|
|
|
repoTag1 = lib.removePrefix "/" repoTag0;
|
|
|
|
|
|
|
|
layers = builtins.map stripNixStore imageLayers;
|
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
manifest = writeText "manifest.json" (
|
|
|
|
builtins.toJSON [
|
|
|
|
{
|
|
|
|
Config = stripNixStore imageConfig;
|
|
|
|
Layers = layers;
|
2024-05-02 00:46:19 +00:00
|
|
|
RepoTags = [ "${repoTag1}:${tag}" ];
|
2024-06-30 08:16:52 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
repositories = writeText "repositories" (
|
|
|
|
builtins.toJSON {
|
2024-05-02 00:46:19 +00:00
|
|
|
${repoTag1} = {
|
|
|
|
${tag} = lib.last layers;
|
|
|
|
};
|
2024-06-30 08:16:52 +00:00
|
|
|
}
|
|
|
|
);
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
imageFileStorePaths = writeText "imageFileStorePaths.txt" (
|
|
|
|
lib.concatStringsSep "\n" ((lib.unique imageLayers) ++ [ imageConfig ])
|
|
|
|
);
|
2024-05-02 00:46:19 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
2024-06-30 08:16:52 +00:00
|
|
|
builder = ./fetchdocker-builder.sh;
|
2024-05-02 00:46:19 +00:00
|
|
|
buildInputs = [ coreutils ];
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
inherit
|
|
|
|
name
|
|
|
|
imageName
|
|
|
|
repository
|
|
|
|
tag
|
|
|
|
;
|
|
|
|
inherit
|
|
|
|
bash
|
|
|
|
gnutar
|
|
|
|
manifest
|
|
|
|
repositories
|
|
|
|
;
|
2024-05-02 00:46:19 +00:00
|
|
|
inherit imageFileStorePaths;
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit image;
|
|
|
|
};
|
|
|
|
}
|