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.

hardware.nix 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. { config, pkgs, lib, ... }:
  2. with lib;
  3. {
  4. options.networking.interfaces = lib.mkOption {
  5. type = with types;
  6. attrsOf (submodule ({ ... }: {
  7. options.genode = {
  8. driver = mkOption {
  9. type = types.enum [ "ipxe" "virtio" ];
  10. default = "ipxe";
  11. };
  12. stack = mkOption {
  13. type = types.enum [ "lwip" "lxip" ];
  14. default = "lwip";
  15. };
  16. };
  17. }));
  18. };
  19. config.genode.init.children = let
  20. inherit (builtins) toFile;
  21. nics = mapAttrs' (name: interface:
  22. let name' = "nic." + name;
  23. in {
  24. name = name';
  25. value = {
  26. inputs = with pkgs.genodePackages;
  27. {
  28. ipxe = [ ipxe_nic_drv ];
  29. virtio = [ virtio_nic_drv ];
  30. }.${interface.genode.driver};
  31. configFile = toFile "${name'}.dhall" ''
  32. let Genode = env:DHALL_GENODE
  33. let Init = Genode.Init
  34. in Init.Child.flat
  35. Init.Child.Attributes::{
  36. , binary = "virtio_pci_nic"
  37. , provides = [ "Nic" ]
  38. , resources = Init.Resources::{
  39. , caps = 128
  40. , ram = Genode.units.MiB 4
  41. }
  42. , routes = [ Init.ServiceRoute.parent "IO_MEM" ]
  43. , config = Init.Config::{
  44. , policies =
  45. [ Init.Config.Policy::{
  46. , service = "Nic"
  47. , label =
  48. Init.LabelSelector.prefix "sockets.${name}"
  49. }
  50. ]
  51. }
  52. }
  53. '';
  54. };
  55. }) config.networking.interfaces;
  56. sockets = mapAttrs' (name: interface:
  57. let name' = "sockets." + name;
  58. in {
  59. name = name';
  60. value = {
  61. inputs = with pkgs.genodePackages;
  62. {
  63. lwip = [ vfs_lwip ];
  64. lxip = [ vfs_lixp ];
  65. }.${interface.genode.stack};
  66. configFile = let ipv4 = builtins.head interface.ipv4.addresses;
  67. in toFile "${name'}.dhall" ''
  68. let Genode = env:DHALL_GENODE
  69. let Init = Genode.Init
  70. in Init.Child.flat
  71. Init.Child.Attributes::{
  72. , binary = "vfs"
  73. , provides = [ "File_system" ]
  74. , resources = Init.Resources::{ caps = 128, ram = Genode.units.MiB 16 }
  75. , config = Init.Config::{
  76. , policies =
  77. [ Init.Config.Policy::{
  78. , service = "File_system"
  79. , label = Init.LabelSelector.suffix "sockets"
  80. , attributes = toMap { root = "/" }
  81. }
  82. ]
  83. , content =
  84. let XML = Genode.Prelude.XML
  85. in [ XML.element
  86. { name = "vfs"
  87. , attributes = XML.emptyAttributes
  88. , content =
  89. [ XML.leaf
  90. { name = "lwip"
  91. , attributes = toMap
  92. { ip_addr = "${ipv4.address}", netmask = "${
  93. if ipv4.prefixLength == 24 then
  94. "255.255.255.0"
  95. else
  96. throw
  97. "missing prefix to netmask conversion"
  98. }" }
  99. }
  100. ]
  101. }
  102. ]
  103. }
  104. }
  105. '';
  106. };
  107. }) config.networking.interfaces;
  108. in nics // sockets // {
  109. platform_drv = {
  110. inputs = [ pkgs.genodePackages.platform_drv ];
  111. configFile = let
  112. policies = concatMapStrings (name: ''
  113. Init.Config.Policy::{
  114. , service = "Platform"
  115. , label = Init.LabelSelector.prefix "nic.${name}"
  116. , content =
  117. [ Genode.Prelude.XML.leaf
  118. { name = "pci", attributes = toMap { class = "ETHERNET" } }
  119. ]
  120. }
  121. '') (builtins.attrNames config.networking.interfaces);
  122. in toFile "platform_drv.dhall" ''
  123. let Genode = env:DHALL_GENODE
  124. let Init = Genode.Init
  125. let label = \(_ : Text) -> { local = _, route = _ }
  126. in Init.Child.flat
  127. Init.Child.Attributes::{
  128. , binary = "platform_drv"
  129. , resources = Init.Resources::{
  130. , caps = 800
  131. , ram = Genode.units.MiB 4
  132. , constrainPhys = True
  133. }
  134. , reportRoms = [ label "acpi" ]
  135. , provides = [ "Platform" ]
  136. , routes =
  137. [ Init.ServiceRoute.parent "IRQ"
  138. , Init.ServiceRoute.parent "IO_MEM"
  139. , Init.ServiceRoute.parent "IO_PORT"
  140. ]
  141. , config = Init.Config::{
  142. , policies = [ ${policies} ]
  143. }
  144. }
  145. '';
  146. };
  147. acpi_drv = {
  148. inputs = [ pkgs.genodePackages.acpi_drv ];
  149. configFile = toFile "acpi_drv.dhall" ''
  150. let Genode = env:DHALL_GENODE
  151. let Init = Genode.Init
  152. let label = \(_ : Text) -> { local = _, route = _ }
  153. in Init.Child.flat
  154. Init.Child.Attributes::{
  155. , binary = "acpi_drv"
  156. , resources = Init.Resources::{
  157. , caps = 400
  158. , ram = Genode.units.MiB 4
  159. , constrainPhys = True
  160. }
  161. , romReports = [ label "acpi" ]
  162. , routes =
  163. [ Init.ServiceRoute.parent "IRQ"
  164. , Init.ServiceRoute.parent "IO_MEM"
  165. , Init.ServiceRoute.parent "IO_PORT"
  166. ]
  167. }
  168. '';
  169. };
  170. };
  171. }