nixpkgs/pkgs/build-support/fetchdocker/default.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

82 lines
1.8 KiB
Nix

{
stdenv,
lib,
coreutils,
bash,
gnutar,
writeText,
}:
let
stripScheme = builtins.replaceStrings [ "https://" "http://" ] [ "" "" ];
stripNixStore = s: lib.removePrefix "${builtins.storeDir}/" 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 paths to collapse possible double slashes
repoTag0 = builtins.toString (/. + "/${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;
};
}