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 5 6 6 let 7 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 + 8 13 fileSystems' = toposort fsBefore (attrValues config.fileSystems); 9 14 10 15 fileSystems = if fileSystems' ? "result" ··· 26 31 27 32 mountPoint = mkOption { 28 33 example = "/mnt/usb"; 29 - type = types.str; 34 + type = nonEmptyStr; 30 35 description = "Location of the mounted the file system."; 31 36 }; 32 37 33 38 device = mkOption { 34 39 default = null; 35 40 example = "/dev/sda"; 36 - type = types.nullOr types.str; 41 + type = types.nullOr nonEmptyStr; 37 42 description = "Location of the device."; 38 43 }; 39 44 40 45 fsType = mkOption { 41 46 default = "auto"; 42 47 example = "ext3"; 43 - type = types.str; 48 + type = nonEmptyStr; 44 49 description = "Type of the file system."; 45 50 }; 46 51 ··· 48 53 default = [ "defaults" ]; 49 54 example = [ "data=journal" ]; 50 55 description = "Options used to mount the file system."; 51 - type = types.listOf types.str; 56 + type = types.listOf nonEmptyStr; 52 57 }; 53 58 54 59 }; ··· 67 72 label = mkOption { 68 73 default = null; 69 74 example = "root-partition"; 70 - type = types.nullOr types.str; 75 + type = types.nullOr nonEmptyStr; 71 76 description = "Label of the device (if any)."; 72 77 }; 73 78