2024-08-24 13:10:45 +02:00
|
|
|
{ nixpkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2024-08-24 15:09:07 +02:00
|
|
|
inherit (builtins)
|
|
|
|
filter isList
|
|
|
|
isString stringLength
|
|
|
|
unsafeDiscardStringContext;
|
|
|
|
|
|
|
|
inherit (nixpkgs.lib.lists) flatten subtractLists;
|
2024-08-24 13:10:45 +02:00
|
|
|
inherit (nixpkgs.lib.strings) addContextFrom;
|
|
|
|
|
|
|
|
split = strOrList:
|
2024-08-24 15:09:07 +02:00
|
|
|
if isList strOrList then flatten strOrList
|
2024-08-24 13:10:45 +02:00
|
|
|
else builtins.split "[[:space:]]+" strOrList
|
2024-08-24 15:09:07 +02:00
|
|
|
|> filter (flag: isString flag && stringLength flag > 0);
|
2024-08-24 13:10:45 +02:00
|
|
|
|
|
|
|
remerge = strOrList: list:
|
|
|
|
if isList strOrList then list
|
2024-08-24 15:09:07 +02:00
|
|
|
else toString list |> addContextFrom strOrList;
|
2024-08-24 13:10:45 +02:00
|
|
|
in {
|
|
|
|
remove = rem: strOrList: split strOrList
|
2024-08-24 13:16:55 +02:00
|
|
|
|> subtractLists rem
|
2024-08-24 13:10:45 +02:00
|
|
|
|> remerge strOrList;
|
|
|
|
|
|
|
|
subst = sub: strOrList: split strOrList
|
2024-08-24 15:09:07 +02:00
|
|
|
|> map (flag: sub.${unsafeDiscardStringContext flag} or flag)
|
2024-08-24 13:10:45 +02:00
|
|
|
|> remerge strOrList;
|
|
|
|
}
|