Skip to content

Commit

Permalink
Added support for btrfs filesystem and made it possible to set arbita…
Browse files Browse the repository at this point in the history
…ry options on FS creation.
  • Loading branch information
makuru-dd authored and astro committed May 26, 2024
1 parent a59c316 commit fa4262c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ rec {
{ image
, label
, size ? throw "Specify a size for volume ${image} or use autoCreate = false"
, mkfsExtraArgs
, fsType ? defaultFsType
, autoCreate ? true
, ...
}: pkgs.lib.warnIf
(label != null && !autoCreate) "Volume is not automatically labeled unless autoCreate is true. Volume has to be labeled manually, otherwise it will not be identified"
(let labelOption =
if autoCreate then
(if builtins.elem fsType ["ext2" "ext3" "ext4" "xfs"] then "-L"
(if builtins.elem fsType ["ext2" "ext3" "ext4" "xfs" "btrfs"] then "-L"
else if fsType == "vfat" then "-n"
else (pkgs.lib.warnIf (label != null)
"Will not label volume ${label} with filesystem type ${fsType}. Open an issue on the microvm.nix project to request a fix."
Expand All @@ -48,15 +49,19 @@ rec {
labelArgument =
if (labelOption != null && label != null) then "${labelOption} '${label}'"
else "";
mkfsExtraArgsString =
if mkfsExtraArgs != null
then nixpkgs-lib.escapeShellArgs mkfsExtraArgs
else " ";
in (nixpkgs-lib.optionalString autoCreate ''
PATH=$PATH:${with pkgs.buildPackages; lib.makeBinPath [ coreutils util-linux e2fsprogs xfsprogs dosfstools ]}
PATH=$PATH:${with pkgs.buildPackages; lib.makeBinPath [ coreutils util-linux e2fsprogs xfsprogs dosfstools btrfs-progs ]}
if [ ! -e '${image}' ]; then
touch '${image}'
# Mark NOCOW
chattr +C '${image}' || true
truncate -s ${toString size}M '${image}'
mkfs.${fsType} ${labelArgument} '${image}'
mkfs.${fsType} ${labelArgument} ${mkfsExtraArgsString} '${image}'
fi
'')));

Expand Down
7 changes: 6 additions & 1 deletion nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ in
default = true;
description = "Created image on host automatically before start?";
};
mkfsExtraArgs = mkOption {
type = listOf str;
default = [];
description = "Set extra Filesystem creation parameters";
};
fsType = mkOption {
type = str;
default = "ext4";
description = "File system for automatic creation and mounting";
description = "Filesystem for automatic creation and mounting";
};
};
});
Expand Down

0 comments on commit fa4262c

Please sign in to comment.