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

amazon-ec2-metadata-mock: init at 1.12.0 #365690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
44 changes: 44 additions & 0 deletions pkgs/by-name/am/amazon-ec2-metadata-mock/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
lib,
buildGoModule,
fetchFromGitHub,
nix-update-script,
versionCheckHook,
}:

buildGoModule rec {
pname = "amazon-ec2-metadata-mock";
version = "1.12.0";

src = fetchFromGitHub {
owner = "aws";
repo = "amazon-ec2-metadata-mock";
rev = "refs/tags/v${version}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rev = "refs/tags/v${version}";
tag = "v${version}";

The tag parameter was recently added to make this shorter.

LGTM otherwise.

hash = "sha256-8X6LBGo496fG0Chhvg3jAaUF6mp8psCzHd+Es75z27Y=";
};

vendorHash = "sha256-jRJX4hvfRuhR5TlZe7LsXaOlUCwmQGem2QKlX3vuk8c=";

subPackages = [ "cmd/" ];

postBuild = ''
mv "$GOPATH/bin/cmd" "$GOPATH/bin/$mainProgram"
'';
Comment on lines +22 to +26
Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to enumerate each cmd/{command} in subPackages to automatically get the binary in $out/bin?

Copy link
Member Author

@arianvp arianvp Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one package named cmd. They don't have a cmd/ec2-metadata-mock folder as would be idiomatic. This is why I need this workaround.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it.

$ tree /nix/store/r2fcrxh07csw9fs1cld9px13ydvj577m-amazon-ec2-metadata-mock-1.12.0
/nix/store/r2fcrxh07csw9fs1cld9px13ydvj577m-amazon-ec2-metadata-mock-1.12.0
└── bin
    └── cmd

Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see why we have to do this. The source layout is cursed.

amazon-ec2-metadata-mock/
└── cmd/
    └── amazon-ec2-metadata-mock.go

We can only do cmd for subpackages since each folder is its own package. Since there's no ec2-metadata-mock folder, we can't do cmd/ec2-metadata-mock. Upstream would need this layout instead:

amazon-ec2-metadata-mock/
└── cmd/
    └── ec2-metadata-mock/
        └── *.go

Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to upstream (since this is breaking Go convention): aws/amazon-ec2-metadata-mock#224

Assuming that gets merged, this should be good (with the source hash fixed):

pkgs/by-name/am/amazon-ec2-metadata-mock/package.nix

{
  lib,
  buildGoModule,
  fetchFromGitHub,
  nix-update-script,
  versionCheckHook,
}:

buildGoModule rec {
  pname = "amazon-ec2-metadata-mock";
  version = "1.12.1";

  src = fetchFromGitHub {
    owner = "aws";
    repo = "amazon-ec2-metadata-mock";
    tag = "v${version}";
    hash = lib.fakeHash;
  };

  vendorHash = "sha256-jRJX4hvfRuhR5TlZe7LsXaOlUCwmQGem2QKlX3vuk8c=";

  subPackages = [ "cmd/ec2-metadata-mock" ];

  doInstallCheck = true;

  nativeInstallCheckInputs = [ versionCheckHook ];

  versionCheckProgram = "${builtins.placeholder "out"}/bin/ec2-metadata-mock";

  versionCheckProgramArg = "--version";

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = {
    description = "Tool to simulate Amazon EC2 instance metadata";
    homepage = "https://github.com/aws/amazon-ec2-metadata-mock";
    license = lib.licenses.asl20;
    mainProgram = "ec2-metadata-mock";
    maintainers = with lib.maintainers; [ arianvp ];
  };
}

Edit: Added versionCheckProgram = "${builtins.placeholder "out"}/bin/ec2-metadata-mock";.

Copy link
Contributor

@commiterate commiterate Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build output:

$ nix-build -A amazon-ec2-metadata-mock                                           
this derivation will be built:
  /nix/store/nflp1z2xmcv31bxgwwx99k0qrk5jilv6-amazon-ec2-metadata-mock-1.12.0.drv
building '/nix/store/nflp1z2xmcv31bxgwwx99k0qrk5jilv6-amazon-ec2-metadata-mock-1.12.0.drv'...
Using versionCheckHook
Running phase: unpackPhase
unpacking source archive /nix/store/crycqj02168xghr6npqvjs3kg3xkikgs-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Running phase: buildPhase
Building subPackage ./cmd/ec2-metadata-mock
Running phase: checkPhase
?       github.com/aws/amazon-ec2-metadata-mock/cmd/ec2-metadata-mock   [no test files]
Running phase: installPhase
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0
shrinking /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin/ec2-metadata-mock
checking for references to /build/ in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0...
patching script interpreter paths in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0
stripping (with command strip and flags -S -p) in  /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin
Running phase: installCheckPhase
Executing versionCheckPhase
Successfully managed to find version 1.12.0 in the output of the command /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin/ec2-metadata-mock --version
2024/12/17 18:25:56 Warning: Failed to find home directory due to error: exec: "getent": executable file not found in $PATH
v1.12.0
Finished versionCheckPhase
no Makefile or custom installCheckPhase, doing nothing
/nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0

Looks like there's some pesky dependency on getent causing this line:

2024/12/17 18:25:56 Warning: Failed to find home directory due to error: exec: "getent": executable file not found in $PATH

https://github.com/aws/amazon-ec2-metadata-mock/blob/98afdd52d3344779e2174448db8e5a37973ab574/pkg/config/config.go#L43-L50

Seems to be for config file handling.

Copy link
Contributor

@commiterate commiterate Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getent dependency is because they're using mitchellh/go-homedir which does this:

https://github.com/mitchellh/go-homedir/blob/af06845cf3004701891bf4fdb884bfe4920b3727/homedir.go#L114

They need to migrate off that package since it's archived and they should be using the built-in os package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue upstream for removing the mitchellh/go-homedir dependency.

aws/amazon-ec2-metadata-mock#225

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like upstream is already reviewing the 2 PRs (they've approved the GitHub Actions workflow runs for them). Might be merged pretty quickly.


mainProgram = "ec2-metadata-mock";
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
versionCheckProgram = "${placeholder "out"}/bin/${mainProgram}";

passthru = {
updateScript = nix-update-script { };
};

meta = {
description = "A tool to simulate Amazon EC2 instance metadata";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "A tool to simulate Amazon EC2 instance metadata";
description = "Tool to simulate Amazon EC2 instance metadata";

homepage = "https://github.com/aws/amazon-ec2-metadata-mock";
license = lib.licenses.asl20;
inherit mainProgram;
maintainers = with lib.maintainers; [ arianvp ];
};
}
Loading