Skip to content

Commit fa4262c

Browse files
makuru-orgastro
authored andcommitted
Added support for btrfs filesystem and made it possible to set arbitary options on FS creation.
1 parent a59c316 commit fa4262c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/default.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ rec {
3232
{ image
3333
, label
3434
, size ? throw "Specify a size for volume ${image} or use autoCreate = false"
35+
, mkfsExtraArgs
3536
, fsType ? defaultFsType
3637
, autoCreate ? true
3738
, ...
3839
}: pkgs.lib.warnIf
3940
(label != null && !autoCreate) "Volume is not automatically labeled unless autoCreate is true. Volume has to be labeled manually, otherwise it will not be identified"
4041
(let labelOption =
4142
if autoCreate then
42-
(if builtins.elem fsType ["ext2" "ext3" "ext4" "xfs"] then "-L"
43+
(if builtins.elem fsType ["ext2" "ext3" "ext4" "xfs" "btrfs"] then "-L"
4344
else if fsType == "vfat" then "-n"
4445
else (pkgs.lib.warnIf (label != null)
4546
"Will not label volume ${label} with filesystem type ${fsType}. Open an issue on the microvm.nix project to request a fix."
@@ -48,15 +49,19 @@ rec {
4849
labelArgument =
4950
if (labelOption != null && label != null) then "${labelOption} '${label}'"
5051
else "";
52+
mkfsExtraArgsString =
53+
if mkfsExtraArgs != null
54+
then nixpkgs-lib.escapeShellArgs mkfsExtraArgs
55+
else " ";
5156
in (nixpkgs-lib.optionalString autoCreate ''
52-
PATH=$PATH:${with pkgs.buildPackages; lib.makeBinPath [ coreutils util-linux e2fsprogs xfsprogs dosfstools ]}
57+
PATH=$PATH:${with pkgs.buildPackages; lib.makeBinPath [ coreutils util-linux e2fsprogs xfsprogs dosfstools btrfs-progs ]}
5358
5459
if [ ! -e '${image}' ]; then
5560
touch '${image}'
5661
# Mark NOCOW
5762
chattr +C '${image}' || true
5863
truncate -s ${toString size}M '${image}'
59-
mkfs.${fsType} ${labelArgument} '${image}'
64+
mkfs.${fsType} ${labelArgument} ${mkfsExtraArgsString} '${image}'
6065
fi
6166
'')));
6267

nixos-modules/microvm/options.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,15 @@ in
198198
default = true;
199199
description = "Created image on host automatically before start?";
200200
};
201+
mkfsExtraArgs = mkOption {
202+
type = listOf str;
203+
default = [];
204+
description = "Set extra Filesystem creation parameters";
205+
};
201206
fsType = mkOption {
202207
type = str;
203208
default = "ext4";
204-
description = "File system for automatic creation and mounting";
209+
description = "Filesystem for automatic creation and mounting";
205210
};
206211
};
207212
});

0 commit comments

Comments
 (0)