summary refs log tree commit diff
path: root/nixos/modules/virtualisation/openstack-config.nix
diff options
context:
space:
mode:
authorAntoine Eiche <lewo@abesis.fr>2019-01-28 15:09:48 +0100
committerAntoine Eiche <lewo@abesis.fr>2019-02-11 20:58:44 +0100
commitd190b204f001d1446807f56eed99a73f8b89e244 (patch)
treea4611c949d4f22b5dce7846382a27b266b212570 /nixos/modules/virtualisation/openstack-config.nix
parent849460f8789943b9758c6e782d1cc0bb8a8bd950 (diff)
downloadnixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar.gz
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar.bz2
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar.lz
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar.xz
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.tar.zst
nixpkgs-d190b204f001d1446807f56eed99a73f8b89e244.zip
Rename `novaImage` to `openstackImage`
People don't necessary know `nova` is related to Openstack (it is a
component of Openstack). So, it is more explicit to call it
`openstackImage`.
Diffstat (limited to 'nixos/modules/virtualisation/openstack-config.nix')
-rw-r--r--nixos/modules/virtualisation/openstack-config.nix69
1 files changed, 69 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/openstack-config.nix b/nixos/modules/virtualisation/openstack-config.nix
new file mode 100644
index 00000000000..7f4799d1719
--- /dev/null
+++ b/nixos/modules/virtualisation/openstack-config.nix
@@ -0,0 +1,69 @@
+{ pkgs, lib, ... }:
+
+with lib;
+
+{
+  imports = [
+    ../profiles/qemu-guest.nix
+    ../profiles/headless.nix
+    # The Openstack Metadata service exposes data on an EC2 API also.
+    ./ec2-data.nix
+    ./amazon-init.nix
+  ];
+
+  config = {
+    fileSystems."/" = {
+      device = "/dev/disk/by-label/nixos";
+      autoResize = true;
+    };
+
+    boot.growPartition = true;
+    boot.kernelParams = [ "console=ttyS0" ];
+    boot.loader.grub.device = "/dev/vda";
+    boot.loader.timeout = 0;
+
+    # Allow root logins
+    services.openssh = {
+      enable = true;
+      permitRootLogin = "prohibit-password";
+      passwordAuthentication = mkDefault false;
+    };
+
+    systemd.services.openstack-init = {
+      path = [ pkgs.wget ];
+      description = "Fetch Metadata on startup";
+      wantedBy = [ "multi-user.target" ];
+      before = [ "apply-ec2-data.service" "amazon-init.service"];
+      wants = [ "network-online.target" ];
+      after = [ "network-online.target" ];
+      script =
+        ''
+          metaDir=/etc/ec2-metadata
+          mkdir -m 0755 -p "$metaDir"
+
+          echo "getting Openstack instance metadata (via EC2 API)..."
+          if ! [ -e "$metaDir/ami-manifest-path" ]; then
+            wget --retry-connrefused -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 --retry-connrefused -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 --retry-connrefused -O "$metaDir/hostname" http://169.254.169.254/1.0/meta-data/hostname
+          fi
+
+          if ! [ -e "$metaDir/public-keys-0-openssh-key" ]; then
+            wget --retry-connrefused -O "$metaDir/public-keys-0-openssh-key" http://169.254.169.254/1.0/meta-data/public-keys/0/openssh-key
+          fi
+        '';
+      restartIfChanged = false;
+      unitConfig.X-StopOnRemoval = false;
+      serviceConfig = {
+        Type = "oneshot";
+        RemainAfterExit = true;
+      };
+    };
+  };
+}