From 99b9db0c70eadaf6323e9ae6e43fabab5858fb30 Mon Sep 17 00:00:00 2001 From: Edgar Lee <122112154+elpdt852@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:30:09 +0800 Subject: [PATCH] Fix infinite recursion in buildImage with default tag --- modules/flake/examples.nix | 1 - package.nix | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/modules/flake/examples.nix b/modules/flake/examples.nix index c642e0f..2a9065b 100644 --- a/modules/flake/examples.nix +++ b/modules/flake/examples.nix @@ -8,7 +8,6 @@ examples = rec { hello = buildImage { name = "ghcr.io/pdtpartners/hello"; - tag = "latest"; config = { entrypoint = ["${pkgs.hello}/bin/hello"]; }; diff --git a/package.nix b/package.nix index eea3463..9ff1f5c 100644 --- a/package.nix +++ b/package.nix @@ -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 @@ -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;