about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/writers
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-10-30 13:37:39 +0100
committerAlyssa Ross <hi@alyssa.is>2023-10-30 13:37:39 +0100
commit7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769 (patch)
tree38e753812c0ceba947d65ec0555a5a66c1a5aa4e /nixpkgs/pkgs/build-support/writers
parent46cf147fc42b72f68ecd52b3b03a8bfd6077f42b (diff)
parent63678e9f3d3afecfeafa0acead6239cdb447574c (diff)
downloadnixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar.gz
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar.bz2
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar.lz
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar.xz
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.tar.zst
nixlib-7e0c8fe656bbc2fcbdfc3e03a367d2c6ff389769.zip
Merge commit '63678e9f3d3afecfeafa0acead6239cdb447574c' into HEAD
Conflicts:
	nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix
Diffstat (limited to 'nixpkgs/pkgs/build-support/writers')
-rw-r--r--nixpkgs/pkgs/build-support/writers/data.nix30
-rw-r--r--nixpkgs/pkgs/build-support/writers/test.nix14
2 files changed, 12 insertions, 32 deletions
diff --git a/nixpkgs/pkgs/build-support/writers/data.nix b/nixpkgs/pkgs/build-support/writers/data.nix
index 48f9bc547ed3..45ed5360eaeb 100644
--- a/nixpkgs/pkgs/build-support/writers/data.nix
+++ b/nixpkgs/pkgs/build-support/writers/data.nix
@@ -1,4 +1,4 @@
-{ lib, runCommand, dasel }:
+{ lib, pkgs, formats, runCommand, dasel }:
 let
   daselBin = lib.getExe dasel;
 
@@ -23,7 +23,7 @@ rec {
   #   writeJSON = makeDataWriter { input = builtins.toJSON; output = "cp $inputPath $out"; };
   #   myConfig = writeJSON "config.json" { hello = "world"; }
   #
-  makeDataWriter = { input ? lib.id, output ? "cp $inputPath $out" }: nameOrPath: data:
+  makeDataWriter = lib.warn "pkgs.writers.makeDataWriter is deprecated. Use pkgs.writeTextFile." ({ input ? lib.id, output ? "cp $inputPath $out" }: nameOrPath: data:
     assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null);
     let
       name = last (builtins.split "/" nameOrPath);
@@ -40,41 +40,25 @@ rec {
         mkdir -p $out/$(dirname "${nameOrPath}")
         mv tmp $out/${nameOrPath}
       ''}
-    '';
+    '');
 
-  # Writes the content to text.
-  #
-  # Example:
-  #   writeText "filename.txt" "file content"
-  writeText = makeDataWriter {
-    input = toString;
-    output = "cp $inputPath $out";
-  };
+  inherit (pkgs) writeText;
 
   # Writes the content to a JSON file.
   #
   # Example:
   #   writeJSON "data.json" { hello = "world"; }
-  writeJSON = makeDataWriter {
-    input = builtins.toJSON;
-    output = "${daselBin} -f $inputPath -r json -w json > $out";
-  };
+  writeJSON = (pkgs.formats.json {}).generate;
 
   # Writes the content to a TOML file.
   #
   # Example:
   #   writeTOML "data.toml" { hello = "world"; }
-  writeTOML = makeDataWriter {
-    input = builtins.toJSON;
-    output = "${daselBin} -f $inputPath -r json -w toml > $out";
-  };
+  writeTOML = (pkgs.formats.toml {}).generate;
 
   # Writes the content to a YAML file.
   #
   # Example:
   #   writeYAML "data.yaml" { hello = "world"; }
-  writeYAML = makeDataWriter {
-    input = builtins.toJSON;
-    output = "${daselBin} -f $inputPath -r json -w yaml > $out";
-  };
+  writeYAML = (pkgs.formats.yaml {}).generate;
 }
diff --git a/nixpkgs/pkgs/build-support/writers/test.nix b/nixpkgs/pkgs/build-support/writers/test.nix
index 2411f8c03a70..005daf0be5b4 100644
--- a/nixpkgs/pkgs/build-support/writers/test.nix
+++ b/nixpkgs/pkgs/build-support/writers/test.nix
@@ -7,6 +7,7 @@
 , python3Packages
 , pypy3Packages
 , runCommand
+, testers
 , writers
 , writeText
 }:
@@ -36,14 +37,7 @@ let
     let
       expectedFile = writeText "${file.name}-expected" expected;
     in
-    runCommand "run-${file.name}" {} ''
-      if ! diff -u ${file} ${expectedFile}; then
-        echo 'test ${file.name} failed'
-        exit 1
-      fi
-
-      touch $out
-    '';
+    testers.testEqualContents { expected = expectedFile; actual = file; assertion = "${file.name} matches"; };
 in
 lib.recurseIntoAttrs {
   bin = lib.recurseIntoAttrs {
@@ -261,7 +255,9 @@ lib.recurseIntoAttrs {
 
     toml = expectDataEqual {
       file = writeTOML "data.toml" { hello = "world"; };
-      expected = "hello = 'world'\n";
+      expected = ''
+        hello = "world"
+      '';
     };
 
     yaml = expectDataEqual {