2021-07-13 19:34:19 +02:00
|
|
|
{ stdenv, lib, python2, python3, kernel, makeWrapper, writeText
|
2021-03-14 17:05:16 +01:00
|
|
|
, gawk, iproute2 }:
|
2017-04-07 11:40:04 +02:00
|
|
|
|
|
|
|
let
|
2018-05-28 07:50:05 +02:00
|
|
|
libexec = "libexec/hypervkvpd";
|
|
|
|
|
|
|
|
daemons = stdenv.mkDerivation rec {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "hyperv-daemons-bin";
|
2017-04-07 11:40:04 +02:00
|
|
|
inherit (kernel) src version;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-07-13 19:34:19 +02:00
|
|
|
buildInputs = [ (if lib.versionOlder version "4.19" then python2 else python3) ];
|
2017-04-07 11:40:04 +02:00
|
|
|
|
|
|
|
# as of 4.9 compilation will fail due to -Werror=format-security
|
|
|
|
hardeningDisable = [ "format" ];
|
|
|
|
|
2018-05-28 07:50:05 +02:00
|
|
|
postPatch = ''
|
2017-04-07 11:40:04 +02:00
|
|
|
cd tools/hv
|
2018-05-28 07:50:05 +02:00
|
|
|
substituteInPlace hv_kvp_daemon.c \
|
|
|
|
--replace /usr/libexec/hypervkvpd/ $out/${libexec}/
|
2017-04-07 11:40:04 +02:00
|
|
|
'';
|
|
|
|
|
2018-05-28 07:50:05 +02:00
|
|
|
# We don't actually need the hv_get_{dhcp,dns}_info scripts on NixOS in
|
|
|
|
# their current incarnation but with them in place, we stop the spam of
|
|
|
|
# errors in the log.
|
2017-04-07 11:40:04 +02:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
|
|
|
|
for f in fcopy kvp vss ; do
|
|
|
|
install -Dm755 hv_''${f}_daemon -t $out/bin
|
|
|
|
done
|
|
|
|
|
2018-05-28 07:50:05 +02:00
|
|
|
install -Dm755 lsvmbus $out/bin/lsvmbus
|
|
|
|
install -Dm755 hv_get_dhcp_info.sh $out/${libexec}/hv_get_dhcp_info
|
|
|
|
install -Dm755 hv_get_dns_info.sh $out/${libexec}/hv_get_dns_info
|
2017-04-07 11:40:04 +02:00
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = ''
|
2018-05-28 07:50:05 +02:00
|
|
|
wrapProgram $out/bin/hv_kvp_daemon \
|
2021-03-14 17:05:16 +01:00
|
|
|
--prefix PATH : $out/bin:${lib.makeBinPath [ gawk iproute2 ]}
|
2017-04-07 11:40:04 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
in stdenv.mkDerivation {
|
2019-08-15 14:41:18 +02:00
|
|
|
pname = "hyperv-daemons";
|
2017-04-07 11:40:04 +02:00
|
|
|
inherit (kernel) version;
|
|
|
|
|
|
|
|
# we just stick the bins into out as well as it requires "out"
|
|
|
|
outputs = [ "bin" "lib" "out" ];
|
|
|
|
|
|
|
|
buildInputs = [ daemons ];
|
|
|
|
|
2018-05-28 07:50:05 +02:00
|
|
|
buildCommand = ''
|
2017-04-07 11:40:04 +02:00
|
|
|
system=$lib/lib/systemd/system
|
|
|
|
|
2018-05-28 07:50:05 +02:00
|
|
|
install -Dm444 ${service "fcopy" "file copy (FCOPY)" "hv_fcopy" } $system/hv-fcopy.service
|
|
|
|
install -Dm444 ${service "kvp" "key-value pair (KVP)" "" } $system/hv-kvp.service
|
|
|
|
install -Dm444 ${service "vss" "volume shadow copy (VSS)" "" } $system/hv-vss.service
|
2017-04-07 11:40:04 +02:00
|
|
|
|
|
|
|
cat > $system/hyperv-daemons.target <<EOF
|
|
|
|
[Unit]
|
|
|
|
Description=Hyper-V Daemons
|
|
|
|
Wants=hv-fcopy.service hv-kvp.service hv-vss.service
|
|
|
|
EOF
|
|
|
|
|
2021-07-13 19:34:19 +02:00
|
|
|
for f in $lib/lib/systemd/system/*.service ; do
|
2017-04-07 11:40:04 +02:00
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
2021-01-11 08:54:33 +01:00
|
|
|
meta = with lib; {
|
2017-04-07 11:40:04 +02:00
|
|
|
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.
|
|
|
|
'';
|
2018-05-28 07:50:05 +02:00
|
|
|
homepage = "https://kernel.org";
|
2017-04-07 11:40:04 +02:00
|
|
|
maintainers = with maintainers; [ peterhoeg ];
|
|
|
|
platforms = kernel.meta.platforms;
|
|
|
|
};
|
|
|
|
}
|