trivial: input type assertions for writeText

This commit is contained in:
Hraban Luyat 2024-06-14 15:06:29 -04:00
parent d544b1259a
commit 5aa55272c2

View File

@ -127,7 +127,13 @@ rec {
# See doc/build-helpers/trivial-build-helpers.chapter.md
# or https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-text-writing
writeText = name: text: writeTextFile { inherit name text; };
writeText = name: text:
# TODO: To fully deprecate, replace the assertion with `lib.isString` and remove the warning
assert lib.assertMsg (lib.strings.isConvertibleWithToString text) ''
pkgs.writeText ${lib.strings.escapeNixString name}: The second argument should be a string, but it's a ${builtins.typeOf text} instead.'';
lib.warnIf (! lib.isString text) ''
pkgs.writeText ${lib.strings.escapeNixString name}: The second argument should be a string, but it's a ${builtins.typeOf text} instead, which is deprecated. Use `toString` to convert the value to a string first.''
writeTextFile { inherit name text; };
# See doc/build-helpers/trivial-build-helpers.chapter.md
# or https://nixos.org/manual/nixpkgs/unstable/#trivial-builder-text-writing