{"id":26656185,"url":"https://github.com/hacker1024/nix-kernel-dev-vm","last_synced_at":"2026-02-17T04:32:49.954Z","repository":{"id":275416052,"uuid":"926017930","full_name":"hacker1024/nix-kernel-dev-vm","owner":"hacker1024","description":"A Nix shell to build a Linux kernel from source and run it in a virtual machine.","archived":false,"fork":false,"pushed_at":"2025-02-02T11:01:51.000Z","size":4,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-17T18:39:37.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hacker1024.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-02T10:49:31.000Z","updated_at":"2025-02-02T13:38:14.000Z","dependencies_parsed_at":"2025-02-02T11:37:34.250Z","dependency_job_id":null,"html_url":"https://github.com/hacker1024/nix-kernel-dev-vm","commit_stats":null,"previous_names":["hacker1024/nix-kernel-dev-vm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hacker1024/nix-kernel-dev-vm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fnix-kernel-dev-vm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fnix-kernel-dev-vm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fnix-kernel-dev-vm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fnix-kernel-dev-vm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hacker1024","download_url":"https://codeload.github.com/hacker1024/nix-kernel-dev-vm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hacker1024%2Fnix-kernel-dev-vm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29533702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T03:01:11.216Z","status":"ssl_error","status_checked_at":"2026-02-17T03:00:31.803Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-25T07:18:40.746Z","updated_at":"2026-02-17T04:32:49.936Z","avatar_url":"https://github.com/hacker1024.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nix kernel development VM\n\nThis repository contains a [Nix] shell that makes it easy to build a Linux\nkernel from source and test it in a virtual machine.\n\nAny host Linux platform with Nix is supported.\n\n[nix]: https://nixos.org\n\n## Goals\n\n_Why use this over other kernel development solutions?_\n\n- **Easy build environment setup**: The shell provides all build dependencies, including the toolchain!\n- **Rapid iteration**: With incremental compilation, it only takes 8 seconds on my machine to go from source to a guest shell prompt.\n- **Minimal disk footprint**: The only substantial file generated is an initial ramdisk. The guest uses a tmpfs root, and all OS files are mounted directly from the host.\n- **Rich guest environment**: A complete NixOS installation is available in the VM. No more tiny custom rootfses!\n- **High configurability (QEMU + OS settings)**: QEMU and the guest OS can be configured to your liking.\n\n## Usage\n\n### Quick start\n\n1. Clone the Linux kernel sources, enter the directory\n2. ```console\n   $ nix-shell path/to/this/repo\n   ```\n   \u003e This may take some some; the guest NixOS system will be evaluated and built.\n3. ```console\n   $ genconfig\n   ```\n   \u003e This only needs to be run once (or whenever the Nix kernel config is updated).\n4. ```console\n   $ launch\n   ```\n   \u003e After some time, the guest will boot. Future invocations will be faster.\n5. A guest console should open, logged in as `root`. You can use it normally, or\n   use some [special QEMU commands](https://www.qemu.org/docs/master/system/mux-chardev.html).\n\nAfter making kernel code changes, repeat from step 4 to test.\n\n### Configuring QEMU and the guest OS\n\nThe guest OS is [NixOS][nix], which is configured in _modules_. When running\n`nix-shell`, a module of your own can be included with the `configuration`\nargument, and the `launch` command will use it.\n\n```console\n$ nix-shell path/to/this/repo --arg configuration path/to/configuration.nix\n\n$ # Or, for small changes:\n$ nix-shell path/to/this/repo --arg configuration '{ my.option = \"abc\"; }'\n```\n\nFor example, here's a module I use to debug an ASUS USB keyboard driver. It\nmodifies some QEMU options, enables a kernel module, and installs a CLI utility.\n\n`configuration.nix`\n\n```nix\n{\n  virtualisation.vmVariant.virtualisation = {\n    memorySize = 512;\n    cores = 4;\n    qemu.options = [\n      \"-device qemu-xhci\"\n      \"-device usb-host,vendorid=0x0b05,productid=0x1b2c\"\n    ];\n  };\n\n  system.customKernelConfig = {\n    HID_ASUS = true;\n  };\n\n  environment.systemPackages = with pkgs; [\n    usbutils\n  ];\n}\n```\n\n#### Enabling graphics\n\nFor convenience, graphics are disabled, and the console is available through\nyour terminal.\n\nIf you desire a full QEMU window, however, you can enable it:\n\n```nix\n{\n  virtualisation.vmVariant.virtualisation.graphics = true;\n}\n```\n\nYou may also wish to install a desktop environment and enable 3D acceleration.  \nHere's an example with GNOME and VirGL - consult the NixOS and QEMU\ndocumentation for more details. You may need [nixGL](https://github.com/nix-community/nixGL).\n\n```nix\n{\n  virtualisation.vmVariant.virtualisation = {\n    graphics = true;\n    qemu.options = [ \"-device virtio-vga-gl\" \"-display gtk,gl=on\" ];\n  };\n\n  system.customKernelConfig = {\n    DRM = true;\n    DRM_VIRTIO_GPU_KMS = true;\n    DRM_FBDEV_EMULATION = true;\n    FRAMEBUFFER_CONSOLE = true;\n  };\n\n  hardware.graphics.enable = true;\n\n  services.xserver = {\n    enable = true;\n    displayManager.gdm.enable = true;\n    desktopManager.gnome.enable = true;\n  };\n\n  users.users.root.password = \"root\";\n}\n```\n\n### A note on kernel modules\n\nIn order to keep the kernel small, the regular list of kernel modules enabled by\nNixOS is not used. Instead, the `system.customKernelConfig` option can be used\nto enable or disable kernel configuration items.\n\nAdditionally, kernel modules are not actually compiled as modules, but are\nrather built in to the kernel directly. This is because the NixOS VM system does\nnot provide an easy way to load external modules with a custom kernel.\n\nThese changes in behavior may break some NixOS features. If this occurs, the\nkernel modules they need must be enabled manually.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacker1024%2Fnix-kernel-dev-vm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhacker1024%2Fnix-kernel-dev-vm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhacker1024%2Fnix-kernel-dev-vm/lists"}