summaryrefslogtreecommitdiffstats
path: root/nixos/modules/virtualisation/ec2-metadata-fetcher.nix
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2019-02-06 12:16:22 +0100
committerAntoine Eiche <lewo@abesis.fr>2019-02-11 20:58:45 +0100
commit933da6de9110ca208a82fb31a6730cbe9d971600 (patch)
treebde6daed5b8cb26053067195b00455c4752307be /nixos/modules/virtualisation/ec2-metadata-fetcher.nix
parent78acac050ff27eb45332095935ab112de31d065d (diff)
nixos: Add ec2-metadata-fetcher.nix file
To share the metadata fetcher script between ec2 and Openstack images.
Diffstat (limited to 'nixos/modules/virtualisation/ec2-metadata-fetcher.nix')
-rw-r--r--nixos/modules/virtualisation/ec2-metadata-fetcher.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/ec2-metadata-fetcher.nix b/nixos/modules/virtualisation/ec2-metadata-fetcher.nix
new file mode 100644
index 000000000000..b531787c31a2
--- /dev/null
+++ b/nixos/modules/virtualisation/ec2-metadata-fetcher.nix
@@ -0,0 +1,23 @@
+{ targetRoot, wgetExtraOptions }:
+''
+ metaDir=${targetRoot}etc/ec2-metadata
+ mkdir -m 0755 -p "$metaDir"
+
+ echo "getting EC2 instance metadata..."
+
+ if ! [ -e "$metaDir/ami-manifest-path" ]; then
+ wget ${wgetExtraOptions} -O "$metaDir/ami-manifest-path" http://169.254.169.254/1.0/meta-data/ami-manifest-path
+ fi
+
+ if ! [ -e "$metaDir/user-data" ]; then
+ wget ${wgetExtraOptions} -O "$metaDir/user-data" http://169.254.169.254/1.0/user-data && chmod 600 "$metaDir/user-data"
+ fi
+
+ if ! [ -e "$metaDir/hostname" ]; then
+ wget ${wgetExtraOptions} -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
+ fi
+
+ if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
+ wget ${wgetExtraOptions} -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
+ fi
+''