From 8041b9b2b301a4fe5442a643f9927c3f6706d6c8 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 15:49:31 -0800 Subject: [PATCH 1/7] lib/generators: builtins.isFloat is in Nix 2.3 There's a couple of aliases in play: 1. `lib.isList` is an alias for `builtins.isList`. 2. `lib.strings.concatStringsSep` is an alias for `builtins.concatStringsSep` --- lib/generators.nix | 61 +++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index ed59654cc07e..746d43449dd6 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -19,7 +19,30 @@ let libStr = lib.strings; libAttr = lib.attrsets; - inherit (lib) isFunction; + inherit (builtins) + addErrorContext + attrNames + concatStringsSep + elem + filter + head + isAttrs + isFloat + isInt + isList + isPath + isString + length + mapAttrs + match + replaceStrings + split + tail + ; + + inherit (lib) + isFunction + ; in rec { @@ -30,7 +53,7 @@ rec { * The builtin `toString` function has some strange defaults, * suitable for bash scripts but not much else. */ - mkValueStringDefault = {}: v: with builtins; + mkValueStringDefault = {}: v: let err = t: v: abort ("generators.mkValueStringDefault: " + "${t} not supported: ${toPretty {} v}"); @@ -86,7 +109,7 @@ rec { }: let mkLine = k: v: indent + mkKeyValue k v + "\n"; mkLines = if listsAsDuplicateKeys - then k: v: map (mkLine k) (if lib.isList v then v else [v]) + then k: v: map (mkLine k) (if isList v then v else [v]) else k: v: [ (mkLine k v) ]; in attrs: libStr.concatStrings (lib.concatLists (libAttr.mapAttrsToList mkLines attrs)); @@ -195,7 +218,6 @@ rec { *> name = "edolstra" */ toGitINI = attrs: - with builtins; let mkSectionName = name: let @@ -266,7 +288,7 @@ rec { /* If this option is true, an error will be thrown, if a certain given depth is exceeded */ , throwOnDepthLimit ? true }: - assert builtins.isInt depthLimit; + assert isInt depthLimit; let specialAttrs = [ "__functor" @@ -275,7 +297,7 @@ rec { "__pretty" ]; stepIntoAttr = evalNext: name: - if builtins.elem name specialAttrs + if elem name specialAttrs then id else evalNext; transform = depth: @@ -284,7 +306,7 @@ rec { then throw "Exceeded maximum eval-depth limit of ${toString depthLimit} while trying to evaluate with `generators.withRecursion'!" else const "" else id; - mapAny = with builtins; depth: v: + mapAny = depth: v: let evalNext = x: mapAny (depth + 1) (transform (depth + 1) x); in @@ -311,9 +333,8 @@ rec { indent ? "" }: let - go = indent: v: with builtins; - let isPath = v: typeOf v == "path"; - introSpace = if multiline then "\n${indent} " else " "; + go = indent: v: + let introSpace = if multiline then "\n${indent} " else " "; outroSpace = if multiline then "\n${indent}" else " "; in if isInt v then toString v # toString loses precision on floats, so we use toJSON instead. This isn't perfect @@ -322,7 +343,7 @@ rec { else if isFloat v then builtins.toJSON v else if isString v then let - lines = filter (v: ! isList v) (builtins.split "\n" v); + lines = filter (v: ! isList v) (split "\n" v); escapeSingleline = libStr.escape [ "\\" "\"" "\${" ]; escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = "\"" + concatStringsSep "\\n" (map escapeSingleline lines) + "\""; @@ -359,10 +380,10 @@ rec { else if v ? type && v.type == "derivation" then "" else "{" + introSpace - + libStr.concatStringsSep introSpace (libAttr.mapAttrsToList + + concatStringsSep introSpace (libAttr.mapAttrsToList (name: value: "${libStr.escapeNixIdentifier name} = ${ - builtins.addErrorContext "while evaluating an attribute `${name}`" + addErrorContext "while evaluating an attribute `${name}`" (go (indent + " ") value) };") v) + outroSpace + "}" @@ -371,9 +392,7 @@ rec { # PLIST handling toPlist = {}: v: let - isFloat = builtins.isFloat or (x: false); - isPath = x: builtins.typeOf x == "path"; - expr = ind: x: with builtins; + expr = ind: x: if x == null then "" else if isBool x then bool ind x else if isInt x then int ind x else @@ -396,20 +415,20 @@ rec { item = ind: libStr.concatMapStringsSep "\n" (indent ind); - list = ind: x: libStr.concatStringsSep "\n" [ + list = ind: x: concatStringsSep "\n" [ (literal ind "") (item ind x) (literal ind "") ]; - attrs = ind: x: libStr.concatStringsSep "\n" [ + attrs = ind: x: concatStringsSep "\n" [ (literal ind "") (attr ind x) (literal ind "") ]; attr = let attrFilter = name: value: name != "_module" && value != null; - in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList + in ind: x: concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optionals (attrFilter name value) [ (key "\t${ind}" name) (expr "\t${ind}" value) @@ -426,8 +445,7 @@ ${expr "" v} * the Natural type. */ toDhall = { }@args: v: - with builtins; - let concatItems = lib.strings.concatStringsSep ", "; + let concatItems = concatStringsSep ", "; in if isAttrs v then "{ ${ concatItems (lib.attrsets.mapAttrsToList @@ -488,7 +506,6 @@ ${expr "" v} /* Interpret as variable bindings */ asBindings ? false, }@args: v: - with builtins; let innerIndent = "${indent} "; introSpace = if multiline then "\n${innerIndent}" else " "; From a89d2ed83d762c522ccff4c2f917094398b0fbf1 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 16:15:07 -0800 Subject: [PATCH 2/7] lib/generators: explicitly import names from `lib` I followed the `inherit` chains in `lib/default.nix` to arrive at these imports. --- lib/generators.nix | 59 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index 746d43449dd6..df12c7175d5f 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -22,6 +22,7 @@ let inherit (builtins) addErrorContext attrNames + concatLists concatStringsSep elem filter @@ -40,8 +41,30 @@ let tail ; + inherit (lib.attrsets) + isDerivation + mapAttrsToList + recursiveUpdate + ; + + inherit (lib.lists) + init + flatten + foldl + last + optionals + reverseList + toList + ; + + inherit (lib.trivial) + isFunction # Note: not the builtin, considers `__functor` in attrsets. + functionArgs # Note: not the builtin; considers `__functor` in attrsets. + ; + inherit (lib) - isFunction + assertMsg + gvariant ; in @@ -59,7 +82,7 @@ rec { "${t} not supported: ${toPretty {} v}"); in if isInt v then toString v # convert derivations to store paths - else if lib.isDerivation v then toString v + else if isDerivation v then toString v # we default to not quoting strings else if isString v then v # isString returns "1", which is not a good default @@ -111,7 +134,7 @@ rec { mkLines = if listsAsDuplicateKeys then k: v: map (mkLine k) (if isList v then v else [v]) else k: v: [ (mkLine k v) ]; - in attrs: libStr.concatStrings (lib.concatLists (libAttr.mapAttrsToList mkLines attrs)); + in attrs: libStr.concatStrings (concatLists (libAttr.mapAttrsToList mkLines attrs)); /* Generate an INI-style config file from an @@ -242,19 +265,19 @@ rec { # generation for multiple ini values mkKeyValue = k: v: let mkKeyValue = mkKeyValueDefault { inherit mkValueString; } " = " k; - in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (lib.toList v)); + in concatStringsSep "\n" (map (kv: "\t" + mkKeyValue kv) (toList v)); # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI gitFlattenAttrs = let recurse = path: value: - if isAttrs value && !lib.isDerivation value then - lib.mapAttrsToList (name: value: recurse ([ name ] ++ path) value) value + if isAttrs value && !isDerivation value then + mapAttrsToList (name: value: recurse ([ name ] ++ path) value) value else if length path > 1 then { - ${concatStringsSep "." (lib.reverseList (tail path))}.${head path} = value; + ${concatStringsSep "." (reverseList (tail path))}.${head path} = value; } else { ${head path} = value; }; - in attrs: lib.foldl lib.recursiveUpdate { } (lib.flatten (recurse [ ] attrs)); + in attrs: foldl recursiveUpdate { } (flatten (recurse [ ] attrs)); toINI_ = toINI { inherit mkKeyValue mkSectionName; }; in @@ -262,7 +285,7 @@ rec { # mkKeyValueDefault wrapper that handles dconf INI quirks. # The main differences of the format is that it requires strings to be quoted. - mkDconfKeyValue = mkKeyValueDefault { mkValueString = v: toString (lib.gvariant.mkValue v); } "="; + mkDconfKeyValue = mkKeyValueDefault { mkValueString = v: toString (gvariant.mkValue v); } "="; # Generates INI in dconf keyfile style. See https://help.gnome.org/admin/system-admin-guide/stable/dconf-keyfiles.html.en # for details. @@ -351,8 +374,8 @@ rec { escapedLines = map escapeMultiline lines; # The last line gets a special treatment: if it's empty, '' is on its own line at the "outer" # indentation level. Otherwise, '' is appended to the last line. - lastLine = lib.last escapedLines; - in "''" + introSpace + concatStringsSep introSpace (lib.init escapedLines) + lastLine = last escapedLines; + in "''" + introSpace + concatStringsSep introSpace (init escapedLines) + (if lastLine == "" then outroSpace else introSpace + lastLine) + "''"; in if multiline && length lines > 1 then multilineResult else singlelineResult @@ -366,7 +389,7 @@ rec { + libStr.concatMapStringsSep introSpace (go (indent + " ")) v + outroSpace + "]" else if isFunction v then - let fna = lib.functionArgs v; + let fna = functionArgs v; showFnas = concatStringsSep ", " (libAttr.mapAttrsToList (name: hasDefVal: if hasDefVal then name + "?" else name) fna); @@ -428,8 +451,8 @@ rec { ]; attr = let attrFilter = name: value: name != "_module" && value != null; - in ind: x: concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList - (name: value: lib.optionals (attrFilter name value) [ + in ind: x: concatStringsSep "\n" (flatten (mapAttrsToList + (name: value: optionals (attrFilter name value) [ (key "\t${ind}" name) (expr "\t${ind}" value) ]) x)); @@ -448,7 +471,7 @@ ${expr "" v} let concatItems = concatStringsSep ", "; in if isAttrs v then "{ ${ - concatItems (lib.attrsets.mapAttrsToList + concatItems (mapAttrsToList (key: value: "${key} = ${toDhall args value}") v) } }" else if isList v then @@ -518,9 +541,9 @@ ${expr "" v} isLuaInline = { _type ? null, ... }: _type == "lua-inline"; generatedBindings = - assert lib.assertMsg (badVarNames == []) "Bad Lua var names: ${toPretty {} badVarNames}"; + assert assertMsg (badVarNames == []) "Bad Lua var names: ${toPretty {} badVarNames}"; libStr.concatStrings ( - lib.attrsets.mapAttrsToList (key: value: "${indent}${key} = ${toLua innerArgs value}\n") v + mapAttrsToList (key: value: "${indent}${key} = ${toLua innerArgs value}\n") v ); # https://en.wikibooks.org/wiki/Lua_Programming/variable#Variable_names @@ -546,7 +569,7 @@ ${expr "" v} ''"${toString v}"'' else "{${introSpace}${concatItems ( - lib.attrsets.mapAttrsToList (key: value: "[${builtins.toJSON key}] = ${toLua innerArgs value}") v + mapAttrsToList (key: value: "[${builtins.toJSON key}] = ${toLua innerArgs value}") v )}${outroSpace}}" ) else From 9513152413b7eef337fd99f9923e122b7bef5936 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 16:21:07 -0800 Subject: [PATCH 3/7] lib/generators: explicitly import names from `lib.string` A couple of these were imports from `builtins`. --- lib/generators.nix | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index df12c7175d5f..4db3cf6512f9 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -16,7 +16,6 @@ { lib }: with (lib).trivial; let - libStr = lib.strings; libAttr = lib.attrsets; inherit (builtins) @@ -57,6 +56,16 @@ let toList ; + inherit (lib.strings) + concatMapStringsSep + concatStrings + escape + escapeNixIdentifier + floatToString + hasInfix + splitString + ; + inherit (lib.trivial) isFunction # Note: not the builtin, considers `__functor` in attrsets. functionArgs # Note: not the builtin; considers `__functor` in attrsets. @@ -99,7 +108,7 @@ rec { # Floats currently can't be converted to precise strings, # condition warning on nix version once this isn't a problem anymore # See https://github.com/NixOS/nix/pull/3480 - else if isFloat v then libStr.floatToString v + else if isFloat v then floatToString v else err "this value is" (toString v); @@ -115,7 +124,7 @@ rec { mkKeyValueDefault = { mkValueString ? mkValueStringDefault {} }: sep: k: v: - "${libStr.escape [sep] k}${sep}${mkValueString v}"; + "${escape [sep] k}${sep}${mkValueString v}"; ## -- FILE FORMAT GENERATORS -- @@ -134,7 +143,7 @@ rec { mkLines = if listsAsDuplicateKeys then k: v: map (mkLine k) (if isList v then v else [v]) else k: v: [ (mkLine k v) ]; - in attrs: libStr.concatStrings (concatLists (libAttr.mapAttrsToList mkLines attrs)); + in attrs: concatStrings (concatLists (libAttr.mapAttrsToList mkLines attrs)); /* Generate an INI-style config file from an @@ -159,7 +168,7 @@ rec { */ toINI = { # apply transformations (e.g. escapes) to section names - mkSectionName ? (name: libStr.escape [ "[" "]" ] name), + mkSectionName ? (name: escape [ "[" "]" ] name), # format a setting line from key and value mkKeyValue ? mkKeyValueDefault {} "=", # allow lists as values for duplicate keys @@ -168,7 +177,7 @@ rec { let # map function to string for each key val mapAttrsToStringsSep = sep: mapFn: attrs: - libStr.concatStringsSep sep + concatStringsSep sep (libAttr.mapAttrsToList mapFn attrs); mkSection = sectName: sectValues: '' [${mkSectionName sectName}] @@ -210,7 +219,7 @@ rec { */ toINIWithGlobalSection = { # apply transformations (e.g. escapes) to section names - mkSectionName ? (name: libStr.escape [ "[" "]" ] name), + mkSectionName ? (name: escape [ "[" "]" ] name), # format a setting line from key and value mkKeyValue ? mkKeyValueDefault {} "=", # allow lists as values for duplicate keys @@ -244,8 +253,8 @@ rec { let mkSectionName = name: let - containsQuote = libStr.hasInfix ''"'' name; - sections = libStr.splitString "." name; + containsQuote = hasInfix ''"'' name; + sections = splitString "." name; section = head sections; subsections = tail sections; subsection = concatStringsSep "." subsections; @@ -367,8 +376,8 @@ rec { else if isString v then let lines = filter (v: ! isList v) (split "\n" v); - escapeSingleline = libStr.escape [ "\\" "\"" "\${" ]; - escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; + escapeSingleline = escape [ "\\" "\"" "\${" ]; + escapeMultiline = replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = "\"" + concatStringsSep "\\n" (map escapeSingleline lines) + "\""; multilineResult = let escapedLines = map escapeMultiline lines; @@ -386,7 +395,7 @@ rec { else if isList v then if v == [] then "[ ]" else "[" + introSpace - + libStr.concatMapStringsSep introSpace (go (indent + " ")) v + + concatMapStringsSep introSpace (go (indent + " ")) v + outroSpace + "]" else if isFunction v then let fna = functionArgs v; @@ -405,7 +414,7 @@ rec { else "{" + introSpace + concatStringsSep introSpace (libAttr.mapAttrsToList (name: value: - "${libStr.escapeNixIdentifier name} = ${ + "${escapeNixIdentifier name} = ${ addErrorContext "while evaluating an attribute `${name}`" (go (indent + " ") value) };") v) @@ -436,7 +445,7 @@ rec { indent = ind: expr "\t${ind}"; - item = ind: libStr.concatMapStringsSep "\n" (indent ind); + item = ind: concatMapStringsSep "\n" (indent ind); list = ind: x: concatStringsSep "\n" [ (literal ind "") @@ -542,7 +551,7 @@ ${expr "" v} generatedBindings = assert assertMsg (badVarNames == []) "Bad Lua var names: ${toPretty {} badVarNames}"; - libStr.concatStrings ( + concatStrings ( mapAttrsToList (key: value: "${indent}${key} = ${toLua innerArgs value}\n") v ); From b83b8a35482be639645743e85b688b1438e284fa Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 16:22:49 -0800 Subject: [PATCH 4/7] lib/generators: explicitly import names from `lib.attrsets` Everything used was already imported. --- lib/generators.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index 4db3cf6512f9..e8772f9d6486 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -16,8 +16,6 @@ { lib }: with (lib).trivial; let - libAttr = lib.attrsets; - inherit (builtins) addErrorContext attrNames @@ -143,7 +141,7 @@ rec { mkLines = if listsAsDuplicateKeys then k: v: map (mkLine k) (if isList v then v else [v]) else k: v: [ (mkLine k v) ]; - in attrs: concatStrings (concatLists (libAttr.mapAttrsToList mkLines attrs)); + in attrs: concatStrings (concatLists (mapAttrsToList mkLines attrs)); /* Generate an INI-style config file from an @@ -178,7 +176,7 @@ rec { # map function to string for each key val mapAttrsToStringsSep = sep: mapFn: attrs: concatStringsSep sep - (libAttr.mapAttrsToList mapFn attrs); + (mapAttrsToList mapFn attrs); mkSection = sectName: sectValues: '' [${mkSectionName sectName}] '' + toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } sectValues; @@ -399,7 +397,7 @@ rec { + outroSpace + "]" else if isFunction v then let fna = functionArgs v; - showFnas = concatStringsSep ", " (libAttr.mapAttrsToList + showFnas = concatStringsSep ", " (mapAttrsToList (name: hasDefVal: if hasDefVal then name + "?" else name) fna); in if fna == {} then "" @@ -412,7 +410,7 @@ rec { else if v ? type && v.type == "derivation" then "" else "{" + introSpace - + concatStringsSep introSpace (libAttr.mapAttrsToList + + concatStringsSep introSpace (mapAttrsToList (name: value: "${escapeNixIdentifier name} = ${ addErrorContext "while evaluating an attribute `${name}`" @@ -574,7 +572,7 @@ ${expr "" v} "(${v.expr})" else if v == { } then "{}" - else if libAttr.isDerivation v then + else if isDerivation v then ''"${toString v}"'' else "{${introSpace}${concatItems ( From 3a01525ae7f18b9d37fff95d1a4ee05133a3a733 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 16:27:00 -0800 Subject: [PATCH 5/7] lib/generators: explicitly import names from `lib.trivial` Everything else was already imported. --- lib/generators.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/generators.nix b/lib/generators.nix index e8772f9d6486..c159a254bb75 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -14,7 +14,7 @@ * Documentation in the manual, #sec-generators */ { lib }: -with (lib).trivial; + let inherit (builtins) addErrorContext @@ -25,6 +25,7 @@ let filter head isAttrs + isBool isFloat isInt isList @@ -36,6 +37,7 @@ let replaceStrings split tail + typeOf ; inherit (lib.attrsets) @@ -65,6 +67,8 @@ let ; inherit (lib.trivial) + const + id isFunction # Note: not the builtin, considers `__functor` in attrsets. functionArgs # Note: not the builtin; considers `__functor` in attrsets. ; From 8422fe83b9576da478f5d66ddb0da4b00b215558 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Wed, 6 Mar 2024 16:34:08 -0800 Subject: [PATCH 6/7] lib/generators: use the explicit public interface pattern This enables further refactoring without accidentally changing the public interface. --- lib/generators.nix | 56 ++++++++++++++++++++++++++++++---------------- 1 file 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; } From a7b4ee2dbef41e9e7ca09ea9625911d8e5e90325 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 14 Mar 2024 13:14:26 -0700 Subject: [PATCH 7/7] lib: use names from `lib` in `lib/generators.nix`, rather than `builtins` or submodules of `lib` There's not a lot of rhyme to which names are exported from which module, as I see it, but everything is found somewhere. --- lib/generators.nix | 60 +++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index c7b1b7fc75f9..5f42a98de709 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -16,67 +16,55 @@ { lib }: let - inherit (builtins) + inherit (lib) addErrorContext + assertMsg attrNames concatLists + concatMapStringsSep + concatStrings concatStringsSep + const elem + escape filter + flatten + foldl + functionArgs # Note: not the builtin; considers `__functor` in attrsets. + gvariant + hasInfix head + id + init isAttrs isBool + isDerivation isFloat + isFunction # Note: not the builtin; considers `__functor` in attrsets. isInt isList isPath isString + last length mapAttrs - match - replaceStrings - split - tail - toJSON - typeOf - ; - - inherit (lib.attrsets) - isDerivation mapAttrsToList - recursiveUpdate - ; - - inherit (lib.lists) - init - flatten - foldl - last optionals + recursiveUpdate + replaceStrings reverseList + splitString + tail toList ; inherit (lib.strings) - concatMapStringsSep - concatStrings - escape escapeNixIdentifier floatToString - hasInfix - splitString - ; - - inherit (lib.trivial) - const - id - isFunction # Note: not the builtin, considers `__functor` in attrsets. - functionArgs # Note: not the builtin; considers `__functor` in attrsets. - ; - - inherit (lib) - assertMsg - gvariant + match + split + toJSON + typeOf ; ## -- HELPER FUNCTIONS & DEFAULTS --