Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion in buildImage with default tag #132

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading