Merge pull request #95406 from Mic92/mountpoint-type

nixos/filesystems: don't allow mountpoints with trailing slash
This commit is contained in:
Kevin Cox 2021-01-31 06:28:02 -05:00 committed by GitHub
commit 969e43e394
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,8 +7,9 @@ let
addCheckDesc = desc: elemType: check: types.addCheck elemType check addCheckDesc = desc: elemType: check: types.addCheck elemType check
// { description = "${elemType.description} (with check: ${desc})"; }; // { description = "${elemType.description} (with check: ${desc})"; };
nonEmptyStr = addCheckDesc "non-empty" types.str
(x: x != "" && ! (all (c: c == " " || c == "\t") (stringToCharacters x))); isNonEmpty = s: (builtins.match "[ \t\n]*" s) == null;
nonEmptyStr = addCheckDesc "non-empty" types.str isNonEmpty;
fileSystems' = toposort fsBefore (attrValues config.fileSystems); fileSystems' = toposort fsBefore (attrValues config.fileSystems);
@ -28,10 +29,10 @@ let
coreFileSystemOpts = { name, config, ... }: { coreFileSystemOpts = { name, config, ... }: {
options = { options = {
mountPoint = mkOption { mountPoint = mkOption {
example = "/mnt/usb"; 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."; description = "Location of the mounted the file system.";
}; };