summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2019-01-28 14:44:41 +0100
committerAntoine Eiche <lewo@abesis.fr>2019-01-28 14:44:41 +0100
commit849460f8789943b9758c6e782d1cc0bb8a8bd950 (patch)
tree45a3a7f3c724eed8eb0d5bb40ae01b901cb52e5a /nixos
parent2858b35100c8cc350b8f162227fbb767c8c2173e (diff)
downloadnixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar.gz
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar.bz2
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar.lz
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar.xz
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.tar.zst
nixpkgs-849460f8789943b9758c6e782d1cc0bb8a8bd950.zip
nova-image: add amazon-init module to the nova image
This allows the VM to provide a `configuration.nix` file to the VM.

The test doesn't work in sandbox because it needs Internet (however it
works interactively).
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/virtualisation/nova-config.nix3
-rw-r--r--nixos/tests/nova-image.nix36
2 files changed, 32 insertions, 7 deletions
diff --git a/nixos/modules/virtualisation/nova-config.nix b/nixos/modules/virtualisation/nova-config.nix
index fef20d498e9..c944fff96a8 100644
--- a/nixos/modules/virtualisation/nova-config.nix
+++ b/nixos/modules/virtualisation/nova-config.nix
@@ -8,6 +8,7 @@ with lib;
     ../profiles/headless.nix
     # The Openstack Metadata service exposes data on an EC2 API also.
     ./ec2-data.nix
+    ./amazon-init.nix
   ];
 
   config = {
@@ -32,7 +33,7 @@ with lib;
       path = [ pkgs.wget ];
       description = "Fetch Metadata on startup";
       wantedBy = [ "multi-user.target" ];
-      before = [ "apply-ec2-data.service" ];
+      before = [ "apply-ec2-data.service" "amazon-init.service"];
       wants = [ "network-online.target" ];
       after = [ "network-online.target" ];
       script =
diff --git a/nixos/tests/nova-image.nix b/nixos/tests/nova-image.nix
index 488649b70e6..7934ab31c70 100644
--- a/nixos/tests/nova-image.nix
+++ b/nixos/tests/nova-image.nix
@@ -19,12 +19,11 @@ let
       ];
     }).config.system.build.novaImage;
 
-in
-  makeEc2Test {
-    name         = "nova-ec2-metadata";
+in {
+  metadata = makeEc2Test {
+    name = "nova-ec2-metadata";
     inherit image;
-    sshPublicKey = snakeOilPublicKey; # That's right folks! My user's key is also the host key!
-
+    sshPublicKey = snakeOilPublicKey;
     userData = ''
       SSH_HOST_ED25519_KEY_PUB:${snakeOilPublicKey}
       SSH_HOST_ED25519_KEY:${replaceStrings ["\n"] ["|"] snakeOilPrivateKey}
@@ -57,4 +56,29 @@ in
       $machine->start;
       $machine->waitForFile("/etc/ec2-metadata/user-data");
     '';
-  }
+  };
+
+  userdata = makeEc2Test {
+    name = "nova-ec2-metadata";
+    inherit image;
+    sshPublicKey = snakeOilPublicKey;
+    userData = ''
+      { pkgs, ... }:
+      {
+        imports = [
+          <nixpkgs/nixos/modules/virtualisation/nova-config.nix>
+          <nixpkgs/nixos/modules/testing/test-instrumentation.nix>
+          <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
+        ];
+        environment.etc.testFile = {
+          text = "whoa";
+        };
+      }
+    '';
+    script = ''
+      $machine->start;
+      $machine->waitForFile("/etc/testFile");
+      $machine->succeed("cat /etc/testFile | grep -q 'whoa'");
+    '';
+  };
+}