Skip to content

Commit

Permalink
Fix infinite recursion in buildImage with default tag
Browse files Browse the repository at this point in the history
  • Loading branch information
elpdt852 committed Mar 23, 2024
1 parent 2df4682 commit 99b9db0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
1 change: 0 additions & 1 deletion modules/flake/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
examples = rec {
hello = buildImage {
name = "ghcr.io/pdtpartners/hello";
tag = "latest";
config = {
entrypoint = ["${pkgs.hello}/bin/hello"];
};
Expand Down
14 changes: 4 additions & 10 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ let
# The image name when exported. When resolvedByNix is enabled, this is
# treated as just the package name to help identify the nix store path.
name,
# The image tag when exported. By default, this is the hash of the
# derivation outPath.
tag ? null,
# The image tag when exported. By default, this mutable "latest" tag.
tag ? "latest",
# If enabled, the OCI archive will be generated with a special image
# reference in the format of "nix:0/nix/store/*.tar", which is resolvable
# by nix-snapshotter if configured as the CRI image-service without a
Expand Down Expand Up @@ -72,18 +71,13 @@ let
let
imageName = lib.toLower name;

imageTag =
if tag != null then tag
else builtins.head (lib.strings.splitString "-" (baseNameOf image.outPath));

imageRef = if resolvedByNix then "nix:0${image.outPath}" else "${imageName}:${imageTag}";
imageRef = if resolvedByNix then "nix:0${image.outPath}" else "${imageName}:${tag}";

refFlag = lib.optionalString (!resolvedByNix) ''--ref "${imageRef}"'';

in runCommand "nix-image-${baseName}.tar" {
passthru = {
inherit name;
tag = imageTag;
inherit name tag;
# For kubernetes pod spec.
image = imageRef;
copyToRegistry = copyToRegistry image;
Expand Down

0 comments on commit 99b9db0

Please sign in to comment.