nixos/filesystems: always write mount options for swap devices

According to fstab(5), unlike last two fields `fs_freq` and `fs_passno`,
the 4-th field `fs_mntops` is NOT optional, though it works when omitted.

For best-practice and easier to be parsed by other programs, we should always
write `defaults` as default mount options for swap devices.
This commit is contained in:
oxalica 2021-02-23 00:56:27 +08:00 committed by Bjørn Forsman
parent 2539e11b58
commit 80a1336bb9

View File

@ -22,8 +22,6 @@ let
# their assertions too
(attrValues config.fileSystems);
prioOption = prio: optionalString (prio != null) " pri=${toString prio}";
specialFSTypes = [ "proc" "sysfs" "tmpfs" "ramfs" "devtmpfs" "devpts" ];
coreFileSystemOpts = { name, config, ... }: {
@ -240,6 +238,8 @@ in
skipCheck = fs: fs.noCheck || fs.device == "none" || builtins.elem fs.fsType fsToSkipCheck;
# https://wiki.archlinux.org/index.php/fstab#Filepath_spaces
escape = string: builtins.replaceStrings [ " " "\t" ] [ "\\040" "\\011" ] string;
swapOptions = sw: "defaults"
+ optionalString (sw.priority != null) ",pri=${toString sw.priority}";
in ''
# This is a generated file. Do not edit!
#
@ -262,7 +262,7 @@ in
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
"${sw.realDevice} none swap${prioOption sw.priority}\n"
"${sw.realDevice} none swap ${swapOptions sw}\n"
)}
'';