Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 136 lines 3.3 kB view raw
1{ 2 stdenv, 3 lib, 4 python3, 5 kernel, 6 makeWrapper, 7 writeText, 8 gawk, 9 iproute2, 10}: 11 12let 13 libexec = "libexec/hypervkvpd"; 14 15 fcopy_name = 16 if lib.versionOlder kernel.version "6.10" then 17 "fcopy" 18 else 19 # The fcopy program is explicitly left out in the Makefile on aarch64 20 (if stdenv.hostPlatform.isAarch64 then null else "fcopy_uio"); 21 22 daemons = stdenv.mkDerivation { 23 pname = "hyperv-daemons-bin"; 24 inherit (kernel) src version; 25 26 nativeBuildInputs = [ makeWrapper ]; 27 buildInputs = [ python3 ]; 28 29 postPatch = '' 30 cd tools/hv 31 substituteInPlace hv_kvp_daemon.c \ 32 --replace /usr/libexec/hypervkvpd/ $out/${libexec}/ 33 ''; 34 35 makeFlags = [ 36 "ARCH=${stdenv.hostPlatform.parsed.cpu.name}" 37 "DESTDIR=$(out)" 38 "sbindir=/bin" 39 "libexecdir=/libexec" 40 ]; 41 42 postFixup = '' 43 wrapProgram $out/bin/hv_kvp_daemon \ 44 --prefix PATH : $out/bin:${ 45 lib.makeBinPath [ 46 gawk 47 iproute2 48 ] 49 } 50 ''; 51 }; 52 53 service = 54 bin: title: check: 55 writeText "hv-${bin}.service" '' 56 [Unit] 57 Description=Hyper-V ${title} daemon 58 ConditionVirtualization=microsoft 59 ${lib.optionalString (check != "") '' 60 ConditionPathExists=/dev/vmbus/${check} 61 ''} 62 [Service] 63 ExecStart=@out@/hv_${bin}_daemon -n 64 Restart=on-failure 65 PrivateTmp=true 66 Slice=hyperv.slice 67 68 [Install] 69 WantedBy=hyperv-daemons.target 70 ''; 71 72in 73stdenv.mkDerivation { 74 pname = "hyperv-daemons"; 75 inherit (kernel) version; 76 77 # we just stick the bins into out as well as it requires "out" 78 outputs = [ 79 "bin" 80 "lib" 81 "out" 82 ]; 83 84 buildInputs = [ daemons ]; 85 passthru = { 86 inherit daemons; 87 }; 88 89 buildCommand = '' 90 system=$lib/lib/systemd/system 91 92 ${lib.optionalString (fcopy_name != null) '' 93 install -Dm444 ${ 94 service fcopy_name "file copy (FCOPY)" 95 "/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio" 96 } $system/hv-fcopy.service 97 ''} 98 install -Dm444 ${service "kvp" "key-value pair (KVP)" "hv_kvp"} $system/hv-kvp.service 99 install -Dm444 ${service "vss" "volume shadow copy (VSS)" "hv_vss"} $system/hv-vss.service 100 101 cat > $system/hyperv-daemons.target <<EOF 102 [Unit] 103 Description=Hyper-V Daemons 104 Wants=hv-kvp.service hv-vss.service 105 ${lib.optionalString (fcopy_name != null) '' 106 Wants=hv-fcopy.service 107 ''} 108 EOF 109 110 for f in $lib/lib/systemd/system/*.service ; do 111 substituteInPlace $f --replace @out@ ${daemons}/bin 112 done 113 114 # we need to do both $out and $bin as $out is required 115 for d in $out/bin $bin/bin ; do 116 # make user binaries available 117 mkdir -p $d 118 ln -s ${daemons}/bin/lsvmbus $d/lsvmbus 119 done 120 ''; 121 122 meta = with lib; { 123 description = "Integration Services for running NixOS under HyperV"; 124 mainProgram = "lsvmbus"; 125 longDescription = '' 126 This packages contains the daemons that are used by the Hyper-V hypervisor 127 on the host. 128 129 Microsoft calls their guest agents "Integration Services" which is why 130 we use that name here. 131 ''; 132 homepage = "https://kernel.org"; 133 maintainers = with maintainers; [ peterhoeg ]; 134 platforms = kernel.meta.platforms; 135 }; 136}