Created
April 25, 2020 21:40
-
-
Save jeremiehuchet/d71d5de5d2a28215f378f5125bfe972f to your computer and use it in GitHub Desktop.
nix function to fetch docker image content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { pkgs }: | |
| { | |
| # fetch docker image content and return path in nix store | |
| # inspired from https://github.com/NixOS/nixpkgs/blob/6dab1b50a63fa6e9dfb9bd9eddd3f5d5c7b055ef/pkgs/build-support/docker/default.nix#L264 | |
| fetchDocker = coordinates: | |
| let | |
| name = "${coordinates.finalImageName}-${coordinates.finalImageTag}"; | |
| result = pkgs.dockerTools.runWithOverlay { | |
| name = "docker-exporter-${name}"; | |
| diskSize = 512; | |
| fromImage = pkgs.dockerTools.pullImage coordinates; | |
| postMount = '' | |
| touch $out/json $out/VERSION | |
| tar -C mnt --hard-dereference --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cf $out/layer.tar . | |
| ''; | |
| }; | |
| in pkgs.runCommandLocal "docker-export-${name}" { } '' | |
| mkdir $out | |
| tar -C $out -xf ${result}/layer.tar | |
| ''; | |
| } |
mped-oticon
commented
Aug 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment