Additional GRUB entries based on default NixOS entry

I’m trying to create a GRUB entry which inherits the linux kernel + parameters and the initrd from the latest/default entry, with the addition of some other kernel parameters that aren’t included by default.
I need this so that I can have two ways to start up NixOS: one which will start the OS normally, and another entry which will pass my 2nd GPU’s id to vfio-pci, so that my 2nd GPU will only be isolated when I need it to be in a Windows VM passthrough setup.

I tried messing with shell scripts and mkDerivation here and here by manually getting the path from /nix/store (since derivations seem to be isolated and unable to access any paths outside /nix/store?), but nixos-rebuild just exits with a mysterious “failed with exit code 2” with no proper stacktrace.

I also saw this topic, which makes a mention of “nesting.clone”, but I can’t find any information about such an option (has it been removed/renamed?)

2 Likes

Can’t you use specialisations for this?

Thanks! That’s a really neat feature I’ve never heard of.

For anyone looking at this in the future wanting to do the same thing;
reference: https://nixos.wiki/wiki/Specialisation
these 4 lines added to the NixOS configuration did the trick:

specialisation.vm.configuration = {
  boot.kernelParams = [ "vfio-pci.ids=[gpu pci ids]" ];
  boot.kernelModules = [ "vfio_pci" "vfio" "vfio_iommu_type1" ];
};
2 Likes

Out of curiousity, how are you defining your VM configuration? Do you just use something like virt-manager to edit the xml file or do you include it in your NixOS config somehow?

Looking to eventually setup single gpu passthrough in this way.

I simply define my VMs inside of virt-manager and, since I’m using impermanence, add /etc/libvirt/hooks and /var/lib/libvirt to environment.persistence.
AFAIK there isn’t a way to declaratively define libvirt configs anyway, unless you write the xml file directly to whatever directory libvirt uses.