about summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@gmail.com>2015-12-12 19:33:02 -0600
committerThomas Tuegel <ttuegel@gmail.com>2015-12-16 15:00:34 -0600
commit8baebb55d43804733c77ac8263fe75e92b544a50 (patch)
treeb24085fb1d5f471b845f8b98138bc8c2ae4c6f6f /lib/strings.nix
parent97834fc233afe624a052fe4f01d5bc876eeaa208 (diff)
lib/strings: add readPathsFromFile
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index ce2c4132bbca0..098da975c6019 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -235,4 +235,19 @@ rec {
     then may_be_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;
+
 }