1{ stdenv
2, lib
3, fetchFromGitHub
4, bash
5, python3
6, installShellFiles
7, gawk
8, curl
9}:
10
11stdenv.mkDerivation rec {
12 pname = "amazon-ec2-utils";
13 version = "2.1.0";
14
15 src = fetchFromGitHub {
16 owner = "amazonlinux";
17 repo = "amazon-ec2-utils";
18 rev = "refs/tags/v${version}";
19 hash = "sha256-Yr6pVwyvyVGV4xrjL7VFSkRH8d1w8VLPMTVjXfneJUM=";
20 };
21
22 outputs = [ "out" "man" ];
23
24 strictDeps = true;
25
26 buildInputs = [
27 bash
28 python3
29 ];
30
31 nativeBuildInputs = [
32 installShellFiles
33 ];
34
35 installPhase = ''
36 install -Dm755 -t $out/bin/ ebsnvme-id
37 install -Dm755 -t $out/bin/ ec2-metadata
38 install -Dm755 -t $out/bin/ ec2nvme-nsid
39 install -Dm755 -t $out/bin/ ec2udev-vbd
40
41 install -Dm644 -t $out/lib/udev/rules.d/ 51-ec2-hvm-devices.rules
42 install -Dm644 -t $out/lib/udev/rules.d/ 51-ec2-xen-vbd-devices.rules
43 install -Dm644 -t $out/lib/udev/rules.d/ 53-ec2-read-ahead-kb.rules
44 install -Dm644 -t $out/lib/udev/rules.d/ 70-ec2-nvme-devices.rules
45 install -Dm644 -t $out/lib/udev/rules.d/ 60-cdrom_id.rules
46
47 installManPage doc/*.8
48 '';
49
50 postFixup = ''
51 for i in $out/etc/udev/rules.d/*.rules $out/lib/udev/rules.d/*.rules ; do
52 substituteInPlace "$i" \
53 --replace '/usr/sbin' "$out/bin" \
54 --replace '/bin/awk' '${gawk}/bin/awk'
55 done
56
57 substituteInPlace "$out/bin/ec2-metadata" \
58 --replace 'curl' '${curl}/bin/curl'
59 '';
60
61 doInstallCheck = true;
62
63 # We cannot run
64 # ec2-metadata --help
65 # because it actually checks EC2 metadata even if --help is given
66 # so it won't work in the test sandbox.
67 installCheckPhase = ''
68 $out/bin/ebsnvme-id --help
69 '';
70
71 meta = with lib; {
72 changelog = "https://github.com/amazonlinux/amazon-ec2-utils/releases/tag/v${version}";
73 description = "Contains a set of utilities and settings for Linux deployments in EC2";
74 homepage = "https://github.com/amazonlinux/amazon-ec2-utils";
75 license = licenses.mit;
76 maintainers = with maintainers; [ ketzacoatl thefloweringash anthonyroussel ];
77 };
78}