Merge pull request #10218 from offlinehacker/nixos/format_options

add support for auto format, format options
This commit is contained in:
Jaka Hudoklin 2015-11-18 22:33:01 +01:00
commit 22c61d3bfc

View File

@ -58,6 +58,15 @@ let
''; '';
}; };
formatOptions = mkOption {
default = "";
type = types.str;
description = ''
If <option>autoFormat</option> option is set specifies
extra options passed to mkfs.
'';
};
autoResize = mkOption { autoResize = mkOption {
default = false; default = false;
type = types.bool; type = types.bool;
@ -81,6 +90,9 @@ let
mountPoint = mkDefault name; mountPoint = mkDefault name;
device = mkIf (config.fsType == "tmpfs") (mkDefault config.fsType); device = mkIf (config.fsType == "tmpfs") (mkDefault config.fsType);
options = mkIf config.autoResize "x-nixos.autoresize"; options = mkIf config.autoResize "x-nixos.autoresize";
# -F needed to allow bare block device without partitions
formatOptions = mkIf ((builtins.substring 0 3 config.fsType) == "ext") (mkDefault "-F");
}; };
}; };
@ -192,8 +204,6 @@ in
let let
mountPoint' = escapeSystemdPath fs.mountPoint; mountPoint' = escapeSystemdPath fs.mountPoint;
device' = escapeSystemdPath fs.device; device' = escapeSystemdPath fs.device;
# -F needed to allow bare block device without partitions
mkfsOpts = optional ((builtins.substring 0 3 fs.fsType) == "ext") "-F";
in nameValuePair "mkfs-${device'}" in nameValuePair "mkfs-${device'}"
{ description = "Initialisation of Filesystem ${fs.device}"; { description = "Initialisation of Filesystem ${fs.device}";
wantedBy = [ "${mountPoint'}.mount" ]; wantedBy = [ "${mountPoint'}.mount" ];
@ -208,7 +218,7 @@ in
type=$(blkid -p -s TYPE -o value "${fs.device}" || true) type=$(blkid -p -s TYPE -o value "${fs.device}" || true)
if [ -z "$type" ]; then if [ -z "$type" ]; then
echo "creating ${fs.fsType} filesystem on ${fs.device}..." echo "creating ${fs.fsType} filesystem on ${fs.device}..."
mkfs.${fs.fsType} ${concatStringsSep " " mkfsOpts} "${fs.device}" mkfs.${fs.fsType} ${fs.formatOptions} "${fs.device}"
fi fi
''; '';
unitConfig.RequiresMountsFor = [ "${dirOf fs.device}" ]; unitConfig.RequiresMountsFor = [ "${dirOf fs.device}" ];