about summary refs log tree commit diff
path: root/nixos/modules/virtualisation/ec2-data.nix
diff options
context:
space:
mode:
authorTanner Doshier <git@doshitan.com>2016-02-19 11:49:31 -0600
committerTanner Doshier <git@doshitan.com>2016-02-25 20:11:49 -0600
commit4e5ef470a7131cd825850b67bea6b148c08359c2 (patch)
tree4e9d7aa8f46a44df47aa5762b6c5313c011c2ddc /nixos/modules/virtualisation/ec2-data.nix
parentb9db67d8e255d86ea70e4015f4bf08e9c45ec99a (diff)
downloadnixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar.gz
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar.bz2
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar.lz
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar.xz
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.tar.zst
nixlib-4e5ef470a7131cd825850b67bea6b148c08359c2.zip
ec2-data: ensure providing a SSH host key is actually optional
27016659046a8f8e7b4fd61ecbceaf9f5e306258 broke this.
Diffstat (limited to 'nixos/modules/virtualisation/ec2-data.nix')
-rw-r--r--nixos/modules/virtualisation/ec2-data.nix24
1 files changed, 13 insertions, 11 deletions
diff --git a/nixos/modules/virtualisation/ec2-data.nix b/nixos/modules/virtualisation/ec2-data.nix
index bee262612680..db3dd9949c12 100644
--- a/nixos/modules/virtualisation/ec2-data.nix
+++ b/nixos/modules/virtualisation/ec2-data.nix
@@ -43,18 +43,20 @@ with lib;
 
             mkdir -m 0755 -p /etc/ssh
 
-            key="$(sed 's/|/\n/g; s/SSH_HOST_DSA_KEY://; t; d' $userData)"
-            key_pub="$(sed 's/SSH_HOST_DSA_KEY_PUB://; t; d' $userData)"
-            if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_dsa_key ]; then
-                (umask 077; echo "$key" > /etc/ssh/ssh_host_dsa_key)
-                echo "$key_pub" > /etc/ssh/ssh_host_dsa_key.pub
-            fi
+            if [ -s "$userData" ]; then
+              key="$(sed 's/|/\n/g; s/SSH_HOST_DSA_KEY://; t; d' $userData)"
+              key_pub="$(sed 's/SSH_HOST_DSA_KEY_PUB://; t; d' $userData)"
+              if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_dsa_key ]; then
+                  (umask 077; echo "$key" > /etc/ssh/ssh_host_dsa_key)
+                  echo "$key_pub" > /etc/ssh/ssh_host_dsa_key.pub
+              fi
 
-            key="$(sed 's/|/\n/g; s/SSH_HOST_ED25519_KEY://; t; d' $userData)"
-            key_pub="$(sed 's/SSH_HOST_ED25519_KEY_PUB://; t; d' $userData)"
-            if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_ed25519_key ]; then
-                (umask 077; echo "$key" > /etc/ssh/ssh_host_ed25519_key)
-                echo "$key_pub" > /etc/ssh/ssh_host_ed25519_key.pub
+              key="$(sed 's/|/\n/g; s/SSH_HOST_ED25519_KEY://; t; d' $userData)"
+              key_pub="$(sed 's/SSH_HOST_ED25519_KEY_PUB://; t; d' $userData)"
+              if [ -n "$key" -a -n "$key_pub" -a ! -e /etc/ssh/ssh_host_ed25519_key ]; then
+                  (umask 077; echo "$key" > /etc/ssh/ssh_host_ed25519_key)
+                  echo "$key_pub" > /etc/ssh/ssh_host_ed25519_key.pub
+              fi
             fi
           '';