11{ lib , pkgs } :
22let
3+ inherit ( lib )
4+ concatStringsSep
5+ escape
6+ flatten
7+ id
8+ isAttrs
9+ isFloat
10+ isInt
11+ isList
12+ isString
13+ mapAttrs
14+ mapAttrsToList
15+ mkOption
16+ optionalAttrs
17+ optionalString
18+ pipe
19+ types
20+ singleton
21+ warn
22+ ;
23+
24+ inherit ( lib . generators )
25+ mkValueStringDefault
26+ toGitINI
27+ toINI
28+ toINIWithGlobalSection
29+ toKeyValue
30+ toLua
31+ mkLuaInline
32+ ;
33+
334 inherit ( lib . types )
435 attrsOf
36+ atom
537 bool
638 coercedTo
739 either
1547 oneOf
1648 path
1749 str
50+ submodule
1851 ;
1952
2053 # Attributes added accidentally in https://github.com/NixOS/nixpkgs/pull/335232 (2024-08-18)
2154 # Deprecated in https://github.com/NixOS/nixpkgs/pull/415666 (2025-06)
22- aliases =
23- lib . mapAttrs ( name : lib . warn "`formats.${ name } ` is deprecated; use `lib.types.${ name } ` instead." )
24- {
25- inherit
26- attrsOf
27- bool
28- coercedTo
29- either
30- float
31- int
32- listOf
33- luaInline
34- mkOptionType
35- nonEmptyListOf
36- nullOr
37- oneOf
38- path
39- str
40- ;
41- } ;
55+ allowAliases = pkgs . config . allowAliases or false ;
56+ aliasWarning = name : warn "`formats.${ name } ` is deprecated; use `lib.types.${ name } ` instead." ;
57+ aliases = mapAttrs aliasWarning {
58+ inherit
59+ attrsOf
60+ bool
61+ coercedTo
62+ either
63+ float
64+ int
65+ listOf
66+ luaInline
67+ mkOptionType
68+ nonEmptyListOf
69+ nullOr
70+ oneOf
71+ path
72+ str
73+ ;
74+ } ;
4275in
43- lib . optionalAttrs pkgs . config . allowAliases aliases
76+ optionalAttrs allowAliases aliases
4477// rec {
4578
4679 /*
@@ -188,7 +221,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
188221 } :
189222 let
190223 singleIniAtomOr =
191- if atomsCoercedToLists then coercedTo singleIniAtom lib . singleton else either singleIniAtom ;
224+ if atomsCoercedToLists then coercedTo singleIniAtom singleton else either singleIniAtom ;
192225 in
193226 if listsAsDuplicateKeys then
194227 singleIniAtomOr ( listOf singleIniAtom )
@@ -212,9 +245,9 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
212245 maybeToList =
213246 listToValue :
214247 if listToValue != null then
215- lib . mapAttrs ( key : val : if lib . isList val then listToValue val else val )
248+ mapAttrs ( key : val : if isList val then listToValue val else val )
216249 else
217- lib . id ;
250+ id ;
218251 in
219252 {
220253 ini =
@@ -239,14 +272,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
239272 in
240273 {
241274
242- type = lib . types . attrsOf ( iniSection atom ) ;
275+ type = attrsOf ( iniSection atom ) ;
243276 lib . types . atom = atom ;
244277
245278 generate =
246279 name : value :
247- lib . pipe value [
248- ( lib . mapAttrs ( _ : maybeToList listToValue ) )
249- ( lib . generators . toINI (
280+ pipe value [
281+ ( mapAttrs ( _ : maybeToList listToValue ) )
282+ ( toINI (
250283 removeAttrs args [
251284 "listToValue"
252285 "atomsCoercedToLists"
@@ -277,14 +310,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
277310 } ;
278311 in
279312 {
280- type = lib . types . submodule {
313+ type = submodule {
281314 options = {
282- sections = lib . mkOption rec {
283- type = lib . types . attrsOf ( iniSection atom ) ;
315+ sections = mkOption rec {
316+ type = attrsOf ( iniSection atom ) ;
284317 default = { } ;
285318 description = type . description ;
286319 } ;
287- globalSection = lib . mkOption rec {
320+ globalSection = mkOption rec {
288321 type = iniSection atom ;
289322 default = { } ;
290323 description = "global " + type . description ;
@@ -300,14 +333,14 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
300333 ...
301334 } :
302335 pkgs . writeText name (
303- lib . generators . toINIWithGlobalSection
336+ toINIWithGlobalSection
304337 ( removeAttrs args [
305338 "listToValue"
306339 "atomsCoercedToLists"
307340 ] )
308341 {
309342 globalSection = maybeToList listToValue globalSection ;
310- sections = lib . mapAttrs ( _ : maybeToList listToValue ) sections ;
343+ sections = mapAttrs ( _ : maybeToList listToValue ) sections ;
311344 }
312345 ) ;
313346 } ;
@@ -327,7 +360,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
327360 {
328361 type = attrsOf ( attrsOf ( either atom ( attrsOf atom ) ) ) ;
329362 lib . types . atom = atom ;
330- generate = name : value : pkgs . writeText name ( lib . generators . toGitINI value ) ;
363+ generate = name : value : pkgs . writeText name ( toGitINI value ) ;
331364 } ;
332365
333366 }
@@ -343,7 +376,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
343376 # optional config options.
344377 systemd =
345378 let
346- mkValueString = lib . generators . mkValueStringDefault { } ;
379+ mkValueString = mkValueStringDefault { } ;
347380 mkKeyValue = k : v : if v == null then "# ${ k } is unset" else "${ k } = ${ mkValueString v } " ;
348381 in
349382 ini {
@@ -379,12 +412,12 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
379412
380413 atom =
381414 if listsAsDuplicateKeys then
382- coercedTo singleAtom lib . singleton ( listOf singleAtom )
415+ coercedTo singleAtom singleton ( listOf singleAtom )
383416 // {
384417 description = singleAtom . description + " or a list of them for duplicate keys" ;
385418 }
386419 else if listToValue != null then
387- coercedTo singleAtom lib . singleton ( nonEmptyListOf singleAtom )
420+ coercedTo singleAtom singleton ( nonEmptyListOf singleAtom )
388421 // {
389422 description = singleAtom . description + " or a non-empty list of them" ;
390423 }
@@ -399,13 +432,11 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
399432 let
400433 transformedValue =
401434 if listToValue != null then
402- lib . mapAttrs ( key : val : if lib . isList val then listToValue val else val ) value
435+ mapAttrs ( key : val : if isList val then listToValue val else val ) value
403436 else
404437 value ;
405438 in
406- pkgs . writeText name (
407- lib . generators . toKeyValue ( removeAttrs args [ "listToValue" ] ) transformedValue
408- ) ;
439+ pkgs . writeText name ( toKeyValue ( removeAttrs args [ "listToValue" ] ) transformedValue ) ;
409440
410441 } ;
411442
@@ -543,18 +574,18 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
543574 "true"
544575 else if value == false then
545576 "false"
546- else if lib . isInt value || lib . isFloat value then
577+ else if isInt value || isFloat value then
547578 toString value
548- else if lib . isString value then
579+ else if isString value then
549580 string value
550- else if lib . isAttrs value then
581+ else if isAttrs value then
551582 attrs value
552- else if lib . isList value then
583+ else if isList value then
553584 list value
554585 else
555586 abort "formats.elixirConf: should never happen (value = ${ value } )" ;
556587
557- escapeElixir = lib . escape [
588+ escapeElixir = escape [
558589 "\\ "
559590 "#"
560591 "\" "
@@ -568,11 +599,11 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
568599 else
569600 let
570601 toKeyword = name : value : "${ name } : ${ toElixir value } " ;
571- keywordList = lib . concatStringsSep ", " ( lib . mapAttrsToList toKeyword set ) ;
602+ keywordList = concatStringsSep ", " ( mapAttrsToList toKeyword set ) ;
572603 in
573604 "[" + keywordList + "]" ;
574605
575- listContent = values : lib . concatStringsSep ", " ( map toElixir values ) ;
606+ listContent = values : concatStringsSep ", " ( map toElixir values ) ;
576607
577608 list = values : "[" + ( listContent values ) + "]" ;
578609
@@ -593,7 +624,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
593624 set :
594625 let
595626 toEntry = name : value : "${ toElixir name } => ${ toElixir value } " ;
596- entries = lib . concatStringsSep ", " ( lib . mapAttrsToList toEntry set ) ;
627+ entries = concatStringsSep ", " ( mapAttrsToList toEntry set ) ;
597628 in
598629 "%{${ entries } }" ;
599630
@@ -605,13 +636,13 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
605636 keyConfig =
606637 rootKey : key : value :
607638 "config ${ rootKey } , ${ key } , ${ toElixir value } " ;
608- keyConfigs = rootKey : values : lib . mapAttrsToList ( keyConfig rootKey ) values ;
609- rootConfigs = lib . flatten ( lib . mapAttrsToList keyConfigs values ) ;
639+ keyConfigs = rootKey : values : mapAttrsToList ( keyConfig rootKey ) values ;
640+ rootConfigs = flatten ( mapAttrsToList keyConfigs values ) ;
610641 in
611642 ''
612643 import Config
613644
614- ${ lib . concatStringsSep "\n " rootConfigs }
645+ ${ concatStringsSep "\n " rootConfigs }
615646 '' ;
616647 in
617648 {
@@ -715,7 +746,7 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
715746 # Wrap standard types, since anything in the Elixir configuration
716747 # can be raw Elixir
717748 }
718- // lib . mapAttrs ( _name : type : elixirOr type ) lib . types ;
749+ // mapAttrs ( _name : type : elixirOr type ) types ;
719750 } ;
720751
721752 generate =
@@ -771,12 +802,12 @@ lib.optionalAttrs pkgs.config.allowAliases aliases
771802 inherit columnWidth ;
772803 inherit indentWidth ;
773804 indentType = if indentUsingTabs then "Tabs" else "Spaces" ;
774- value = lib . generators . toLua { inherit asBindings multiline ; } value ;
805+ value = toLua { inherit asBindings multiline ; } value ;
775806 passAsFile = [ "value" ] ;
776807 preferLocalBuild = true ;
777808 }
778809 ''
779- ${ lib . optionalString ( ! asBindings ) ''
810+ ${ optionalString ( ! asBindings ) ''
780811 echo -n 'return ' >> $out
781812 '' }
782813 cat $valuePath >> $out
0 commit comments