From 3fae68b30cfc27a7df5beaf9aaa7cb654edd8403 Mon Sep 17 00:00:00 2001 From: K900 Date: Mon, 28 Feb 2022 19:51:03 +0300 Subject: [PATCH 1/3] build-support/writeTextFile: fix for names with spaces I am sorry. --- pkgs/build-support/trivial-builders.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 68f0f1bc4ddc..fc3a6b35dbcc 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -121,7 +121,7 @@ rec { allowSubstitutes = false; } '' - target=$out${destination} + target=$out${lib.escapeShellArg destination} mkdir -p "$(dirname "$target")" if [ -e "$textPath" ]; then From 267f618da56d8ef12c3ada98d08c032549afadc2 Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 1 Mar 2022 10:28:39 +0300 Subject: [PATCH 2/3] build-support/makeDesktopItem: remove workaround, fix quoting --- pkgs/build-support/make-desktopitem/default.nix | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/make-desktopitem/default.nix b/pkgs/build-support/make-desktopitem/default.nix index d831fe24d33b..e09fd0e20f22 100644 --- a/pkgs/build-support/make-desktopitem/default.nix +++ b/pkgs/build-support/make-desktopitem/default.nix @@ -34,11 +34,6 @@ , extraConfig ? {} # Additional values to be added literally to the final item, e.g. vendor extensions }: let - # FIXME: workaround until https://github.com/NixOS/nixpkgs/pull/162246 lands - cleanName = if lib.hasInfix " " name - then throw "makeDesktopItem: name must not contain spaces!" - else name; - # There are multiple places in the FDO spec that make "boolean" values actually tristate, # e.g. StartupNotify, where "unset" is literally defined as "do something reasonable". # So, handle null values separately. @@ -116,8 +111,8 @@ let content = [ mainSectionRendered ] ++ actionsRendered; in writeTextFile { - name = "${cleanName}.desktop"; - destination = "/share/applications/${cleanName}.desktop"; + name = "${name}.desktop"; + destination = "/share/applications/${name}.desktop"; text = builtins.concatStringsSep "\n" content; - checkPhase = "${buildPackages.desktop-file-utils}/bin/desktop-file-validate $target"; + checkPhase = ''${buildPackages.desktop-file-utils}/bin/desktop-file-validate "$target"''; } From 7e3c503257490763fac7ceacbd33e551a0811e37 Mon Sep 17 00:00:00 2001 From: K900 Date: Thu, 3 Mar 2022 10:26:30 +0300 Subject: [PATCH 3/3] build-support/writeTextFile: add test for weird file names --- .../trivial-builders/test/write-text-file.nix | 34 +++++++++++++++++++ pkgs/test/default.nix | 1 + 2 files changed, 35 insertions(+) create mode 100644 pkgs/build-support/trivial-builders/test/write-text-file.nix diff --git a/pkgs/build-support/trivial-builders/test/write-text-file.nix b/pkgs/build-support/trivial-builders/test/write-text-file.nix new file mode 100644 index 000000000000..ac83a75fca4a --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/write-text-file.nix @@ -0,0 +1,34 @@ +{ writeTextFile }: +let + veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes''; +in writeTextFile { + name = "weird-names"; + destination = "/etc/${veryWeirdName}"; + text = ''passed!''; + checkPhase = '' + # intentionally hardcode everything here, to make sure + # Nix does not mess with file paths + + name="here's a name with some \"bad\" characters, like spaces and quotes" + fullPath="$out/etc/$name" + + if [ -f "$fullPath" ]; then + echo "[PASS] File exists!" + else + echo "[FAIL] File was not created at expected path!" + exit 1 + fi + + content=$(<"$fullPath") + expected="passed!" + + if [ "$content" = "$expected" ]; then + echo "[PASS] Contents match!" + else + echo "[FAIL] File contents don't match!" + echo " Expected: $expected" + echo " Got: $content" + exit 2 + fi + ''; +} diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 4110327946d9..d572c0390609 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -59,6 +59,7 @@ with pkgs; trivial-builders = recurseIntoAttrs { writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {}; + writeTextFile = callPackage ../build-support/trivial-builders/test/write-text-file.nix {}; references = callPackage ../build-support/trivial-builders/test/references.nix {}; overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {}; concat = callPackage ../build-support/trivial-builders/test/concat-test.nix {};