summary refs log tree commit diff
path: root/nixos/modules/virtualisation/openstack-metadata-fetcher.nix
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2020-11-18 11:42:32 -0500
committerGraham Christensen <graham@grahamc.com>2020-11-18 11:42:32 -0500
commit21339b41bf60847b0b8880b8ca5ceb2867044bf1 (patch)
treeeff01cbac1307bb04bff101de8668f0b5d81659a /nixos/modules/virtualisation/openstack-metadata-fetcher.nix
parent6625284c397b44bc9518a5a1567c1b5aae455c08 (diff)
downloadnixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar.gz
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar.bz2
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar.lz
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar.xz
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.tar.zst
nixpkgs-21339b41bf60847b0b8880b8ca5ceb2867044bf1.zip
nixos: openstack: have its own metadata fetcher expression
These two APIs have diverged over time and are no longer compatible.
Diffstat (limited to 'nixos/modules/virtualisation/openstack-metadata-fetcher.nix')
-rw-r--r--nixos/modules/virtualisation/openstack-metadata-fetcher.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/openstack-metadata-fetcher.nix b/nixos/modules/virtualisation/openstack-metadata-fetcher.nix
new file mode 100644
index 00000000000..b531787c31a
--- /dev/null
+++ b/nixos/modules/virtualisation/openstack-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
+''