1{ stdenv, lib, python, kernel, makeWrapper, writeText }:
2
3let
4 daemons = stdenv.mkDerivation rec {
5 name = "hyperv-daemons-bin-${version}";
6 inherit (kernel) src version;
7
8 nativeBuildInputs = [ makeWrapper ];
9
10 # as of 4.9 compilation will fail due to -Werror=format-security
11 hardeningDisable = [ "format" ];
12
13 preConfigure = ''
14 cd tools/hv
15 '';
16
17 installPhase = ''
18 runHook preInstall
19
20 for f in fcopy kvp vss ; do
21 install -Dm755 hv_''${f}_daemon -t $out/bin
22 done
23
24 install -Dm755 hv_get_dns_info.sh lsvmbus -t $out/bin
25
26 # I don't know why this isn't being handled automatically by fixupPhase
27 substituteInPlace $out/bin/lsvmbus \
28 --replace '/usr/bin/env python' ${python.interpreter}
29
30 runHook postInstall
31 '';
32
33 postFixup = ''
34 # kvp needs to be able to find the script(s)
35 wrapProgram $out/bin/hv_kvp_daemon --prefix PATH : $out/bin
36 '';
37 };
38
39 service = bin: title: check:
40 writeText "hv-${bin}.service" ''
41 [Unit]
42 Description=Hyper-V ${title} daemon
43 ConditionVirtualization=microsoft
44 ${lib.optionalString (check != "") ''
45 ConditionPathExists=/dev/vmbus/${check}
46 ''}
47 [Service]
48 ExecStart=@out@/hv_${bin}_daemon -n
49 Restart=on-failure
50 PrivateTmp=true
51 Slice=hyperv.slice
52
53 [Install]
54 WantedBy=hyperv-daemons.target
55 '';
56
57in stdenv.mkDerivation rec {
58 name = "hyperv-daemons-${version}";
59
60 inherit (kernel) version;
61
62 # we just stick the bins into out as well as it requires "out"
63 outputs = [ "bin" "lib" "out" ];
64
65 phases = [ "installPhase" ];
66
67 buildInputs = [ daemons ];
68
69 installPhase = ''
70 system=$lib/lib/systemd/system
71
72 mkdir -p $system
73
74 cp ${service "fcopy" "file copy (FCOPY)" "hv_fcopy" } $system/hv-fcopy.service
75 cp ${service "kvp" "key-value pair (KVP)" "" } $system/hv-kvp.service
76 cp ${service "vss" "volume shadow copy (VSS)" "" } $system/hv-vss.service
77
78 cat > $system/hyperv-daemons.target <<EOF
79 [Unit]
80 Description=Hyper-V Daemons
81 Wants=hv-fcopy.service hv-kvp.service hv-vss.service
82 EOF
83
84 for f in $lib/lib/systemd/system/* ; do
85 substituteInPlace $f --replace @out@ ${daemons}/bin
86 done
87
88 # we need to do both $out and $bin as $out is required
89 for d in $out/bin $bin/bin ; do
90 # make user binaries available
91 mkdir -p $d
92 ln -s ${daemons}/bin/lsvmbus $d/lsvmbus
93 done
94 '';
95
96 meta = with stdenv.lib; {
97 description = "Integration Services for running NixOS under HyperV";
98 longDescription = ''
99 This packages contains the daemons that are used by the Hyper-V hypervisor
100 on the host.
101
102 Microsoft calls their guest agents "Integration Services" which is why
103 we use that name here.
104 '';
105 homepage = https://kernel.org;
106 maintainers = with maintainers; [ peterhoeg ];
107 platforms = kernel.meta.platforms;
108 };
109}