Skip to content

Commit 3374f72

Browse files
committed
nixos-modules/microvm/options: add microvm.volumes readOnly option
1 parent 5792bc1 commit 3374f72

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

lib/runners/alioth.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ in {
2929
"--blk" (lib.escapeShellArg "path=${storeDisk},readonly=true")
3030
]
3131
++
32-
builtins.concatMap ({ image, serial, direct, ... }:
32+
builtins.concatMap ({ image, serial, direct, readOnly, ... }:
3333
lib.warnIf (serial != null) ''
3434
Volume serial is not supported for alioth
3535
''
3636
lib.warnIf direct ''
3737
Volume direct IO is not supported for alioth
3838
''
39-
[ "--blk" (lib.escapeShellArg image) ]
39+
[
40+
"--blk"
41+
(lib.escapeShellArg "path=${image},readOnly=${
42+
lib.boolToString readOnly
43+
}")
44+
]
4045
) volumes
4146
++
4247
builtins.concatMap ({ proto, socket, tag, ... }:

lib/runners/cloud-hypervisor.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,17 @@ in {
163163
readonly = "on";
164164
} // mqOps))
165165
++
166-
map ({ image, serial, direct, ... }:
166+
map ({ image, serial, direct, readOnly, ... }:
167167
opsMapped (
168168
{
169169
path = toString image;
170170
direct =
171-
if direct == null then null
172-
else if direct then "on"
171+
if direct
172+
then "on"
173+
else "off";
174+
readonly =
175+
if readOnly
176+
then "on"
173177
else "off";
174178
} //
175179
lib.optionalAttrs (serial != null) {

lib/runners/crosvm.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ in {
9292
"-s" socket
9393
]
9494
++
95-
builtins.concatMap ({ image, direct, serial, ... }:
95+
builtins.concatMap ({ image, direct, serial, readOnly, ... }:
9696
[ "--block"
9797
"${image},o_direct=${
98-
if direct then "true" else "false"
98+
lib.boolToString direct
99+
},ro=${
100+
lib.boolToString readOnly
99101
}${
100102
lib.optionalString (serial != null) ",id=${serial}"
101103
}"

lib/runners/firecracker.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let
3737
is_root_device = false;
3838
is_read_only = true;
3939
io_engine = "Async";
40-
} ] ++ map ({ image, serial, direct, ... }:
40+
} ] ++ map ({ image, serial, direct, readOnly, ... }:
4141
lib.warnIf (serial != null) ''
4242
Volume serial is not supported for firecracker
4343
''
@@ -47,7 +47,7 @@ let
4747
drive_id = image;
4848
path_on_host = image;
4949
is_root_device = false;
50-
is_read_only = false;
50+
is_read_only = readOnly;
5151
io_engine = "Async";
5252
}) volumes;
5353
network-interfaces = map ({ type, id, mac, ... }:

lib/runners/kvmtool.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ in {
3838
++
3939
lib.optionals (balloonMem > 0) [ "--balloon" ]
4040
++
41-
builtins.concatMap ({ image, serial, direct, ... }:
41+
builtins.concatMap ({ image, serial, direct, readOnly, ... }:
4242
lib.warnIf (serial != null) ''
4343
Volume serial is not supported for kvmtool
4444
''
4545
[ "-d"
4646
(lib.escapeShellArg "image${
4747
lib.optionalString direct ",direct"
48+
}${
49+
lib.optionalString readOnly ",ro"
4850
}")
4951
]
5052
) volumes

lib/runners/qemu.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ lib.warnIf (mem == 2048) ''
208208
lib.optionals (user != null) [ "-user" user ] ++
209209
lib.optionals (socket != null) [ "-qmp" "unix:${socket},server,nowait" ] ++
210210
lib.optionals (balloonMem > 0) [ "-device" "virtio-balloon" ] ++
211-
builtins.concatMap ({ image, letter, serial, direct, ... }:
211+
builtins.concatMap ({ image, letter, serial, direct, readOnly, ... }:
212212
[ "-drive"
213213
"id=vd${letter},format=raw,file=${image},if=none,aio=io_uring,discard=unmap${
214214
lib.optionalString (direct != null) ",cache=none"
215-
}"
215+
},read-only=${if readOnly then "on" else "off"}"
216216
"-device"
217217
"virtio-blk-${devType},drive=vd${letter}${
218218
lib.optionalString (serial != null) ",serial=${serial}"

lib/runners/stratovirt.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ in {
9292
"-device" "virtio-blk-${devType 2},drive=store,id=blk_store"
9393
] ++
9494
lib.optionals (socket != null) [ "-qmp" "unix:${socket},server,nowait" ] ++
95-
builtins.concatMap ({ index, image, letter, serial, direct, ... }: [
95+
builtins.concatMap ({ index, image, letter, serial, direct, readOnly, ... }: [
9696
"-drive"
9797
"id=vd${
9898
letter
9999
},format=raw,if=none,aio=io_uring,file=${
100100
image
101101
},direct=${
102102
if direct then "on" else "off"
103+
},readonly=${
104+
if readOnly then "on" else "off"
103105
}"
104106
"-device"
105107
"virtio-blk-${

nixos-modules/microvm/options.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ in
194194
default = false;
195195
description = "Whether to set O_DIRECT on the disk.";
196196
};
197+
readOnly = mkOption {
198+
type = bool;
199+
default = false;
200+
description = "Turn off write access";
201+
};
197202
label = mkOption {
198203
type = nullOr str;
199204
default = null;

0 commit comments

Comments
 (0)