summary refs log tree commit diff
path: root/pkgs/pkgs-lib
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2022-03-28 09:23:25 +0200
committerRobert Hensing <robert@roberthensing.nl>2022-04-01 15:19:45 +0200
commit9a0739cbe2b3b56dbc923a36f4e204afba917641 (patch)
tree5709a1466e206e0faddbe2844855c658d7cd77c3 /pkgs/pkgs-lib
parent4f8e44394cb5afdef302618d3b2a75ad4291c71f (diff)
formats.javaProperties: Add comment
Diffstat (limited to 'pkgs/pkgs-lib')
-rw-r--r--pkgs/pkgs-lib/formats/java-properties/default.nix13
-rw-r--r--pkgs/pkgs-lib/tests/formats.nix2
2 files changed, 11 insertions, 4 deletions
diff --git a/pkgs/pkgs-lib/formats/java-properties/default.nix b/pkgs/pkgs-lib/formats/java-properties/default.nix
index e4f42a61f5c82..b63b96d32769f 100644
--- a/pkgs/pkgs-lib/formats/java-properties/default.nix
+++ b/pkgs/pkgs-lib/formats/java-properties/default.nix
@@ -1,6 +1,6 @@
 { lib, pkgs }:
 {
-  javaProperties = {}: {
+  javaProperties = { comment ? "Generated with Nix" }: {
     type = lib.types.attrsOf lib.types.str;
 
     generate = name: value:
@@ -76,10 +76,15 @@
 
           inputEncoding = "UTF-8";
 
+          inherit comment;
+
         } ''
-        jq -r --arg hash '#' "$jqCode" "$valuePath" \
-          | iconv --from-code "$inputEncoding" --to-code JAVA \
-          > "$out"
+        (
+          echo "$comment" | while read -r ln; do echo "# $ln"; done
+          echo
+          jq -r --arg hash '#' "$jqCode" "$valuePath" \
+            | iconv --from-code "$inputEncoding" --to-code JAVA \
+        ) > "$out"
       '';
   };
 }
diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix
index 71b4a3946a34b..1efe9d8686b1d 100644
--- a/pkgs/pkgs-lib/tests/formats.nix
+++ b/pkgs/pkgs-lib/tests/formats.nix
@@ -179,6 +179,8 @@ in runBuildTests {
       "الجبر" = "أكثر من مجرد أرقام";
     };
     expected = ''
+      # Generated with Nix
+
       1 = 2
       foo = bar
       \u00fctf\ 8 = d\u00fbh