From f0b6425d738288f85381488cc3e25c30a441235c Mon Sep 17 00:00:00 2001 From: networkException Date: Sat, 21 Sep 2024 23:53:21 +0200 Subject: [PATCH 1/2] doc/build-helpers: fix wrong invokations of writeTextFile with destination This patch fixes occurances of writeTextFile invokations with a destination set but without a leading slash. This would cause an opaque build time error. --- doc/build-helpers/trivial-build-helpers.chapter.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/build-helpers/trivial-build-helpers.chapter.md b/doc/build-helpers/trivial-build-helpers.chapter.md index 31b42bd77426..ff00548e049a 100644 --- a/doc/build-helpers/trivial-build-helpers.chapter.md +++ b/doc/build-helpers/trivial-build-helpers.chapter.md @@ -501,7 +501,7 @@ writeTextFile { text = '' Contents of File ''; - destination = "share/my-file"; + destination = "/share/my-file"; } ``` @@ -586,7 +586,7 @@ writeTextFile { echo "hi" ''; executable = true; - destination = "bin/my-script"; + destination = "/bin/my-script"; } ``` @@ -674,7 +674,7 @@ writeTextFile { echo "hi" ''; executable = true; - destination = "bin/my-script"; + destination = "/bin/my-script"; } ``` From 6215daa52004e2e36117fa204db95fce46598945 Mon Sep 17 00:00:00 2001 From: networkException Date: Sat, 21 Sep 2024 23:54:48 +0200 Subject: [PATCH 2/2] writeTextFile: assert destination starting with a / This patch adds an assertion to the writeTextFile trivial builder, asserting that a specified destination starts with a slash. This matches the current behavior of the function and merely provides a helpful error message. --- pkgs/build-support/trivial-builders/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/build-support/trivial-builders/default.nix b/pkgs/build-support/trivial-builders/default.nix index 3bccc871a7dc..a02fe1fd6d0a 100644 --- a/pkgs/build-support/trivial-builders/default.nix +++ b/pkgs/build-support/trivial-builders/default.nix @@ -86,6 +86,13 @@ rec { , preferLocalBuild ? true , derivationArgs ? { } }: + assert lib.assertMsg (destination != "" -> (lib.hasPrefix "/" destination && destination != "/")) '' + destination must be an absolute path, relative to the derivation's out path, + got '${destination}' instead. + + Ensure that the path starts with a / and specifies at least the filename. + ''; + let matches = builtins.match "/bin/([^/]+)" destination; in