From f536901693ef6128cc61030ee74eb4433793b174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 14 Aug 2020 07:25:50 +0100 Subject: [PATCH] nixos/filesystems: don't allow mountpoints with trailing slash They are semantically the same as the non-slash version and therefore are potential source of duplicates. Also fixes https://github.com/NixOS/nixpkgs/issues/78951 --- nixos/modules/tasks/filesystems.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index 96f57fc80b0c..5388fc738e31 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -7,8 +7,9 @@ let addCheckDesc = desc: elemType: check: types.addCheck elemType check // { description = "${elemType.description} (with check: ${desc})"; }; - nonEmptyStr = addCheckDesc "non-empty" types.str - (s: (builtins.match ".*[^ \t]+.*" s) != null); + + isNonEmpty = s: (builtins.match ".*[^ \t]+.*" s) != null; + nonEmptyStr = addCheckDesc "non-empty" types.str isNonEmpty; fileSystems' = toposort fsBefore (attrValues config.fileSystems); @@ -28,10 +29,10 @@ let coreFileSystemOpts = { name, config, ... }: { options = { - mountPoint = mkOption { example = "/mnt/usb"; - type = nonEmptyStr; + type = addCheckDesc "non-empty without trailing slash" types.str + (s: isNonEmpty s && (builtins.match "(/|/.*[^/])" s) != null); description = "Location of the mounted the file system."; };