Skip to content

Commit 0cb5add

Browse files
wokalskiastro
authored andcommitted
Add direct and serial options to disk devices
1 parent b1fd970 commit 0cb5add

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/runners/cloud-hypervisor.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ let
2626
useVirtiofs = builtins.any ({ proto, ... }: proto == "virtiofs") shares;
2727

2828
# Transform attrs to parameters in form of `key1=value1,key2=value2,[...]`
29-
opsMapped = ops: lib.concatStringsSep "," (lib.mapAttrsToList (k: v: "${k}=${v}") ops);
29+
opsMapped = ops: lib.concatStringsSep "," (
30+
lib.mapAttrsToList
31+
(k: v: "${k}=${v}")
32+
(lib.attrsets.filterAttrs (_: v: v != null) ops)
33+
);
3034

3135
# Attrs representing CHV mem options
3236
memOps = opsMapped ({
@@ -159,9 +163,14 @@ in {
159163
readonly = "on";
160164
} // mqOps))
161165
++
162-
map ({ image, ... }: (opsMapped ({
166+
map ({ image, serial, direct, ... }: (opsMapped (({
167+
inherit serial;
163168
path = toString image;
164-
} // mqOps))) volumes
169+
direct =
170+
if direct == null then null
171+
else if direct then "on"
172+
else "off";
173+
}) // mqOps))) volumes
165174
)
166175
++
167176
arg "--fs" (map ({ proto, socket, tag, ... }:

nixos-modules/microvm/options.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ in
185185
type = str;
186186
description = "Path to disk image on the host";
187187
};
188+
serial = mkOption {
189+
type = nullOr str;
190+
default = null;
191+
description = "User-configured serial number for the disk
192+
(Currently only respected if using cloud-hypervisor)";
193+
};
194+
direct = mkOption {
195+
type = nullOr bool;
196+
default = null;
197+
description = "Whether to set O_DIRECT on the disk.
198+
(Currently only respected if using cloud-hypervisor)";
199+
};
188200
label = mkOption {
189201
type = nullOr str;
190202
default = null;

0 commit comments

Comments
 (0)