about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2018-01-04 21:11:34 +0800
committerGitHub <noreply@github.com>2018-01-04 21:11:34 +0800
commit423dd6cc29b5ada2c927590ed73855b042f4cda2 (patch)
tree2db8ae7f8ae846520edec0d0c884447a6218b8c7
parent450f6b7987b498cfb313fcc67ab82ca0ada3939c (diff)
parent85e507ebeaa1958d04335c38ded126093a1fb409 (diff)
downloadnixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar.gz
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar.bz2
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar.lz
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar.xz
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.tar.zst
nixlib-423dd6cc29b5ada2c927590ed73855b042f4cda2.zip
Merge pull request #33415 from peterhoeg/p/hv
hyperv-daemons: package and nixos module
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/virtualisation/hyperv-guest.nix37
-rw-r--r--pkgs/os-specific/linux/hyperv-daemons/default.nix109
-rw-r--r--pkgs/top-level/all-packages.nix2
4 files changed, 149 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index fdd3bb844c2f..45e4279fecb7 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -746,6 +746,7 @@
   ./virtualisation/lxcfs.nix
   ./virtualisation/lxd.nix
   ./virtualisation/amazon-options.nix
+  ./virtualisation/hyperv-guest.nix
   ./virtualisation/openvswitch.nix
   ./virtualisation/parallels-guest.nix
   ./virtualisation/rkt.nix
diff --git a/nixos/modules/virtualisation/hyperv-guest.nix b/nixos/modules/virtualisation/hyperv-guest.nix
new file mode 100644
index 000000000000..ecd2a8117710
--- /dev/null
+++ b/nixos/modules/virtualisation/hyperv-guest.nix
@@ -0,0 +1,37 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.virtualisation.hypervGuest;
+
+in {
+  options = {
+    virtualisation.hypervGuest = {
+      enable = mkEnableOption "Hyper-V Guest Support";
+    };
+  };
+
+  config = mkIf cfg.enable {
+    environment.systemPackages = [ config.boot.kernelPackages.hyperv-daemons.bin ];
+
+    security.rngd.enable = false;
+
+    # enable hotadding memory
+    services.udev.packages = lib.singleton (pkgs.writeTextFile {
+      name = "hyperv-memory-hotadd-udev-rules";
+      destination = "/etc/udev/rules.d/99-hyperv-memory-hotadd.rules";
+      text = ''
+        ACTION="add", SUBSYSTEM=="memory", ATTR{state}="online"
+      '';
+    });
+
+    systemd = {
+      packages = [ config.boot.kernelPackages.hyperv-daemons.lib ];
+
+      targets.hyperv-daemons = {
+        wantedBy = [ "multi-user.target" ];
+      };
+    };
+  };
+}
diff --git a/pkgs/os-specific/linux/hyperv-daemons/default.nix b/pkgs/os-specific/linux/hyperv-daemons/default.nix
new file mode 100644
index 000000000000..f89747dc200d
--- /dev/null
+++ b/pkgs/os-specific/linux/hyperv-daemons/default.nix
@@ -0,0 +1,109 @@
+{ stdenv, lib, python, kernel, makeWrapper, writeText }:
+
+let
+  daemons = stdenv.mkDerivation rec {
+    name = "hyperv-daemons-bin-${version}";
+    inherit (kernel) src version;
+
+    nativeBuildInputs = [ makeWrapper ];
+
+    # as of 4.9 compilation will fail due to -Werror=format-security
+    hardeningDisable = [ "format" ];
+
+    preConfigure = ''
+      cd tools/hv
+    '';
+
+    installPhase = ''
+      runHook preInstall
+
+      for f in fcopy kvp vss ; do
+        install -Dm755 hv_''${f}_daemon -t $out/bin
+      done
+
+      install -Dm755 hv_get_dns_info.sh lsvmbus -t $out/bin
+
+      # I don't know why this isn't being handled automatically by fixupPhase
+      substituteInPlace $out/bin/lsvmbus \
+        --replace '/usr/bin/env python' ${python.interpreter}
+
+      runHook postInstall
+    '';
+
+    postFixup = ''
+      # kvp needs to be able to find the script(s)
+      wrapProgram $out/bin/hv_kvp_daemon --prefix PATH : $out/bin
+    '';
+  };
+
+  service = bin: title: check:
+    writeText "hv-${bin}.service" ''
+      [Unit]
+      Description=Hyper-V ${title} daemon
+      ConditionVirtualization=microsoft
+      ${lib.optionalString (check != "") ''
+        ConditionPathExists=/dev/vmbus/${check}
+      ''}
+      [Service]
+      ExecStart=@out@/hv_${bin}_daemon -n
+      Restart=on-failure
+      PrivateTmp=true
+      Slice=hyperv.slice
+
+      [Install]
+      WantedBy=hyperv-daemons.target
+    '';
+
+in stdenv.mkDerivation rec {
+  name    = "hyperv-daemons-${version}";
+
+  inherit (kernel) version;
+
+  # we just stick the bins into out as well as it requires "out"
+  outputs = [ "bin" "lib" "out" ];
+
+  phases = [ "installPhase" ];
+
+  buildInputs = [ daemons ];
+
+  installPhase = ''
+    system=$lib/lib/systemd/system
+
+    mkdir -p $system
+
+    cp ${service "fcopy" "file copy (FCOPY)" "hv_fcopy" } $system/hv-fcopy.service
+    cp ${service "kvp"   "key-value pair (KVP)"     ""  } $system/hv-kvp.service
+    cp ${service "vss"   "volume shadow copy (VSS)" ""  } $system/hv-vss.service
+
+    cat > $system/hyperv-daemons.target <<EOF
+    [Unit]
+    Description=Hyper-V Daemons
+    Wants=hv-fcopy.service hv-kvp.service hv-vss.service
+    EOF
+
+    for f in $lib/lib/systemd/system/* ; do
+      substituteInPlace $f --replace @out@ ${daemons}/bin
+    done
+
+    # we need to do both $out and $bin as $out is required
+    for d in $out/bin $bin/bin ; do
+      # make user binaries available
+      mkdir -p $d
+      ln -s ${daemons}/bin/lsvmbus $d/lsvmbus
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Integration Services for running NixOS under HyperV";
+    longDescription = ''
+      This packages contains the daemons that are used by the Hyper-V hypervisor
+      on the host.
+
+      Microsoft calls their guest agents "Integration Services" which is why
+      we use that name here.
+    '';
+    homepage = https://kernel.org;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms = kernel.meta.platforms;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index d7fb0ba5a7a4..6faaaf070c4c 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -12861,6 +12861,8 @@ with pkgs;
 
     pktgen = callPackage ../os-specific/linux/pktgen { };
 
+    hyperv-daemons = callPackage ../os-specific/linux/hyperv-daemons { };
+
     odp-dpdk = callPackage ../os-specific/linux/odp-dpdk { };
 
     ofp = callPackage ../os-specific/linux/ofp { };