1{
2 lib,
3 bash,
4 coreutils,
5 curl,
6 fetchFromGitHub,
7 gawk,
8 gnugrep,
9 gnused,
10 installShellFiles,
11 makeWrapper,
12 nix-update-script,
13 python3,
14 stdenv,
15 udevCheckHook,
16 util-linux,
17}:
18
19stdenv.mkDerivation rec {
20 pname = "amazon-ec2-utils";
21 version = "2.2.0";
22
23 src = fetchFromGitHub {
24 owner = "amazonlinux";
25 repo = "amazon-ec2-utils";
26 tag = "v${version}";
27 hash = "sha256-plTBh2LAXkYVSxN0IZJQuPr7QxD7+OAqHl/Zl8JPCmg=";
28 };
29
30 strictDeps = true;
31
32 nativeBuildInputs = [
33 installShellFiles
34 makeWrapper
35 udevCheckHook
36 ];
37
38 buildInputs = [
39 bash
40 python3
41 ];
42
43 installPhase = ''
44 mkdir $out
45
46 for file in {ebsnvme-id,ec2-metadata,ec2nvme-nsid,ec2udev-vbd}; do
47 install -D -m 755 -t $out/bin "$file"
48 done
49
50 wrapProgram $out/bin/ec2-metadata \
51 --prefix PATH : ${
52 lib.makeBinPath [
53 coreutils
54 curl
55 util-linux
56 ]
57 }
58
59 wrapProgram $out/bin/ec2nvme-nsid \
60 --prefix PATH : ${
61 lib.makeBinPath [
62 coreutils
63 ]
64 }
65
66 wrapProgram $out/bin/ec2udev-vbd \
67 --prefix PATH : ${
68 lib.makeBinPath [
69 coreutils
70 gnugrep
71 gnused
72 ]
73 }
74
75 for file in *.rules; do
76 install -D -m 644 -t $out/lib/udev/rules.d "$file"
77 done
78
79 substituteInPlace $out/lib/udev/rules.d/{51-ec2-hvm-devices,70-ec2-nvme-devices}.rules \
80 --replace-fail /usr/sbin $out/bin
81
82 substituteInPlace $out/lib/udev/rules.d/53-ec2-read-ahead-kb.rules \
83 --replace-fail /bin/awk ${gawk}/bin/awk
84
85 installManPage doc/*.8
86 '';
87
88 outputs = [
89 "out"
90 "man"
91 ];
92
93 doInstallCheck = true;
94
95 # We can't run `ec2-metadata` since it calls IMDS even with `--help`.
96 installCheckPhase = ''
97 runHook preInstallCheck
98
99 $out/bin/ebsnvme-id --help
100
101 runHook postInstallCheck
102 '';
103
104 passthru = {
105 updateScript = nix-update-script { };
106 };
107
108 meta = {
109 description = "Contains a set of utilities and settings for Linux deployments in EC2";
110 homepage = "https://github.com/amazonlinux/amazon-ec2-utils";
111 license = lib.licenses.mit;
112 maintainers = with lib.maintainers; [
113 anthonyroussel
114 arianvp
115 ketzacoatl
116 thefloweringash
117 ];
118 };
119}