mirror of
https://gitlab.com/upRootNutrition/dotfiles.git
synced 2025-12-07 13:32:15 -06:00
test: vaultwarden microVM
This commit is contained in:
parent
e90d05f83d
commit
7ba592c0c5
43 changed files with 4005 additions and 267 deletions
47
example/microvm/pci-devices.nix
Executable file
47
example/microvm/pci-devices.nix
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
pciDevices = builtins.filter ({ bus, ... }: bus == "pci") config.microvm.devices;
|
||||
|
||||
# TODO: don't hardcode but obtain from host config
|
||||
user = "microvm";
|
||||
group = "kvm";
|
||||
|
||||
in
|
||||
{
|
||||
microvm.binScripts.pci-setup = lib.mkIf (pciDevices != [ ]) (
|
||||
''
|
||||
set -eou pipefail
|
||||
${pkgs.kmod}/bin/modprobe vfio-pci
|
||||
''
|
||||
+ lib.concatMapStrings (
|
||||
{ path, ... }:
|
||||
''
|
||||
cd /sys/bus/pci/devices/${path}
|
||||
if [ -e driver ]; then
|
||||
echo ${path} > driver/unbind
|
||||
fi
|
||||
echo vfio-pci > driver_override
|
||||
echo ${path} > /sys/bus/pci/drivers_probe
|
||||
''
|
||||
+
|
||||
# In order to access the vfio dev the permissions must be set
|
||||
# for the user/group running the VMM later.
|
||||
#
|
||||
# Insprired by https://www.kernel.org/doc/html/next/driver-api/vfio.html#vfio-usage-example
|
||||
#
|
||||
# assert we could get the IOMMU group number (=: name of VFIO dev)
|
||||
''
|
||||
[[ -e iommu_group ]] || exit 1
|
||||
VFIO_DEV=$(basename $(readlink iommu_group))
|
||||
echo "Making VFIO device $VFIO_DEV accessible for user"
|
||||
chown ${user}:${group} /dev/vfio/$VFIO_DEV
|
||||
''
|
||||
) pciDevices
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue