summary refs log tree commit diff
path: root/pkgs/os-specific/linux/hyperv-daemons/default.nix
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2017-04-07 17:40:04 +0800
committerPeter Hoeg <peter@hoeg.com>2017-10-14 14:38:04 +0800
commit51f1c635e679fdadead32e5aec464b28c254d099 (patch)
tree64bad6ce4baad60415ed83c4179f5772f0291f8e /pkgs/os-specific/linux/hyperv-daemons/default.nix
parent41306ca50580d66591058211676c463fcb30a2fd (diff)
downloadnixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar.gz
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar.bz2
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar.lz
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar.xz
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.tar.zst
nixpkgs-51f1c635e679fdadead32e5aec464b28c254d099.zip
hyperv-daemons: init at current linux kernel version
Diffstat (limited to 'pkgs/os-specific/linux/hyperv-daemons/default.nix')
-rw-r--r--pkgs/os-specific/linux/hyperv-daemons/default.nix109
1 files changed, 109 insertions, 0 deletions
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 00000000000..91b3c25bd31
--- /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 the
+      we use that name here.
+    '';
+    homepage = https://kernel.org;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms = kernel.meta.platforms;
+  };
+}