Emery Hemingway 4 месяцев назад
Родитель
Сommit
26d4f6b62e

+ 8
- 5
nixos-modules/default.nix Просмотреть файл

@@ -1,12 +1,15 @@
1 1
 { flake }:
2 2
 
3
-let
4
-  baseModules =
5
-    [ ./genode-core.nix ./genode-init.nix ./gui ./hardware.nix ./systemd.nix ];
6
-in {
3
+{
7 4
 
8 5
   x86_64 = {
9
-    imports = [ baseModules ];
6
+    imports = [
7
+      ./genode-core.nix
8
+      ./genode-init.nix
9
+      ./hardware.nix
10
+      ./qemu-vm.nix
11
+      ./systemd.nix
12
+    ];
10 13
     nixpkgs = rec {
11 14
       localSystem = "x86_64-linux";
12 15
       crossSystem = "x86_64-genode";

+ 36
- 16
nixos-modules/genode-core.nix Просмотреть файл

@@ -98,13 +98,22 @@ in {
98 98
       };
99 99
 
100 100
       storeBackend = mkOption {
101
-        type = types.enum [ "tarball" "usb" ]; # "parent"?
101
+        type = types.enum [ "ahci" "tarball" "usb" ]; # "parent"?
102 102
         default = "tarball";
103 103
         description = ''
104 104
           Backend for the initial /nix/store file-system.
105 105
 
106 106
           <variablelist>
107 107
 
108
+            <varlistentry>
109
+              <term><literal>ahci</literal></term>
110
+              <listitem>
111
+                <para>
112
+                  An EXT2 file-system backed by SATA storage.
113
+                </para>
114
+              </listitem>
115
+            </varlistentry>
116
+
108 117
             <varlistentry>
109 118
               <term><literal>tarball</literal></term>
110 119
               <listitem>
@@ -188,12 +197,12 @@ in {
188 197
     }];
189 198
 
190 199
     genode.core.basePackages =
191
-      lib.optional (config.genode.boot.storeBackend == "usb")
200
+      lib.optional (config.genode.boot.storeBackend != "tarball")
192 201
       pkgs.genodePackages.part_block;
193 202
 
194 203
     genode.core.children =
195 204
       # Component to steer the store_fs to a specific partition
196
-      (if config.genode.boot.storeBackend == "usb" then {
205
+      (if config.genode.boot.storeBackend != "tarball" then {
197 206
         part_block.configFile = builtins.toFile "part_block.dhall" ''
198 207
           let Genode = env:DHALL_GENODE
199 208
 
@@ -223,18 +232,25 @@ in {
223 232
         { }) // {
224 233
           store_fs.configFile = let
225 234
 
226
-            storeVfsConfig = {
235
+            storeVfsConfig = let
236
+              rumpExt2 = ''
237
+                VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
238
+              '';
239
+            in {
240
+              ahci = rumpExt2;
227 241
               tarball = ''
228 242
                 VFS.vfs [ VFS.leafAttrs "tar" (toMap { name = "${config.system.build.tarball.fileName}.tar" }) ]
229 243
               '';
230
-              usb = ''
231
-                VFS.vfs [ VFS.leafAttrs "rump" (toMap { fs = "ext2fs", ram="12M" }) ]
232
-              '';
244
+              usb = rumpExt2;
233 245
             }.${config.genode.boot.storeBackend};
234 246
 
235
-            storeResources = {
247
+            storeResources = let
248
+              rumpExt2 =
249
+                "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
250
+            in {
251
+              ahci = rumpExt2;
236 252
               tarball = "Init.Resources.default";
237
-              usb = "Init.Resources::{ caps = 256, ram = Genode.units.MiB 16 }";
253
+              usb = rumpExt2;
238 254
             }.${config.genode.boot.storeBackend};
239 255
 
240 256
           in builtins.toFile "store_fs.dhall" ''
@@ -272,6 +288,7 @@ in {
272 288
         "${config.system.build.tarball}/tarball/${config.system.build.tarball.fileName}.tar";
273 289
 
274 290
       storeBackendInputs = {
291
+        ahci = [ pkgs.genodePackages.rump ];
275 292
         tarball = [ config.system.build.tarball ];
276 293
         usb = [ pkgs.genodePackages.rump ];
277 294
       }.${config.genode.boot.storeBackend};
@@ -370,7 +387,7 @@ in {
370 387
       xmllint --noout $out
371 388
     '';
372 389
 
373
-    system.build.bootDriveImage = let
390
+    virtualisation.diskImage = let
374 391
       espImage = import ./lib/make-esp-fs.nix { inherit config pkgs; };
375 392
       storeFsImage =
376 393
         pkgs.callPackage ./lib/make-ext2-fs.nix { inherit config pkgs; };
@@ -382,12 +399,15 @@ in {
382 399
     # virtualisation.useEFIBoot = config.genode.boot.storeBackend == "usb";
383 400
 
384 401
     virtualisation.qemu.options =
385
-      lib.optionals (config.genode.boot.storeBackend == "usb") [
386
-        "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd"
387
-        "-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
388
-        "-usb"
389
-        "-device usb-storage,drive=usbdisk"
390
-      ];
402
+      let blockCommon = [ "-bios ${pkgs.buildPackages.OVMF.fd}/FV/OVMF.fd" ];
403
+      in {
404
+        tarball = [ ];
405
+        ahci = blockCommon;
406
+        usb = blockCommon ++ [
407
+          "-drive id=usbdisk,file=${config.system.build.bootDriveImage},if=none,readonly"
408
+          "-device usb-storage,drive=usbdisk"
409
+        ];
410
+      }.${config.genode.boot.storeBackend};
391 411
 
392 412
   };
393 413
 

+ 83
- 31
nixos-modules/hardware.nix Просмотреть файл

@@ -36,6 +36,16 @@ with lib;
36 36
 
37 37
     hardware.genode = {
38 38
 
39
+      ahci.enable = lib.mkEnableOption "AHCI (SATA) block driver";
40
+
41
+      framebuffer = {
42
+        enable = lib.mkEnableOption "framebuffer driver";
43
+        driver = mkOption {
44
+          type = types.enum [ "boot" "vesa" ];
45
+          default = "vesa";
46
+        };
47
+      };
48
+
39 49
       usb = {
40 50
 
41 51
         enable = lib.mkEnableOption "USB driver";
@@ -48,14 +58,6 @@ with lib;
48 58
 
49 59
       };
50 60
 
51
-      framebuffer = {
52
-        enable = lib.mkEnableOption "framebuffer driver";
53
-        driver = mkOption {
54
-          type = types.enum [ "boot" "vesa" ];
55
-          default = "vesa";
56
-        };
57
-      };
58
-
59 61
     };
60 62
 
61 63
   };
@@ -92,6 +94,8 @@ with lib;
92 94
         policyCheck
93 95
       ];
94 96
 
97
+    hardware.genode.ahci.enable = config.genode.boot.storeBackend == "ahci";
98
+
95 99
     hardware.genode.usb.storage.enable = config.genode.boot.storeBackend
96 100
       == "usb";
97 101
 
@@ -115,31 +119,43 @@ with lib;
115 119
               ]
116 120
             }
117 121
       '') (builtins.attrNames config.networking.interfaces)
118
-      ++ lib.optional config.hardware.genode.framebuffer.enable
119
-      (builtins.toFile ("framebuffer.platform-policy.dhall") ''
120
-        let Genode = env:DHALL_GENODE
122
+      ++ (lib.optional config.hardware.genode.ahci.enable
123
+        (builtins.toFile ("ahci.platform-policy.dhall") ''
124
+          let Genode = env:DHALL_GENODE
121 125
 
122
-        in  Genode.Init.Config.Policy::{
123
-            , service = "Platform"
124
-            , label = Genode.Init.LabelSelector.prefix "fb_drv"
125
-            , content =
126
-              [ Genode.Prelude.XML.leaf
127
-                  { name = "pci", attributes = toMap { class = "VGA" } }
128
-              ]
129
-            }
130
-      '') ++ lib.optional config.hardware.genode.usb.enable
131
-      (builtins.toFile ("usb.platform-policy.dhall") ''
132
-        let Genode = env:DHALL_GENODE
126
+          in  Genode.Init.Config.Policy::{
127
+              , service = "Platform"
128
+              , label = Genode.Init.LabelSelector.prefix "ahci_drv"
129
+              , content =
130
+                [ Genode.Prelude.XML.leaf
131
+                    { name = "pci", attributes = toMap { class = "AHCI" } }
132
+                ]
133
+              }
134
+        '')) ++ (lib.optional config.hardware.genode.framebuffer.enable
135
+          (builtins.toFile ("framebuffer.platform-policy.dhall") ''
136
+            let Genode = env:DHALL_GENODE
137
+
138
+            in  Genode.Init.Config.Policy::{
139
+                , service = "Platform"
140
+                , label = Genode.Init.LabelSelector.prefix "fb_drv"
141
+                , content =
142
+                  [ Genode.Prelude.XML.leaf
143
+                      { name = "pci", attributes = toMap { class = "VGA" } }
144
+                  ]
145
+                }
146
+          '')) ++ (lib.optional config.hardware.genode.usb.enable
147
+            (builtins.toFile ("usb.platform-policy.dhall") ''
148
+              let Genode = env:DHALL_GENODE
133 149
 
134
-        in  Genode.Init.Config.Policy::{
135
-            , service = "Platform"
136
-            , label = Genode.Init.LabelSelector.prefix "usb_drv"
137
-            , content =
138
-              [ Genode.Prelude.XML.leaf
139
-                  { name = "pci", attributes = toMap { class = "USB" } }
140
-              ]
141
-            }
142
-      '');
150
+              in  Genode.Init.Config.Policy::{
151
+                  , service = "Platform"
152
+                  , label = Genode.Init.LabelSelector.prefix "usb_drv"
153
+                  , content =
154
+                    [ Genode.Prelude.XML.leaf
155
+                        { name = "pci", attributes = toMap { class = "USB" } }
156
+                    ]
157
+                  }
158
+            ''));
143 159
 
144 160
     genode.init.children = let
145 161
 
@@ -280,6 +296,40 @@ with lib;
280 296
 
281 297
     in lib.filterAttrs (n: v: v != null) (nics // sockets);
282 298
 
299
+    genode.core.children.ahci_drv = {
300
+      inputs = [ pkgs.genodePackages.ahci_drv ];
301
+      configFile = pkgs.writeText "ahci_drv.dhall" ''
302
+        let Genode = env:DHALL_GENODE
303
+
304
+        let Init = Genode.Init
305
+
306
+        in  Init.Child.flat
307
+              Init.Child.Attributes::{
308
+              , binary = "ahci_drv"
309
+              , resources = Init.Resources::{
310
+                , caps = 400
311
+                , ram = Genode.units.MiB 10
312
+                , constrainPhys = True
313
+                }
314
+              , romReports = [ { local = "ports", route = "ahci_ports" } ]
315
+              , routes =
316
+                [ Init.ServiceRoute.parent "IRQ"
317
+                , Init.ServiceRoute.parent "IO_MEM"
318
+                , Init.ServiceRoute.parent "IO_PORT"
319
+                ]
320
+              , config = Init.Config::{
321
+                , policies =
322
+                  [ Init.Config.Policy::{
323
+                    , service = "Block"
324
+                    , label = Init.LabelSelector.prefix "part_block"
325
+                    , attributes = toMap { device = "0", writeable = "yes" }
326
+                    }
327
+                  ]
328
+                }
329
+              }
330
+      '';
331
+    };
332
+
283 333
     genode.core.children.acpi_drv = {
284 334
       inputs = [ pkgs.genodePackages.acpi_drv ];
285 335
       configFile = pkgs.writeText "acpi_drv.dhall" ''
@@ -452,6 +502,8 @@ with lib;
452 502
         '';
453 503
       };
454 504
 
505
+    virtualisation.useBootLoader = config.genode.boot.storeBackend != "tarball";
506
+
455 507
     virtualisation.qemu.options = lib.optional config.hardware.genode.usb.enable
456 508
       (lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb"
457 509
         ++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)

+ 1
- 1
nixos-modules/lib/make-bootable-image.nix Просмотреть файл

@@ -64,6 +64,6 @@ pkgs.stdenv.mkDerivation {
64 64
       start=$espSectorOffset, type=$efiUuid
65 65
     EOF
66 66
 
67
-    qemu-img convert $img $out
67
+    qemu-img convert -f raw -O qcow2 $img $out
68 68
   '';
69 69
 }

+ 7
- 1
nixos-modules/nova.nix Просмотреть файл

@@ -31,7 +31,7 @@ in {
31 31
   };
32 32
 
33 33
   genode.boot.storePaths =
34
-    lib.optional (config.genode.boot.storeBackend == "usb") bootDir;
34
+    lib.optional (config.genode.boot.storeBackend != "tarball") bootDir;
35 35
 
36 36
   virtualisation.qemu.options =
37 37
     lib.optionals (!config.virtualisation.useBootLoader) [
@@ -39,6 +39,12 @@ in {
39 39
       "-initrd '${pkgs.genodePackages.NOVA}/hypervisor-x86_64 arg=iommu logmem novpid serial,${config.genode.boot.image}/image.elf'"
40 40
     ];
41 41
 
42
+  virtualisation.qemu.kernel = "${pkgs.genodePackages.bender}/share/bender/bender";
43
+
44
+  virtualisation.qemu.initrd = "${pkgs.genodePackages.NOVA}/hypervisor-x86_64";
45
+
46
+  virtualisation.qemu.cmdline = "arg=iommu logmem novpid serial,${config.genode.boot.image}/image.elf";
47
+
42 48
   boot.loader.grub.extraEntries = ''
43 49
     menuentry 'Genode on NOVA' {
44 50
       insmod multiboot2

+ 24
- 296
nixos-modules/qemu-vm.nix Просмотреть файл

@@ -11,77 +11,6 @@ let
11 11
 
12 12
   consoles = lib.concatMapStringsSep " " (c: "console=${c}") cfg.qemu.consoles;
13 13
 
14
-  driveOpts = { ... }: {
15
-
16
-    options = {
17
-
18
-      file = mkOption {
19
-        type = types.str;
20
-        description = "The file image used for this drive.";
21
-      };
22
-
23
-      driveExtraOpts = mkOption {
24
-        type = types.attrsOf types.str;
25
-        default = { };
26
-        description = "Extra options passed to drive flag.";
27
-      };
28
-
29
-      deviceExtraOpts = mkOption {
30
-        type = types.attrsOf types.str;
31
-        default = { };
32
-        description = "Extra options passed to device flag.";
33
-      };
34
-
35
-      name = mkOption {
36
-        type = types.nullOr types.str;
37
-        default = null;
38
-        description =
39
-          "A name for the drive. Must be unique in the drives list. Not passed to qemu.";
40
-      };
41
-
42
-    };
43
-
44
-  };
45
-
46
-  driveCmdline = idx:
47
-    { file, driveExtraOpts, deviceExtraOpts, ... }:
48
-    let
49
-      drvId = "drive${toString idx}";
50
-      mkKeyValue = generators.mkKeyValueDefault { } "=";
51
-      mkOpts = opts: concatStringsSep "," (mapAttrsToList mkKeyValue opts);
52
-      driveOpts = mkOpts (driveExtraOpts // {
53
-        index = idx;
54
-        id = drvId;
55
-        "if" = "none";
56
-        inherit file;
57
-      });
58
-      deviceOpts = mkOpts (deviceExtraOpts // { drive = drvId; });
59
-      device = if cfg.qemu.diskInterface == "scsi" then
60
-        "-device lsi53c895a -device scsi-hd,${deviceOpts}"
61
-      else
62
-        "-device virtio-blk-pci,${deviceOpts}";
63
-    in "-drive ${driveOpts} ${device}";
64
-
65
-  drivesCmdLine = drives: concatStringsSep " " (imap1 driveCmdline drives);
66
-
67
-  # Creates a device name from a 1-based a numerical index, e.g.
68
-  # * `driveDeviceName 1` -> `/dev/vda`
69
-  # * `driveDeviceName 2` -> `/dev/vdb`
70
-  driveDeviceName = idx:
71
-    let letter = elemAt lowerChars (idx - 1);
72
-    in if cfg.qemu.diskInterface == "scsi" then
73
-      "/dev/sd${letter}"
74
-    else
75
-      "/dev/vd${letter}";
76
-
77
-  lookupDriveDeviceName = driveName: driveList:
78
-    (findSingle (drive: drive.name == driveName)
79
-      (throw "Drive ${driveName} not found")
80
-      (throw "Multiple drives named ${driveName}") driveList).device;
81
-
82
-  addDeviceNames =
83
-    imap1 (idx: drive: drive // { device = driveDeviceName idx; });
84
-
85 14
   efiPrefix = if (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) then
86 15
     "${pkgs.buildPackages.OVMF.fd}/FV/OVMF"
87 16
   else if pkgs.stdenv.isAarch64 then
@@ -97,6 +26,11 @@ let
97 26
 
98 27
     NIX_DISK_IMAGE=$(readlink -f ''${NIX_DISK_IMAGE:-${config.virtualisation.diskImage}})
99 28
 
29
+    if ! test -w "$NIX_DISK_IMAGE"; then
30
+      ${qemu}/bin/qemu-img create -f qcow2 -b $NIX_DISK_IMAGE $TMPDIR/disk.img || exit 1
31
+      NIX_DISK_IMAGE=$TMPDIR/disk.img
32
+    fi
33
+
100 34
     if ! test -e "$NIX_DISK_IMAGE"; then
101 35
         ${qemu}/bin/qemu-img create -f qcow2 "$NIX_DISK_IMAGE" \
102 36
           ${toString config.virtualisation.diskSize}M || exit 1
@@ -107,131 +41,19 @@ let
107 41
         TMPDIR=$(mktemp -d nix-vm.XXXXXXXXXX --tmpdir)
108 42
     fi
109 43
 
110
-    # Create a directory for exchanging data with the VM.
111
-    mkdir -p $TMPDIR/xchg
112
-
113
-    ${if cfg.useBootLoader then ''
114
-      # Create a writable copy/snapshot of the boot disk.
115
-      # A writable boot disk can be booted from automatically.
116
-      ${qemu}/bin/qemu-img create -f qcow2 -b ${bootDisk}/disk.img $TMPDIR/disk.img || exit 1
117
-
118
-      NIX_EFI_VARS=$(readlink -f ''${NIX_EFI_VARS:-${cfg.efiVars}})
119
-
120
-      ${if cfg.useEFIBoot then ''
121
-        # VM needs writable EFI vars
122
-        if ! test -e "$NIX_EFI_VARS"; then
123
-          cp ${bootDisk}/efi-vars.fd "$NIX_EFI_VARS" || exit 1
124
-          chmod 0644 "$NIX_EFI_VARS" || exit 1
125
-        fi
126
-      '' else
127
-        ""}
128
-    '' else
129
-      ""}
130
-
131
-    cd $TMPDIR
132
-    idx=0
133
-    ${flip concatMapStrings cfg.emptyDiskImages (size: ''
134
-      if ! test -e "empty$idx.qcow2"; then
135
-          ${qemu}/bin/qemu-img create -f qcow2 "empty$idx.qcow2" "${
136
-            toString size
137
-          }M"
138
-      fi
139
-      idx=$((idx + 1))
140
-    '')}
141
-
142 44
     # Start QEMU.
45
+    set -v
143 46
     exec ${qemuBinary qemu} \
144 47
         -name ${config.system.name} \
145 48
         -m ${toString config.virtualisation.memorySize} \
146 49
         -smp ${toString config.virtualisation.cores} \
147
-        -device virtio-rng-pci \
148 50
         ${concatStringsSep " " config.virtualisation.qemu.networkingOptions} \
149
-        -virtfs local,path=/nix/store,security_model=none,mount_tag=store \
150
-        -virtfs local,path=$TMPDIR/xchg,security_model=none,mount_tag=xchg \
151
-        -virtfs local,path=''${SHARED_DIR:-$TMPDIR/xchg},security_model=none,mount_tag=shared \
152
-        ${drivesCmdLine config.virtualisation.qemu.drives} \
153 51
         ${toString config.virtualisation.qemu.options} \
52
+        $NIX_DISK_IMAGE \
154 53
         $QEMU_OPTS \
155 54
         "$@"
156 55
   '';
157 56
 
158
-  regInfo =
159
-    pkgs.closureInfo { rootPaths = config.virtualisation.pathsInNixDB; };
160
-
161
-  # Generate a hard disk image containing a /boot partition and GRUB
162
-  # in the MBR.  Used when the `useBootLoader' option is set.
163
-  # Uses `runInLinuxVM` to create the image in a throwaway VM.
164
-  # See note [Disk layout with `useBootLoader`].
165
-  # FIXME: use nixos/lib/make-disk-image.nix.
166
-  bootDisk = pkgs.vmTools.runInLinuxVM (pkgs.runCommand "nixos-boot-disk" {
167
-    preVM = ''
168
-      mkdir $out
169
-      diskImage=$out/disk.img
170
-      ${qemu}/bin/qemu-img create -f qcow2 $diskImage "60M"
171
-      ${if cfg.useEFIBoot then ''
172
-        efiVars=$out/efi-vars.fd
173
-        cp ${efiVarsDefault} $efiVars
174
-        chmod 0644 $efiVars
175
-      '' else
176
-        ""}
177
-    '';
178
-    buildInputs = [ pkgs.utillinux ];
179
-    QEMU_OPTS = "-nographic -serial stdio -monitor none"
180
-      + lib.optionalString cfg.useEFIBoot
181
-      (" -drive if=pflash,format=raw,unit=0,readonly=on,file=${efiFirmware}"
182
-        + " -drive if=pflash,format=raw,unit=1,file=$efiVars");
183
-  } ''
184
-    # Create a /boot EFI partition with 60M and arbitrary but fixed GUIDs for reproducibility
185
-    ${pkgs.gptfdisk}/bin/sgdisk \
186
-      --set-alignment=1 --new=1:34:2047 --change-name=1:BIOSBootPartition --typecode=1:ef02 \
187
-      --set-alignment=512 --largest-new=2 --change-name=2:EFISystem --typecode=2:ef00 \
188
-      --attributes=1:set:1 \
189
-      --attributes=2:set:2 \
190
-      --disk-guid=97FD5997-D90B-4AA3-8D16-C1723AEA73C1 \
191
-      --partition-guid=1:1C06F03B-704E-4657-B9CD-681A087A2FDC \
192
-      --partition-guid=2:970C694F-AFD0-4B99-B750-CDB7A329AB6F \
193
-      --hybrid 2 \
194
-      --recompute-chs /dev/vda
195
-
196
-    ${optionalString (config.boot.loader.grub.device != "/dev/vda")
197
-    # In this throwaway VM, we only have the /dev/vda disk, but the
198
-    # actual VM described by `config` (used by `switch-to-configuration`
199
-    # below) may set `boot.loader.grub.device` to a different device
200
-    # that's nonexistent in the throwaway VM.
201
-    # Create a symlink for that device, so that the `grub-install`
202
-    # by `switch-to-configuration` will hit /dev/vda anyway.
203
-    ''
204
-      ln -s /dev/vda ${config.boot.loader.grub.device}
205
-    ''}
206
-
207
-    ${pkgs.dosfstools}/bin/mkfs.fat -F16 /dev/vda2
208
-    export MTOOLS_SKIP_CHECK=1
209
-    ${pkgs.mtools}/bin/mlabel -i /dev/vda2 ::boot
210
-
211
-    mkdir /boot
212
-    mount /dev/vda2 /boot
213
-
214
-    ${optionalString config.boot.loader.efi.canTouchEfiVariables ''
215
-      mount -t efivarfs efivarfs /sys/firmware/efi/efivars
216
-    ''}
217
-
218
-    # This is needed for GRUB 0.97, which doesn't know about virtio devices.
219
-    mkdir /boot/grub
220
-    echo '(hd0) /dev/vda' > /boot/grub/device.map
221
-
222
-    # This is needed for systemd-boot to find ESP, and udev is not available here to create this
223
-    mkdir -p /dev/block
224
-    ln -s /dev/vda2 /dev/block/254:2
225
-
226
-    # Install bootloader
227
-    touch /etc/NIXOS
228
-    export NIXOS_INSTALL_BOOTLOADER=1
229
-    ${config.system.build.toplevel}/bin/switch-to-configuration boot
230
-
231
-    umount /boot
232
-  '' # */
233
-  );
234
-
235 57
 in {
236 58
   options = {
237 59
 
@@ -258,14 +80,6 @@ in {
258 80
       '';
259 81
     };
260 82
 
261
-    virtualisation.bootDevice = mkOption {
262
-      type = types.str;
263
-      example = "/dev/vda";
264
-      description = ''
265
-        The disk to be used for the root filesystem.
266
-      '';
267
-    };
268
-
269 83
     virtualisation.emptyDiskImages = mkOption {
270 84
       default = [ ];
271 85
       type = types.listOf types.int;
@@ -384,26 +198,28 @@ in {
384 198
         '';
385 199
       };
386 200
 
387
-      drives = mkOption {
388
-        type = types.listOf (types.submodule driveOpts);
389
-        description = "Drives passed to qemu.";
390
-        apply = addDeviceNames;
391
-      };
392
-
393 201
       diskInterface = mkOption {
394
-        default = "virtio";
395
-        example = "scsi";
396
-        type = types.enum [ "virtio" "scsi" "ide" ];
202
+        default = "ahci";
203
+        example = "usb";
204
+        type = types.enum [ "ahci" "usb" "virtio" ];
397 205
         description = "The interface used for the virtual hard disks.";
398 206
       };
399 207
 
400
-      guestAgent.enable = mkOption {
401
-        default = true;
402
-        type = types.bool;
403
-        description = ''
404
-          Enable the Qemu guest agent.
405
-        '';
208
+      kernel = mkOption {
209
+        type = types.path;
210
+        description = "Guest kernel.";
406 211
       };
212
+
213
+      initrd = mkOption {
214
+        type = types.path;
215
+        description = "Guest initrd.";
216
+      };
217
+
218
+      cmdline = mkOption {
219
+        type = types.str;
220
+        description = "Command line options to pass to guest.";
221
+      };
222
+
407 223
     };
408 224
 
409 225
     virtualisation.useBootLoader = mkOption {
@@ -449,73 +265,8 @@ in {
449 265
 
450 266
   config = {
451 267
 
452
-    # Note [Disk layout with `useBootLoader`]
453
-    #
454
-    # If `useBootLoader = true`, we configure 2 drives:
455
-    # `/dev/?da` for the root disk, and `/dev/?db` for the boot disk
456
-    # which has the `/boot` partition and the boot loader.
457
-    # Concretely:
458
-    #
459
-    # * The second drive's image `disk.img` is created in `bootDisk = ...`
460
-    #   using a throwaway VM. Note that there the disk is always `/dev/vda`,
461
-    #   even though in the final VM it will be at `/dev/*b`.
462
-    # * The disks are attached in `virtualisation.qemu.drives`.
463
-    #   Their order makes them appear as devices `a`, `b`, etc.
464
-    # * `fileSystems."/boot"` is adjusted to be on device `b`.
465
-
466
-    # If `useBootLoader`, GRUB goes to the second disk, see
467
-    # note [Disk layout with `useBootLoader`].
468
-    boot.loader.grub.device = mkVMOverride (if cfg.useBootLoader then
469
-      driveDeviceName 2 # second disk
470
-    else
471
-      cfg.bootDevice);
472
-
473
-    boot.initrd.extraUtilsCommands = ''
474
-      # We need mke2fs in the initrd.
475
-      copy_bin_and_libs ${pkgs.e2fsprogs}/bin/mke2fs
476
-    '';
477
-
478
-    boot.initrd.postDeviceCommands = ''
479
-      # If the disk image appears to be empty, run mke2fs to
480
-      # initialise.
481
-      FSTYPE=$(blkid -o value -s TYPE ${cfg.bootDevice} || true)
482
-      if test -z "$FSTYPE"; then
483
-          mke2fs -t ext4 ${cfg.bootDevice}
484
-      fi
485
-    '';
486
-
487
-    boot.initrd.postMountCommands = ''
488
-      # Mark this as a NixOS machine.
489
-      mkdir -p $targetRoot/etc
490
-      echo -n > $targetRoot/etc/NIXOS
491
-
492
-      # Fix the permissions on /tmp.
493
-      chmod 1777 $targetRoot/tmp
494
-
495
-      mkdir -p $targetRoot/boot
496
-
497
-      ${optionalString cfg.writableStore ''
498
-        echo "mounting overlay filesystem on /nix/store..."
499
-        mkdir -p 0755 $targetRoot/nix/.rw-store/store $targetRoot/nix/.rw-store/work $targetRoot/nix/store
500
-        mount -t overlay overlay $targetRoot/nix/store \
501
-          -o lowerdir=$targetRoot/nix/.ro-store,upperdir=$targetRoot/nix/.rw-store/store,workdir=$targetRoot/nix/.rw-store/work || fail
502
-      ''}
503
-    '';
504
-
505
-    virtualisation.bootDevice = mkDefault (driveDeviceName 1);
506
-
507 268
     # FIXME: Consolidate this one day.
508 269
     virtualisation.qemu.options = mkMerge [
509
-      (mkIf (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
510
-        "-usb"
511
-        "-device usb-tablet,bus=usb-bus.0"
512
-      ])
513
-      (mkIf (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64) [
514
-        "-device virtio-gpu-pci"
515
-        "-device usb-ehci,id=usb0"
516
-        "-device usb-kbd"
517
-        "-device usb-tablet"
518
-      ])
519 270
       (mkIf cfg.useEFIBoot [
520 271
         "-drive if=pflash,format=raw,unit=0,readonly,file=${efiFirmware}"
521 272
         "-drive if=pflash,format=raw,unit=1,file=$NIX_EFI_VARS"
@@ -524,29 +275,6 @@ in {
524 275
       (mkIf (!cfg.graphics) [ "-nographic" ])
525 276
     ];
526 277
 
527
-    virtualisation.qemu.drives = mkMerge [
528
-      [{
529
-        name = "root";
530
-        file = "$NIX_DISK_IMAGE";
531
-        driveExtraOpts.cache = "writeback";
532
-        driveExtraOpts.werror = "report";
533
-      }]
534
-      (mkIf cfg.useBootLoader [
535
-        # The order of this list determines the device names, see
536
-        # note [Disk layout with `useBootLoader`].
537
-        {
538
-          name = "boot";
539
-          file = "$TMPDIR/disk.img";
540
-          driveExtraOpts.media = "disk";
541
-          deviceExtraOpts.bootindex = "1";
542
-        }
543
-      ])
544
-      (imap0 (idx: _: {
545
-        file = "$(pwd)/empty${toString idx}.qcow2";
546
-        driveExtraOpts.werror = "report";
547
-      }) cfg.emptyDiskImages)
548
-    ];
549
-
550 278
     system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } ''
551 279
       mkdir -p $out/bin
552 280
       ln -s ${

+ 35
- 0
tests/ahci.nix Просмотреть файл

@@ -0,0 +1,35 @@
1
+{
2
+  name = "ahci";
3
+  machine = { pkgs, ... }: {
4
+    genode.boot.storeBackend = "ahci";
5
+    genode.init.children.hello = {
6
+      inputs = [ pkgs.hello pkgs.genodePackages.vfs.lib ];
7
+      configFile = pkgs.writeText "ahci-hello.child.dhall" ''
8
+        let Genode = env:DHALL_GENODE
9
+
10
+        let Init = Genode.Init
11
+
12
+        let Child = Init.Child
13
+
14
+        let Libc = Genode.Libc
15
+
16
+        in  Child.flat
17
+              Child.Attributes::{
18
+              , binary = "hello"
19
+              , exitPropagate = True
20
+              , resources = Genode.Init.Resources::{
21
+                , caps = 500
22
+                , ram = Genode.units.MiB 10
23
+                }
24
+              , config =
25
+                  Libc.toConfig
26
+                    Libc::{ args = [ "hello", "-g", "Hello from AHCI test" ] }
27
+              }
28
+      '';
29
+    };
30
+  };
31
+  testScript = ''
32
+    start_all()
33
+    machine.wait_until_serial_output("Hello from AHCI test")
34
+  '';
35
+}

+ 1
- 0
tests/default.nix Просмотреть файл

@@ -8,6 +8,7 @@ let
8 8
   testingPython = import ./lib/testing-python.nix;
9 9
 
10 10
   testSpecs = map (p: import p) [
11
+    ./ahci.nix
11 12
     ./bash.nix
12 13
     ./hello.nix
13 14
     ./log.nix

Загрузка…
Отмена
Сохранить