summary refs log tree commit diff
path: root/nixos/modules/virtualisation/amazon-image.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-04 15:42:49 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-04 15:45:54 +0100
commit27016659046a8f8e7b4fd61ecbceaf9f5e306258 (patch)
tree6fc7f6233ccd3b5d9d37970c883bbe0a19ce5e02 /nixos/modules/virtualisation/amazon-image.nix
parent5c72b20ddeaed9cf3698a35760ef0fa5d9ff9e97 (diff)
downloadnixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar.gz
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar.bz2
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar.lz
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar.xz
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.tar.zst
nixpkgs-27016659046a8f8e7b4fd61ecbceaf9f5e306258.zip
Fetch all EC2 metadata / user data in the initrd
Since we're already fetching one datum, we may as well fetch the
others needed by fetch-ec2-data. This also eliminates the dependency
on wget.
Diffstat (limited to 'nixos/modules/virtualisation/amazon-image.nix')
-rw-r--r--nixos/modules/virtualisation/amazon-image.nix16
1 files changed, 14 insertions, 2 deletions
diff --git a/nixos/modules/virtualisation/amazon-image.nix b/nixos/modules/virtualisation/amazon-image.nix
index 2f6a95786a2..a895f66db8e 100644
--- a/nixos/modules/virtualisation/amazon-image.nix
+++ b/nixos/modules/virtualisation/amazon-image.nix
@@ -57,8 +57,7 @@ let cfg = config.ec2; in
     boot.initrd.postMountCommands =
       ''
         metaDir=$targetRoot/etc/ec2-metadata
-        mkdir -m 0755 -p $targetRoot/etc
-        mkdir -m 0700 -p "$metaDir"
+        mkdir -m 0755 -p "$metaDir"
 
         echo "getting EC2 instance metadata..."
 
@@ -66,6 +65,19 @@ let cfg = config.ec2; in
           wget -q -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 -q -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 -q -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
+        fi
+
+        if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
+          wget -q -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
+        fi
+
         diskNr=0
         diskForUnionfs=
         for device in /dev/xvd[abcde]*; do