Genode Packages collection https://git.sr.ht/~ehmry/genodepkgs/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.nix 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. { self }: {
  2. genodeHost = { config, lib, pkgs, modulesPath, ... }:
  3. let
  4. apps' = self.apps.x86_64-linux-x86_64-genode;
  5. config' = config;
  6. lib' = self.lib.x86_64-linux-x86_64-genode;
  7. pkgs' = self.packages.x86_64-linux-x86_64-genode;
  8. legacyPackages' = self.legacyPackages.x86_64-linux-x86_64-genode;
  9. modulesPath' = "${self.inputs.nixpkgs}/nixos/modules";
  10. genodeConfig = config.genode;
  11. console = lib'.runDhallCommand "vbox.dhall" { } ''
  12. dhall > $out <<< '${
  13. ./dhall/console.dhall
  14. } { bash = "${legacyPackages'.bash}", coreutils = "${legacyPackages'.coreutils}", path = "${
  15. lib.makeSearchPathOutput "bin" "bin"
  16. (with legacyPackages'; [ bash coreutils ])
  17. }" }'
  18. '';
  19. guestChildren = lib'.runDhallCommand "vbox.dhall" { } (''
  20. dhall > $out << END
  21. let Genode = env:DHALL_GENODE
  22. in [
  23. '' + builtins.concatStringsSep "," (lib.mapAttrsToList (vmName: cfg:
  24. let
  25. inherit (cfg) config;
  26. boot = {
  27. iso = rec {
  28. filename = "nixos.iso";
  29. drv = pkgs.callPackage
  30. "${modulesPath'}/../lib/make-iso9660-image.nix"
  31. # call the ISO utility from our nixpkgs with the package set of the guest
  32. {
  33. isoName = filename;
  34. inherit (config.isoImage) volumeID contents;
  35. };
  36. format = "< ISO | VDI >.ISO";
  37. storeRoot = "${baseNameOf drv}/iso";
  38. uuid = "81763434-9a51-49e8-9444-528a5a28c4bc";
  39. };
  40. vdi = rec {
  41. filename = "nixos.vdi";
  42. drv = import "${modulesPath'}/../lib/make-disk-image.nix" {
  43. inherit config lib pkgs;
  44. diskSize = config.virtualbox.baseImageSize;
  45. partitionTableType = "legacy";
  46. name = "nixos-${pkgs.stdenv.hostPlatform.system}.vdi";
  47. format = "vdi";
  48. };
  49. format = "< ISO | VDI >.VDI";
  50. storeRoot = baseNameOf drv;
  51. uuid = ''
  52. $(${pkgs.virtualbox}/bin/VBoxManage showmediuminfo "${boot.drv}/${boot.filename}" | awk '/^UUID:/ {print $2}')'';
  53. };
  54. }.${cfg.bootFormat};
  55. in lib'.runDhallCommand "vbox.dhall" { } ''
  56. bootUuid=${boot.uuid}
  57. dhall > $out << END
  58. { mapKey = "vbox-${vmName}"
  59. , mapValue =
  60. ${./dhall/vbox-guest.dhall}
  61. { bootFilename = "${boot.filename}"
  62. , bootFormat = ${boot.format}
  63. , bootPkg = "${boot.storeRoot}"
  64. , bootUuid = "$bootUuid"
  65. , memorySize = ${toString cfg.memorySize}
  66. , vmName = "${vmName}"
  67. }
  68. }
  69. END
  70. '') config.genode.guests) + ''
  71. ] : Genode.Init.Children.Type
  72. END
  73. '');
  74. initConfig = let
  75. fbDriverConfig = {
  76. intel = ./dhall/intel_fb_drv.dhall;
  77. vesa = ./dhall/vesa_fb_drv.dhall;
  78. }.${genodeConfig.fbDriver};
  79. in ''
  80. ${
  81. ./dhall/root.dhall
  82. } { fbDriver = ${fbDriverConfig}, guests = toMap { console = ${console} } # ${guestChildren}, inputFilterChargens = ${genodeConfig.inputFilter.extraChargen}, partitionType = ${
  83. ./dhall/partition-type
  84. }, wm = ${./dhall/wm.dhall}, graphical-log = ${
  85. ./dhall/graphical-log.dhall
  86. }, fs-log = ${
  87. ./dhall/fs-log.dhall
  88. }, systemLabel = "${config.system.nixos.label}" }'';
  89. buildBootDescription = self.legacyPackages.x86_64-linux.callPackage
  90. ./buildBootDescription.nix { lib = lib'; };
  91. bootDescription = buildBootDescription {
  92. inherit initConfig;
  93. imageInputs = [ legacyPackages'.bash ] ++ map pkgs'.genodeSources.depot
  94. ([
  95. "acpi_drv"
  96. "ahci_drv"
  97. "cached_fs_rom"
  98. "chroot"
  99. "decorator"
  100. "event_filter"
  101. "fs_log"
  102. "gui_fb"
  103. "init"
  104. "ipxe_nic_drv"
  105. "libc"
  106. "libiconv"
  107. "log_core"
  108. "nic_router"
  109. "nitpicker"
  110. "part_block"
  111. "platform_drv"
  112. "posix"
  113. "ps2_drv"
  114. "report_rom"
  115. "rom_to_file"
  116. "rtc_drv"
  117. "rump"
  118. "stdcxx"
  119. "terminal"
  120. "terminal_log"
  121. "usb_drv"
  122. "vfs"
  123. "vfs_audit"
  124. "vfs_import"
  125. "vfs_pipe"
  126. "vfs_ttf"
  127. "window_layouter"
  128. "wm"
  129. ] ++ lib.optional (genodeConfig.guests != { }) "vbox5"
  130. ++ lib.optional (genodeConfig.fbDriver == "vesa") "vesa_drv"
  131. ++ lib.optional (genodeConfig.fbDriver == "intel") "intel_fb_drv")
  132. ++ (with pkgs'; [ base-nova block_router ]);
  133. extraBinaries = [
  134. "ld.lib.so"
  135. "libc.so"
  136. "libm.so"
  137. "libposix.so"
  138. "librump.so"
  139. "librump_fs.so"
  140. "libstdcxx.so"
  141. "libvfs.so"
  142. "libvfs_audit.so"
  143. "libvfs_import.so"
  144. "libvfs_pipe.so"
  145. "libvfs_rump.so"
  146. "libvfs_ttf.so"
  147. ] ++ lib.optionals (genodeConfig.guests != { }) [
  148. "libc_pipe.so"
  149. "libiconv.so"
  150. "libqemu-usb.so"
  151. ];
  152. extraRoms = {
  153. "Inconsolata.ttf" =
  154. "${pkgs.inconsolata}/share/fonts/truetype/inconsolata/Inconsolata-Regular.ttf";
  155. "focus" = builtins.toFile "nitpicker-is-too-complicated.xml" ''
  156. <focus label="focus"/>
  157. '';
  158. };
  159. };
  160. firmware = lib'.novaImage "stage0" { gzip = true; } bootDescription;
  161. in {
  162. options.genode = with lib; {
  163. fbDriver = mkOption {
  164. default = "vesa";
  165. type = types.enum [ "intel" "vesa" ];
  166. description = ''
  167. Set framebuffer driver.
  168. '';
  169. };
  170. guests = mkOption {
  171. type = types.attrsOf (types.submodule
  172. ({ config, options, name, ... }: {
  173. options = {
  174. bootFormat = mkOption {
  175. default = "vdi";
  176. type = types.enum [ "iso" "vdi" ];
  177. description = "Set boot media format.";
  178. };
  179. memorySize = mkOption {
  180. type = types.int;
  181. default = 1536;
  182. description = ''
  183. The amount of RAM in MiB allocated to the VirtualBox guest.
  184. '';
  185. };
  186. config = mkOption {
  187. description = ''
  188. A specification of the desired configuration of this
  189. guest VM, as a NixOS module.
  190. '';
  191. type = mkOptionType {
  192. name = "Toplevel NixOS config";
  193. merge = loc: defs:
  194. (import "${modulesPath}/../lib/eval-config.nix" {
  195. inherit (config'.nixpkgs) system;
  196. modules = {
  197. iso = [
  198. "${modulesPath}/installer/cd-dvd/iso-image.nix"
  199. ];
  200. vdi = [
  201. "${modulesPath}/virtualisation/virtualbox-image.nix"
  202. {
  203. virtualbox.memorySize =
  204. genodeConfig.guests.${name}.memorySize;
  205. }
  206. ];
  207. }.${genodeConfig.guests.${name}.bootFormat}
  208. ++ [{ system.nixos.tags = [ name ]; }]
  209. ++ (map (x: x.value) defs);
  210. prefix = [ "guests" name ];
  211. }).config;
  212. };
  213. };
  214. };
  215. }));
  216. default = { };
  217. };
  218. inputFilter = {
  219. extraChargen = mkOption {
  220. description =
  221. "Dhall expression of the type <code>List Prelude.XML.Type</code>";
  222. type = types.str;
  223. default = "${./dhall/qwerty.chargen.dhall}";
  224. };
  225. };
  226. };
  227. config = {
  228. system.build.genode = {
  229. inherit firmware console;
  230. config = lib'.runDhallCommand "config.dhall" { }
  231. ''dhall > $out <<< "${initConfig}"'';
  232. xml = lib'.runDhallCommand "config.xml" { }
  233. ''${apps'.render-init.program} <<< "${initConfig}" > $out'';
  234. };
  235. boot.loader.grub = {
  236. extraEntries = ''
  237. menuentry Genode on NOVA {
  238. insmod multiboot2
  239. insmod gzio
  240. multiboot2 /bender
  241. module2 /hypervisor hypervisor iommu novpid serial logmem
  242. module2 /image.elf.gz image.elf
  243. }
  244. '';
  245. extraFiles = {
  246. "bender" = "${pkgs'.genodeSources}/tool/boot/bender";
  247. "hypervisor" = "${pkgs'.NOVA}/hypervisor-x86_64";
  248. "image.elf.gz" = "${firmware}/image.elf.gz";
  249. };
  250. };
  251. };
  252. };
  253. workman-layout.genode.inputFilter.extraChargen =
  254. "${./dhall/workman.chargen.dhall}";
  255. }