lib/flags: Avoid attrset issue with string context
This commit is contained in:
parent
ad369da0f9
commit
9044b74987
1 changed files with 10 additions and 7 deletions
|
@ -1,25 +1,28 @@
|
||||||
{ nixpkgs, ... }:
|
{ nixpkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) filter isList isString stringLength;
|
inherit (builtins)
|
||||||
inherit (nixpkgs.lib.lists) subtractLists;
|
filter isList
|
||||||
|
isString stringLength
|
||||||
|
unsafeDiscardStringContext;
|
||||||
|
|
||||||
|
inherit (nixpkgs.lib.lists) flatten subtractLists;
|
||||||
inherit (nixpkgs.lib.strings) addContextFrom;
|
inherit (nixpkgs.lib.strings) addContextFrom;
|
||||||
|
|
||||||
split = strOrList:
|
split = strOrList:
|
||||||
if isList strOrList then strOrList
|
if isList strOrList then flatten strOrList
|
||||||
else builtins.split "[[:space:]]+" strOrList
|
else builtins.split "[[:space:]]+" strOrList
|
||||||
|> filter (flag: isString flag && stringLength flag > 0)
|
|> filter (flag: isString flag && stringLength flag > 0);
|
||||||
|> map (flag: addContextFrom strOrList flag);
|
|
||||||
|
|
||||||
remerge = strOrList: list:
|
remerge = strOrList: list:
|
||||||
if isList strOrList then list
|
if isList strOrList then list
|
||||||
else toString list;
|
else toString list |> addContextFrom strOrList;
|
||||||
in {
|
in {
|
||||||
remove = rem: strOrList: split strOrList
|
remove = rem: strOrList: split strOrList
|
||||||
|> subtractLists rem
|
|> subtractLists rem
|
||||||
|> remerge strOrList;
|
|> remerge strOrList;
|
||||||
|
|
||||||
subst = sub: strOrList: split strOrList
|
subst = sub: strOrList: split strOrList
|
||||||
|> map (flag: sub.${flag} or flag)
|
|> map (flag: sub.${unsafeDiscardStringContext flag} or flag)
|
||||||
|> remerge strOrList;
|
|> remerge strOrList;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue