Skip to content

Instantly share code, notes, and snippets.

@gjz010
Last active June 24, 2023 17:17
Show Gist options
  • Select an option

  • Save gjz010/34942697c95d553c3686bc6467ebb9ff to your computer and use it in GitHub Desktop.

Select an option

Save gjz010/34942697c95d553c3686bc6467ebb9ff to your computer and use it in GitHub Desktop.
NixOS on RISC-V qemu
*.img
*.qcow2
result
.vscode
uboot
image
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1687573093,
"narHash": "sha256-uDBSnAFTcAOa+mHmnRNJQalO3A9pdxpRRhDc3SA+Hmg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b36c2496a5d4888de475f79407e0da9df66bca28",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
/*
NixOS unstable (23.11) on RISC-V 64 qemu
Startup:
```
$ nix build .#image -o image
$ nix build .#uboot -o uboot
$ zstd -d result/sd-image/nixos-sd-image-*-riscv64-linux.img.zst -o riscv.img -k
$ qemu-img convert -f raw -O qcow2 riscv.img riscv.qcow2
$ qemu-system-riscv64 -machine virt -cpu rv64 --nographic -drive file=riscv.qcow2,id=sdimage -device virtio-blk-device,drive=sdimage -m 8G -kernel uboot/u-boot.bin
```
*/
{
inputs.nixpkgs.url = github:NixOS/nixpkgs;
outputs = { self, nixpkgs }: {
nixosConfigurations.minimal = nixpkgs.lib.nixosSystem {
modules = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-riscv64-qemu.nix"
{
boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "virtio_balloon" "virtio_blk" "virtio_pci" "virtio_ring" ];
users.extraUsers.root.password = "";
services.openssh.enable = true;
networking.firewall.allowedTCPPorts = [ 22 ];
users = {
mutableUsers = true;
};
}
({ config, lib, pkgs, ... }:{
nixpkgs.buildPlatform.system = "x86_64-linux";
nixpkgs.hostPlatform.system = "riscv64-linux";
})
];
};
legacyPackages.x86_64-linux.image = self.nixosConfigurations.minimal.config.system.build.sdImage;
# https://lists.denx.de/pipermail/u-boot/2023-January/504492.html
legacyPackages.x86_64-linux.uboot = (nixpkgs.legacyPackages.x86_64-linux.pkgsCross.riscv64.ubootQemuRiscv64Smode.override {
version = "2023.04";
src = builtins.fetchurl {
url = "https://github.com/u-boot/u-boot/archive/refs/tags/v2023.04.tar.gz";
sha256 = "1wj8m05bs9r0ap97m78xngc196bz3z7hw1m0crz8nw0ggvmcbk4q";
};
}).overrideAttrs (final: prev: {
patches = [];
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment