-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
base: master
Are you sure you want to change the base?
Conversation
34d6661
to
e95eb9a
Compare
e95eb9a
to
b545763
Compare
subPackages = [ "cmd/" ]; | ||
|
||
postBuild = '' | ||
mv "$GOPATH/bin/cmd" "$GOPATH/bin/$mainProgram" | ||
''; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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";
.
There was a problem hiding this comment.
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
Seems to be for config file handling.
There was a problem hiding this comment.
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:
They need to migrate off that package since it's archived and they should be using the built-in os
package.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to upstream: aws/amazon-ec2-metadata-mock#226
There was a problem hiding this comment.
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.
I'd prefer to get this merged as is as I need it :D |
}; | ||
|
||
meta = { | ||
description = "A tool to simulate Amazon EC2 instance metadata"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = "A tool to simulate Amazon EC2 instance metadata"; | |
description = "Tool to simulate Amazon EC2 instance metadata"; |
src = fetchFromGitHub { | ||
owner = "aws"; | ||
repo = "amazon-ec2-metadata-mock"; | ||
rev = "refs/tags/v${version}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rev = "refs/tags/v${version}"; | |
tag = "v${version}"; |
The tag parameter was recently added to make this shorter.
LGTM otherwise.
A tool to simulate Amazon EC2 instance metadata.
I want to use this for better EC2 image tests.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.