79 lines
2.4 KiB
Nix
79 lines
2.4 KiB
Nix
{
|
|
lib,
|
|
cloud-hypervisor,
|
|
fetchFromGitHub,
|
|
rustPlatform,
|
|
enableDebug ? true,
|
|
}:
|
|
|
|
let
|
|
inherit (lib) optionals optionalAttrs optionalString;
|
|
spectrum = builtins.fetchTree {
|
|
url = "https://spectrum-os.org/git/spectrum";
|
|
type = "git";
|
|
rev = "0f3388f0191d9a03c7bf471c269a34a79f22018b";
|
|
};
|
|
in
|
|
cloud-hypervisor.overrideAttrs (
|
|
finalAttrs: oldAttrs:
|
|
let
|
|
patchesFromDir =
|
|
root:
|
|
builtins.concatMap (name: lib.optionals (lib.hasSuffix ".patch" name) [ (root + "/${name}") ]) (
|
|
builtins.attrNames (builtins.readDir root)
|
|
);
|
|
spectrumPatches = {
|
|
version = "2025-12-20";
|
|
vhost = fetchFromGitHub {
|
|
name = "vhost";
|
|
owner = "rust-vmm";
|
|
repo = "vhost";
|
|
rev = "vhost-user-backend-v0.20.0";
|
|
hash = "sha256-KK1+mwYQr7YkyGT9+51v7TJael9D0lle2JXfRoTqYq8=";
|
|
};
|
|
patches = patchesFromDir (spectrum + "/pkgs/cloud-hypervisor");
|
|
vhostPatches = patchesFromDir (spectrum + "/pkgs/cloud-hypervisor/vhost");
|
|
};
|
|
oldPatchesStruct = oldAttrs.passthru.spectrumPatches or { };
|
|
missingPatchPhases = previouslyPatched != { };
|
|
isNewer = lib.versionOlder oldAttrs.spectrumPatches.version or "2000-00-00" spectrumPatches.version;
|
|
oldPatches = oldPatchesStruct.patches or [ ];
|
|
removeAll = removeElts: lst: builtins.filter (x: !(builtins.elem x removeElts)) lst;
|
|
in
|
|
optionalAttrs isNewer {
|
|
passthru = oldAttrs.passthru or { } // {
|
|
inherit spectrumPatches;
|
|
};
|
|
# Verbatim from spectrum
|
|
postUnpack =
|
|
oldAttrs.postUnpack or ""
|
|
+ optionalString missingPatchPhases ''
|
|
unpackFile $vhost
|
|
chmod -R +w vhost
|
|
'';
|
|
inherit (spectrumPatches) vhost;
|
|
|
|
patches = removeAll oldPatches (oldAttrs.patches or [ ]) ++ spectrumPatches.patches;
|
|
inherit (spectrumPatches) vhostPatches;
|
|
# Verbatim copy from spectrum
|
|
postPatch =
|
|
oldAttrs.postPatch or ""
|
|
+ optionalString missingPatchPhases ''
|
|
pushd ../vhost
|
|
for patch in $vhostPatches; do
|
|
echo applying patch $patch
|
|
patch -p1 < $patch
|
|
done
|
|
popd
|
|
'';
|
|
cargoDeps = rustPlatform.fetchCargoVendor {
|
|
inherit (finalAttrs) patches;
|
|
inherit (oldAttrs) src;
|
|
hash = "sha256-wGtsyKDg1z1QK9mJ1Q43NSjoPbm3m81p++DoD8ipIUI=";
|
|
};
|
|
}
|
|
// lib.optionalAttrs enableDebug {
|
|
buildType = "debug";
|
|
dontStrip = true;
|
|
}
|
|
)
|