various: lib usage improvements - prefer removeAttrs over filterAttrs (#455787)

This commit is contained in:
Johannes Kirschbauer
2025-10-27 16:17:52 +00:00
committed by GitHub
20 changed files with 27 additions and 27 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ let
]
++ lib.pipe config.i18n.extraLocaleSettings [
# See description of extraLocaleSettings for why is this ignored here.
(lib.filterAttrs (n: v: n != "LANGUAGE"))
(x: lib.removeAttrs x [ "LANGUAGE" ])
(lib.mapAttrs (n: v: (sanitizeUTF8Capitalization v)))
(lib.mapAttrsToList (LCRole: lang: lang + "/" + (config.i18n.localeCharsets.${LCRole} or "UTF-8")))
]
+4 -6
View File
@@ -101,14 +101,12 @@ let
# removes NixOS special and unused attributes
sensorToConf =
{ type, query, ... }@args:
(lib.filterAttrs (
k: v:
v != null
&& !(lib.elem k [
(lib.filterAttrs (k: v: v != null) (
lib.removeAttrs args [
"type"
"query"
])
) args)
]
))
// {
"${type}" = query;
};
+1 -1
View File
@@ -403,7 +403,7 @@ in
}
];
services.public-inbox.settings = filterAttrsRecursive (n: v: v != null) {
publicinbox = mapAttrs (n: filterAttrs (n: v: n != "description")) cfg.inboxes;
publicinbox = mapAttrs (n: v: removeAttrs v [ "description" ]) cfg.inboxes;
};
users = {
users.public-inbox = {
@@ -126,7 +126,7 @@ let
'';
# Get a submodule without any embedded metadata:
_filter = x: filterAttrs (k: v: k != "_module") x;
_filter = x: removeAttrs x [ "_module" ];
# https://grafana.com/docs/grafana/latest/administration/provisioning/#datasources
grafanaTypes.datasourceConfig = types.submodule {
@@ -15,6 +15,7 @@ let
nameValuePair
toLower
filterAttrs
removeAttrs
escapeShellArg
literalExpression
mkIf
@@ -41,7 +42,7 @@ let
)
else
nameValuePair (toLower name) value
) (filterAttrs (n: _: !(n == "_module")) cfg.configuration)
) (removeAttrs cfg.configuration [ "_module" ])
)
);
+1 -1
View File
@@ -270,7 +270,7 @@ let
lib.updateManyAttrsByPath [
{
path = lib.init pathList;
update = old: lib.filterAttrs (n: v: n != (lib.last pathList)) old;
update = old: lib.removeAttrs old [ (lib.last pathList) ];
}
] set;
in
+1 -1
View File
@@ -592,7 +592,7 @@ in
'';
enabledUpstreamSystemUnits = filter (n: !elem n cfg.suppressedSystemUnits) upstreamSystemUnits;
enabledUnits = filterAttrs (n: v: !elem n cfg.suppressedSystemUnits) cfg.units;
enabledUnits = removeAttrs cfg.units cfg.suppressedSystemUnits;
in
{
@@ -35,9 +35,7 @@ let
}) supportedDevices
);
unsupportedDeviceIds = lib.filterAttrs (
name: value: !(lib.hasAttr name supportedDeviceIds)
) deviceIds;
unsupportedDeviceIds = lib.removeAttrs deviceIds (lib.attrNames supportedDeviceIds);
componentHashes = {
"arria_lite" = "sha256-ASvi9YX15b4XXabGjkuR5wl9wDwCijl8s750XTR/4XU=";
@@ -29,7 +29,7 @@ buildPythonPackage rec {
];
optional-dependencies = {
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
gevent = [ gevent ];
redis = [ redis ];
};
@@ -34,7 +34,7 @@ buildPythonPackage rec {
code_syntax_highlighting = [ pygments ];
wavedrom = [ wavedrom ];
latex = [ latex2mathml ];
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
};
meta = {
@@ -50,7 +50,7 @@ buildPythonPackage rec {
optional-dependencies = {
botocore = [ botocore ];
zarr = [ zarr ];
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
};
nativeCheckInputs = [
@@ -53,7 +53,7 @@ buildPythonPackage rec {
];
optional-dependencies = {
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
atari = [
# multi-agent-ale-py
pygame
@@ -55,7 +55,7 @@ buildPythonPackage rec {
optional-dependencies = {
adlfs = [ adlfs ];
azure = [ azure-storage-blob ];
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
};
pythonImportsCheck = [
@@ -67,7 +67,7 @@ buildPythonPackage rec {
ratelimit
];
avro = [ fastavro ];
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
};
nativeCheckInputs = [
@@ -46,7 +46,7 @@ buildPythonPackage rec {
];
optional-dependencies = {
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
cli = [
click
consolekit
@@ -92,7 +92,7 @@ buildPythonPackage rec {
];
optional-dependencies = {
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
argparse = [
docstring-parser
@@ -55,7 +55,7 @@ buildPythonPackage rec {
pythonImportsCheck = [ "whey" ];
optional-dependencies = {
all = lib.flatten (lib.attrValues (lib.filterAttrs (n: v: n != "all") optional-dependencies));
all = lib.flatten (lib.attrValues (lib.removeAttrs optional-dependencies [ "all" ]));
editable = [
editables
];
@@ -99,7 +99,7 @@ let
let
# only formatters that were not requested
unwanted = lib.pipe knownFormatters [
(lib.filterAttrs (fmt: _: !(lib.elem fmt supportedFormatters)))
(fmts: lib.removeAttrs fmts supportedFormatters)
lib.attrsToList
];
# all flags to disable
+1 -1
View File
@@ -57,7 +57,7 @@
in
{
name = lib.removeSuffix ".patch" src.name;
patch = fetchurl (lib.filterAttrs (k: v: k != "extra") src);
patch = fetchurl (lib.removeAttrs src [ "extra" ]);
extra = src.extra;
inherit version sha256;
};
+4 -1
View File
@@ -731,7 +731,10 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check
(disallowedPackages prevStage)
# Only cctools and ld64 are rebuilt from `bintoolsPackages` to avoid rebuilding their dependencies
# again in this stage after building them in stage 1.
(lib.filterAttrs (name: _: name != "ld64" && name != "cctools") (bintoolsPackages prevStage))
(lib.removeAttrs (bintoolsPackages prevStage) [
"ld64"
"cctools"
])
(llvmToolsDeps prevStage)
(sdkPackages prevStage)
(sdkPackagesNoCC prevStage)