3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/os-specific/linux/hyperv-daemons/default.nix
Profpatsch 4a7f99d55d treewide: with stdenv.lib; in meta -> with lib;
Part of: https://github.com/NixOS/nixpkgs/issues/108938

meta = with stdenv.lib;

is a widely used pattern. We want to slowly remove
the `stdenv.lib` indirection and encourage people
to use `lib` directly. Thus let’s start with the meta
field.

This used a rewriting script to mostly automatically
replace all occurances of this pattern, and add the
`lib` argument to the package header if it doesn’t
exist yet.

The script in its current form is available at
https://cs.tvl.fyi/depot@2f807d7f141068d2d60676a89213eaa5353ca6e0/-/blob/users/Profpatsch/nixpkgs-rewriter/default.nix
2021-01-11 10:38:22 +01:00

115 lines
3.3 KiB
Nix

{ stdenv, lib, python, kernel, makeWrapper, writeText
, gawk, iproute }:
let
libexec = "libexec/hypervkvpd";
daemons = stdenv.mkDerivation rec {
pname = "hyperv-daemons-bin";
inherit (kernel) src version;
nativeBuildInputs = [ makeWrapper ];
# as of 4.9 compilation will fail due to -Werror=format-security
hardeningDisable = [ "format" ];
postPatch = ''
cd tools/hv
substituteInPlace hv_kvp_daemon.c \
--replace /usr/libexec/hypervkvpd/ $out/${libexec}/
'';
# 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.
installPhase = ''
runHook preInstall
for f in fcopy kvp vss ; do
install -Dm755 hv_''${f}_daemon -t $out/bin
done
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
# 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 = ''
wrapProgram $out/bin/hv_kvp_daemon \
--prefix PATH : $out/bin:${lib.makeBinPath [ gawk iproute ]}
'';
};
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 {
pname = "hyperv-daemons";
inherit (kernel) version;
# we just stick the bins into out as well as it requires "out"
outputs = [ "bin" "lib" "out" ];
buildInputs = [ daemons ];
buildCommand = ''
system=$lib/lib/systemd/system
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
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 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;
};
}