@ -252,8 +252,8 @@ rec {
merge = mergeEqualOption ;
} ;
# drop this in the future:
list = builtins . trace " ` t y p e s . l i s t ` i s d e p r e c a t e d ; u s e ` t y p e s . l i s t O f ` i n s t e a d " types . listOf ;
# TODO: drop this in the future:
list = builtins . trace " ` t y p e s . l i s t ` h a s b e e n r e m o v e d ; p l e a s e u s e ` t y p e s . l i s t O f ` i n s t e a d " types . listOf ;
listOf = elemType : mkOptionType rec {
name = " l i s t O f " ;
@ -326,110 +326,15 @@ rec {
functor = ( defaultFunctor name ) // { wrapped = elemType ; } ;
} ;
# List or attribute set of ...
loaOf = elemType :
let
convertAllLists = loc : defs :
let
padWidth = stringLength ( toString ( length defs ) ) ;
unnamedPrefix = i : " u n n a m e d - " + fixedWidthNumber padWidth i + " . " ;
in
imap1 ( i : convertIfList loc ( unnamedPrefix i ) ) defs ;
convertIfList = loc : unnamedPrefix : def :
if isList def . value then
let
padWidth = stringLength ( toString ( length def . value ) ) ;
unnamed = i : unnamedPrefix + fixedWidthNumber padWidth i ;
anyString = placeholder " n a m e " ;
nameAttrs = [
{ path = [ " e n v i r o n m e n t " " e t c " ] ;
name = " t a r g e t " ;
}
{ path = [ " c o n t a i n e r s " anyString " b i n d M o u n t s " ] ;
name = " m o u n t P o i n t " ;
}
{ path = [ " p r o g r a m s " " s s h " " k n o w n H o s t s " ] ;
# hostNames is actually a list so we would need to handle it only when singleton
name = " h o s t N a m e s " ;
}
{ path = [ " f i l e S y s t e m s " ] ;
name = " m o u n t P o i n t " ;
}
{ path = [ " b o o t " " s p e c i a l F i l e S y s t e m s " ] ;
name = " m o u n t P o i n t " ;
}
{ path = [ " s e r v i c e s " " z n a p z e n d " " z e t u p " ] ;
name = " d a t a s e t " ;
}
{ path = [ " s e r v i c e s " " z n a p z e n d " " z e t u p " anyString " d e s t i n a t i o n s " ] ;
name = " l a b e l " ;
}
{ path = [ " s e r v i c e s " " g e o c l u e 2 " " a p p C o n f i g " ] ;
name = " d e s k t o p I D " ;
}
] ;
matched = let
equals = a : b : b == anyString || a == b ;
fallback = { name = " n a m e " ; } ;
in findFirst ( { path , . . . }: all ( v : v == true ) ( zipListsWith equals loc path ) ) fallback nameAttrs ;
nameAttr = matched . name ;
nameValueOld = value :
if isList value then
if length value > 0 then
" [ " + concatMapStringsSep " " escapeNixString value + " ] "
else
" [ ] "
else
escapeNixString value ;
nameValueNew = value : unnamed :
if isList value then
if length value > 0 then
head value
else
unnamed
else
value ;
res =
{ inherit ( def ) file ;
value = listToAttrs (
imap1 ( elemIdx : elem :
{ name = nameValueNew ( elem . ${ nameAttr } or ( unnamed elemIdx ) ) ( unnamed elemIdx ) ;
value = elem ;
} ) def . value ) ;
} ;
option = concatStringsSep " . " loc ;
sample = take 3 def . value ;
more = lib . optionalString ( length def . value > 3 ) " . . . " ;
list = concatMapStrings ( x : '' { ${ nameAttr } = ${ nameValueOld ( x . ${ nameAttr } or " u n n a m e d " ) } ; . . . } '' ) sample ;
set = concatMapStrings ( x : '' ${ nameValueNew ( x . ${ nameAttr } or " u n n a m e d " ) " u n n a m e d " } = { . . . } ; '' ) sample ;
msg = ''
In file $ { def . file }
a list is being assigned to the option config . ${ option } .
This will soon be an error as type loaOf is deprecated .
See https://github.com/NixOS/nixpkgs/pull/63103 for more information .
Do
$ { option } =
{ ${ set } ${ more } }
instead of
$ { option } =
[ $ { list } $ { more } ]
'' ;
in
lib . warn msg res
else
def ;
attrOnly = attrsOf elemType ;
in mkOptionType rec {
name = " l o a O f " ;
description = " l i s t o r a t t r i b u t e s e t o f ${ elemType . description } s " ;
check = x : isList x || isAttrs x ;
merge = loc : defs : attrOnly . merge loc ( convertAllLists loc defs ) ;
emptyValue = { value = { } ; } ;
getSubOptions = prefix : elemType . getSubOptions ( prefix ++ [ " < n a m e ? > " ] ) ;
getSubModules = elemType . getSubModules ;
substSubModules = m : loaOf ( elemType . substSubModules m ) ;
functor = ( defaultFunctor name ) // { wrapped = elemType ; } ;
} ;
# TODO: drop this in the future:
loaOf =
let msg =
''
` types . loaOf ` has been removed and mixing lists with attribute values
is no longer possible ; please use ` types . attrsOf ` instead .
See https://github.com/NixOS/nixpkgs/issues/1800 for the motivation .
'' ;
in builtins . trace msg types . attrsOf ;
# Value of given type but with no merging (i.e. `uniq list`s are not concatenated).
uniq = elemType : mkOptionType rec {