mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-19 18:44:13 +00:00
lib/strings: add readPathsFromFile
This commit is contained in:
parent
97834fc233
commit
8baebb55d4
@ -235,4 +235,19 @@ rec {
|
|||||||
then may_be_int
|
then may_be_int
|
||||||
else throw "Could not convert ${str} to int.";
|
else throw "Could not convert ${str} to int.";
|
||||||
|
|
||||||
|
# Read a list of paths from `file', relative to the `rootPath'. Lines
|
||||||
|
# beginning with `#' are treated as comments and ignored. Whitespace
|
||||||
|
# is significant.
|
||||||
|
readPathsFromFile = rootPath: file:
|
||||||
|
let
|
||||||
|
root = toString rootPath;
|
||||||
|
lines =
|
||||||
|
builtins.map (lib.removeSuffix "\n")
|
||||||
|
(lib.splitString "\n" (builtins.readFile file));
|
||||||
|
removeComments = lib.filter (line: !(lib.hasPrefix "#" line));
|
||||||
|
relativePaths = removeComments lines;
|
||||||
|
absolutePaths = builtins.map (path: builtins.toPath (root + "/" + path)) relativePaths;
|
||||||
|
in
|
||||||
|
absolutePaths;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user