about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Taron <philip.taron@gmail.com>2024-03-06 16:34:08 -0800
committerPhilip Taron <philip.taron@gmail.com>2024-03-14 13:15:45 -0700
commit8422fe83b9576da478f5d66ddb0da4b00b215558 (patch)
tree780c38a43116c3c8fbd4735c7a62a6ec9ede2133 /lib
parent3a01525ae7f18b9d37fff95d1a4ee05133a3a733 (diff)
downloadnixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar.gz
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar.bz2
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar.lz
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar.xz
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.tar.zst
nixlib-8422fe83b9576da478f5d66ddb0da4b00b215558.zip
lib/generators: use the explicit public interface pattern
This enables further refactoring without accidentally changing the public interface.
Diffstat (limited to 'lib')
-rw-r--r--lib/generators.nix56
1 files changed, 37 insertions, 19 deletions
diff --git a/lib/generators.nix b/lib/generators.nix
index c159a254bb75..c7b1b7fc75f9 100644
--- a/lib/generators.nix
+++ b/lib/generators.nix
@@ -37,6 +37,7 @@ let
     replaceStrings
     split
     tail
+    toJSON
     typeOf
     ;
 
@@ -77,9 +78,6 @@ let
     assertMsg
     gvariant
     ;
-in
-
-rec {
 
   ## -- HELPER FUNCTIONS & DEFAULTS --
 
@@ -302,19 +300,6 @@ rec {
   # for details.
   toDconfINI = toINI { mkKeyValue = mkDconfKeyValue; };
 
-  /* Generates JSON from an arbitrary (non-function) value.
-    * For more information see the documentation of the builtin.
-    */
-  toJSON = {}: builtins.toJSON;
-
-
-  /* YAML has been a strict superset of JSON since 1.2, so we
-    * use toJSON. Before it only had a few differences referring
-    * to implicit typing rules, so it should work with older
-    * parsers as well.
-    */
-  toYAML = toJSON;
-
   withRecursion =
     {
       /* If this option is not null, the given value will stop evaluating at a certain depth */
@@ -496,7 +481,7 @@ ${expr "" v}
     else if v == null then
       abort "generators.toDhall: cannot convert a null to Dhall"
     else
-      builtins.toJSON v;
+      toJSON v;
 
   /*
    Translate a simple Nix expression to Lua representation with occasional
@@ -566,7 +551,7 @@ ${expr "" v}
     else if v == null then
       "nil"
     else if isInt v || isFloat v || isString v || isBool v then
-      builtins.toJSON v
+      toJSON v
     else if isList v then
       (if v == [ ] then "{}" else
       "{${introSpace}${concatItems (map (value: "${toLua innerArgs value}") v)}${outroSpace}}")
@@ -580,7 +565,7 @@ ${expr "" v}
           ''"${toString v}"''
         else
           "{${introSpace}${concatItems (
-            mapAttrsToList (key: value: "[${builtins.toJSON key}] = ${toLua innerArgs value}") v
+            mapAttrsToList (key: value: "[${toJSON key}] = ${toLua innerArgs value}") v
             )}${outroSpace}}"
       )
     else
@@ -593,4 +578,37 @@ ${expr "" v}
      mkLuaInline :: String -> AttrSet
   */
   mkLuaInline = expr: { _type = "lua-inline"; inherit expr; };
+
+in
+
+# Everything in this attrset is the public interface of the file.
+{
+  inherit
+    mkDconfKeyValue
+    mkKeyValueDefault
+    mkLuaInline
+    mkValueStringDefault
+    toDconfINI
+    toDhall
+    toGitINI
+    toINI
+    toINIWithGlobalSection
+    toKeyValue
+    toLua
+    toPlist
+    toPretty
+    withRecursion
+    ;
+
+  /* Generates JSON from an arbitrary (non-function) value.
+    * For more information see the documentation of the builtin.
+    */
+  toJSON = {}: toJSON;
+
+  /* YAML has been a strict superset of JSON since 1.2, so we
+    * use toJSON. Before it only had a few differences referring
+    * to implicit typing rules, so it should work with older
+    * parsers as well.
+    */
+  toYAML = {}: toJSON;
 }