modules/filesystems: disallow non-empty fstab fields (#22803)

It was possible to pass empty strings / strings with only separator characters;
this lead to broken fstab formatting.

authored by Profpatsch and committed by GitHub 91d0260f cb2499ac

+10 -5
+10 -5
nixos/modules/tasks/filesystems.nix
··· 5 6 let 7 8 fileSystems' = toposort fsBefore (attrValues config.fileSystems); 9 10 fileSystems = if fileSystems' ? "result" ··· 26 27 mountPoint = mkOption { 28 example = "/mnt/usb"; 29 - type = types.str; 30 description = "Location of the mounted the file system."; 31 }; 32 33 device = mkOption { 34 default = null; 35 example = "/dev/sda"; 36 - type = types.nullOr types.str; 37 description = "Location of the device."; 38 }; 39 40 fsType = mkOption { 41 default = "auto"; 42 example = "ext3"; 43 - type = types.str; 44 description = "Type of the file system."; 45 }; 46 ··· 48 default = [ "defaults" ]; 49 example = [ "data=journal" ]; 50 description = "Options used to mount the file system."; 51 - type = types.listOf types.str; 52 }; 53 54 }; ··· 67 label = mkOption { 68 default = null; 69 example = "root-partition"; 70 - type = types.nullOr types.str; 71 description = "Label of the device (if any)."; 72 }; 73
··· 5 6 let 7 8 + addCheckDesc = desc: elemType: check: types.addCheck elemType check 9 + // { description = "${elemType.description} (with check: ${desc})"; }; 10 + nonEmptyStr = addCheckDesc "non-empty" types.str 11 + (x: x != "" && ! (all (c: c == " " || c == "\t") (stringToCharacters x))); 12 + 13 fileSystems' = toposort fsBefore (attrValues config.fileSystems); 14 15 fileSystems = if fileSystems' ? "result" ··· 31 32 mountPoint = mkOption { 33 example = "/mnt/usb"; 34 + type = nonEmptyStr; 35 description = "Location of the mounted the file system."; 36 }; 37 38 device = mkOption { 39 default = null; 40 example = "/dev/sda"; 41 + type = types.nullOr nonEmptyStr; 42 description = "Location of the device."; 43 }; 44 45 fsType = mkOption { 46 default = "auto"; 47 example = "ext3"; 48 + type = nonEmptyStr; 49 description = "Type of the file system."; 50 }; 51 ··· 53 default = [ "defaults" ]; 54 example = [ "data=journal" ]; 55 description = "Options used to mount the file system."; 56 + type = types.listOf nonEmptyStr; 57 }; 58 59 }; ··· 72 label = mkOption { 73 default = null; 74 example = "root-partition"; 75 + type = types.nullOr nonEmptyStr; 76 description = "Label of the device (if any)."; 77 }; 78