nixos: Add ec2-metadata-fetcher.nix file

To share the metadata fetcher script between ec2 and Openstack images.
This commit is contained in:
Antoine Eiche
2019-02-11 20:58:45 +01:00
parent 78acac050f
commit 933da6de91
3 changed files with 38 additions and 43 deletions
+8 -21
View File
@@ -8,7 +8,13 @@
with lib;
let cfg = config.ec2; in
let
cfg = config.ec2;
metadataFetcher = import ./ec2-metadata-fetcher.nix {
targetRoot = "$targetRoot/";
wgetExtraOptions = "-q";
};
in
{
imports = [ ../profiles/headless.nix ./ec2-data.nix ./amazon-init.nix ];
@@ -61,26 +67,7 @@ let cfg = config.ec2; in
# Nix operations.
boot.initrd.postMountCommands =
''
metaDir=$targetRoot/etc/ec2-metadata
mkdir -m 0755 -p "$metaDir"
echo "getting EC2 instance metadata..."
if ! [ -e "$metaDir/ami-manifest-path" ]; then
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
${metadataFetcher}
diskNr=0
diskForUnionfs=