diff --git a/nixos/lib/utils.nix b/nixos/lib/utils.nix index 692f0aac40a4..487b20f53d8c 100644 --- a/nixos/lib/utils.nix +++ b/nixos/lib/utils.nix @@ -43,6 +43,8 @@ in let hasSlashSuffix = hasSuffix "/"; + isAbsolute = hasPrefix "/"; + # normalisePath adds a slash at the end of the path if it didn't already # have one. # @@ -62,6 +64,7 @@ let mountPoint = normalisePath mount.mountPoint; depends = map normalisePath mount.depends; }; + utils = rec { # Copy configuration files to avoid having the entire sources in the system closure @@ -115,7 +118,6 @@ let in s: let - isAbsolute = hasPrefix "/" s; # path_simplify(): collapse duplicate slashes and drop "." components. rawComponents = filter (c: c != "" && c != ".") (splitString "/" s); # systemd accepts ".." only where it is redundant: a leading ".." in an @@ -128,7 +130,7 @@ let acc: c: if c == ".." then # A leading ".." in an absolute path is the only redundant case. - if isAbsolute && acc.components == [ ] then acc else acc // { normalized = false; } + if isAbsolute s && acc.components == [ ] then acc else acc // { normalized = false; } else acc // { components = acc.components ++ [ c ]; } ) @@ -144,7 +146,7 @@ let else if simplified.components != [ ] then concatStringsSep "/" simplified.components # The root directory, and - matching systemd-escape - the empty string. - else if isAbsolute || s == "" then + else if isAbsolute s || s == "" then "/" # A relative path that reduces to nothing (e.g. "."), which has no # valid escaping.