From 56575cc0ac289d1f50358297cb72d9cd73f24630 Mon Sep 17 00:00:00 2001 From: Eric Sagnes Date: Fri, 29 Jul 2016 17:15:37 +0900 Subject: [PATCH] lib: add fileContents function --- lib/strings.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/strings.nix b/lib/strings.nix index 5e5f7b378667..daf845839343 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -479,4 +479,14 @@ rec { absolutePaths = builtins.map (path: builtins.toPath (root + "/" + path)) relativePaths; in absolutePaths; + + /* Read the contents of a file removing the trailing \n + + Example: + $ echo "1.0" > ./version + + fileContents ./version + => "1.0" + */ + fileContents = file: removeSuffix "\n" (builtins.readFile file); }