Skip to content

Instantly share code, notes, and snippets.

@j-brn
Last active June 16, 2025 07:27
Show Gist options
  • Select an option

  • Save j-brn/716a03822d256bc5bf5d77b951c7915c to your computer and use it in GitHub Desktop.

Select an option

Save j-brn/716a03822d256bc5bf5d77b951c7915c to your computer and use it in GitHub Desktop.
KVMFR-NixOS
{
virtualisation.kvmfr = {
enable = true;
shm = {
enable = true;
size = 128;
user = "j-brn";
group = "libvirtd";
mode = "0600";
};
};
}
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.virtualisation.kvmfr;
in
{
options.virtualisation.kvmfr = {
enable = mkEnableOption "Kvmfr";
shm = {
enable = mkEnableOption "shm";
size = mkOption {
type = types.int;
default = "128";
description = "Size of the shared memory device in megabytes.";
};
user = mkOption {
type = types.str;
default = "root";
description = "Owner of the shared memory device.";
};
group = mkOption {
type = types.str;
default = "root";
description = "Group of the shared memory device.";
};
mode = mkOption {
type = types.str;
default = "0600";
description = "Mode of the shared memory device.";
};
};
};
config = mkIf cfg.enable {
boot.extraModulePackages = with config.boot.kernelPackages; [
(pkgs.callPackage ./kvmfr-package.nix { inherit kernel;})
];
boot.initrd.kernelModules = [ "kvmfr" ];
boot.kernelParams = optionals cfg.shm.enable [
"kvmfr.static_size_mb=${toString cfg.shm.size}"
];
services.udev.extraRules = optionals cfg.shm.enable ''
SUBSYSTEM=="kvmfr", OWNER="${cfg.shm.user}", GROUP="${cfg.shm.group}", MODE="${cfg.shm.mode}"
'';
};
}
{ stdenv, lib, fetchFromGitHub, kernel, kmod, looking-glass-client, ... }:
stdenv.mkDerivation rec {
pname = "kvmfr-${version}-${kernel.version}";
version = looking-glass-client.version;
src = looking-glass-client.src;
sourceRoot = "source/module";
hardeningDisable = [ "pic" "format" ];
nativeBuildInputs = kernel.moduleBuildDependencies;
makeFlags = [
"KVER=${kernel.modDirVersion}"
"KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
];
installPhase = ''
install -D kvmfr.ko -t "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/misc/"
'';
meta = with lib; {
description = "This kernel module implements a basic interface to the IVSHMEM device for LookingGlass";
homepage = "https://github.com/gnif/LookingGlass";
license = licenses.gpl2Only;
maintainers = with maintainers; [ j-brn ];
platforms = [ "x86_64-linux" ];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment