From bc3d5934d7f276a21537b40159491257ee163d94 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Tue, 14 Feb 2023 19:11:59 +0100 Subject: [PATCH] treewide: use lib.optionals --- .../editors/vscode/extensions/vscodeEnv.nix | 3 +-- .../file-managers/spacefm/default.nix | 2 +- pkgs/applications/kde/kdevelop/wrapper.nix | 4 ++-- .../networking/browsers/chromium/browser.nix | 4 +--- .../networking/browsers/firefox/wrapper.nix | 4 ++-- pkgs/applications/radio/gnuradio/shared.nix | 18 ++++++++---------- pkgs/applications/radio/gnuradio/wrapper.nix | 7 ++----- pkgs/build-support/build-setupcfg/default.nix | 7 ++++--- .../dotnet/make-nuget-source/default.nix | 4 +--- .../interpreters/python/default.nix | 2 +- .../python/python-packages-base.nix | 2 +- pkgs/development/java-modules/m2install.nix | 2 +- .../androidenv/compose-android-packages.nix | 6 +++--- .../python-modules/polars/default.nix | 2 +- pkgs/games/xjump/default.nix | 8 ++------ pkgs/stdenv/generic/check-meta.nix | 2 +- pkgs/stdenv/native/default.nix | 6 +++--- pkgs/tools/archivers/zip/default.nix | 2 +- pkgs/tools/nix/info/default.nix | 2 +- pkgs/tools/typesetting/tex/nix/default.nix | 5 +++-- pkgs/top-level/darwin-packages.nix | 2 +- pkgs/top-level/release-haskell.nix | 4 +--- pkgs/top-level/release-python.nix | 2 +- 23 files changed, 43 insertions(+), 57 deletions(-) diff --git a/pkgs/applications/editors/vscode/extensions/vscodeEnv.nix b/pkgs/applications/editors/vscode/extensions/vscodeEnv.nix index 7c58a4bdfb34..818cca51772a 100644 --- a/pkgs/applications/editors/vscode/extensions/vscodeEnv.nix +++ b/pkgs/applications/editors/vscode/extensions/vscodeEnv.nix @@ -25,8 +25,7 @@ }: let mutableExtensionsFilePath = toString mutableExtensionsFile; - mutableExtensions = if builtins.pathExists mutableExtensionsFile - then import mutableExtensionsFilePath else []; + mutableExtensions = lib.optionals builtins.pathExists mutableExtensionsFile (import mutableExtensionsFilePath); vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { inherit lib writeShellScriptBin extensionsFromVscodeMarketplace; vscodeDefault = vscode; diff --git a/pkgs/applications/file-managers/spacefm/default.nix b/pkgs/applications/file-managers/spacefm/default.nix index 334228f98ead..605340cbc85c 100644 --- a/pkgs/applications/file-managers/spacefm/default.nix +++ b/pkgs/applications/file-managers/spacefm/default.nix @@ -49,7 +49,7 @@ stdenv.mkDerivation rec { buildInputs = [ gtk3 udev desktop-file-utils shared-mime-info wrapGAppsHook ffmpegthumbnailer jmtpfs lsof udisks2 - ] ++ (if ifuseSupport then [ ifuse ] else []); + ] ++ (lib.optionals ifuseSupport [ ifuse ]); # Introduced because ifuse doesn't build due to CVEs in libplist # Revert when libplist builds again… diff --git a/pkgs/applications/kde/kdevelop/wrapper.nix b/pkgs/applications/kde/kdevelop/wrapper.nix index 86d3de9eb39a..c73f2bba7b50 100644 --- a/pkgs/applications/kde/kdevelop/wrapper.nix +++ b/pkgs/applications/kde/kdevelop/wrapper.nix @@ -1,7 +1,7 @@ -{ symlinkJoin, kdevelop-unwrapped, plugins ? null }: +{ lib, symlinkJoin, kdevelop-unwrapped, plugins ? null }: symlinkJoin { name = "kdevelop-with-plugins"; - paths = [ kdevelop-unwrapped ] ++ (if plugins != null then plugins else []); + paths = [ kdevelop-unwrapped ] ++ (lib.optionals (plugins != null) plugins); } diff --git a/pkgs/applications/networking/browsers/chromium/browser.nix b/pkgs/applications/networking/browsers/chromium/browser.nix index 2f39e82f3b24..1eea3e8962f8 100644 --- a/pkgs/applications/networking/browsers/chromium/browser.nix +++ b/pkgs/applications/networking/browsers/chromium/browser.nix @@ -90,9 +90,7 @@ mkChromiumDerivation (base: rec { license = if enableWideVine then lib.licenses.unfree else lib.licenses.bsd3; platforms = lib.platforms.linux; mainProgram = "chromium"; - hydraPlatforms = if (channel == "stable" || channel == "ungoogled-chromium") - then ["aarch64-linux" "x86_64-linux"] - else []; + hydraPlatforms = lib.optionals (channel == "stable" || channel == "ungoogled-chromium") ["aarch64-linux" "x86_64-linux"]; timeout = 172800; # 48 hours (increased from the Hydra default of 10h) }; }) diff --git a/pkgs/applications/networking/browsers/firefox/wrapper.nix b/pkgs/applications/networking/browsers/firefox/wrapper.nix index 06bd49facb81..de68807d8f25 100644 --- a/pkgs/applications/networking/browsers/firefox/wrapper.nix +++ b/pkgs/applications/networking/browsers/firefox/wrapper.nix @@ -98,7 +98,7 @@ let usesNixExtensions = nixExtensions != null; - nameArray = builtins.map(a: a.name) (if usesNixExtensions then nixExtensions else []); + nameArray = builtins.map(a: a.name) (lib.optionals usesNixExtensions nixExtensions); requiresSigning = browser ? MOZ_REQUIRE_SIGNING -> toString browser.MOZ_REQUIRE_SIGNING != ""; @@ -114,7 +114,7 @@ let throw "nixExtensions has an invalid entry. Missing extid attribute. Please use fetchfirefoxaddon" else a - ) (if usesNixExtensions then nixExtensions else []); + ) (lib.optionals usesNixExtensions nixExtensions); enterprisePolicies = { diff --git a/pkgs/applications/radio/gnuradio/shared.nix b/pkgs/applications/radio/gnuradio/shared.nix index ff6aaf35bea0..bdbc22cb787d 100644 --- a/pkgs/applications/radio/gnuradio/shared.nix +++ b/pkgs/applications/radio/gnuradio/shared.nix @@ -37,20 +37,18 @@ rec { ); nativeBuildInputs = lib.flatten (lib.mapAttrsToList ( feat: info: ( - if hasFeature feat then - (if builtins.hasAttr "native" info then info.native else []) ++ - (if builtins.hasAttr "pythonNative" info then info.pythonNative else []) - else - [] + lib.optionals (hasFeature feat) ( + (lib.optionals (builtins.hasAttr "native" info) info.native) ++ + (lib.optionals (builtins.hasAttr "pythonNative" info) info.pythonNative) + ) ) ) featuresInfo); buildInputs = lib.flatten (lib.mapAttrsToList ( feat: info: ( - if hasFeature feat then - (if builtins.hasAttr "runtime" info then info.runtime else []) ++ - (if builtins.hasAttr "pythonRuntime" info then info.pythonRuntime else []) - else - [] + lib.optionals (hasFeature feat) ( + (lib.optionals (builtins.hasAttr "runtime" info) info.runtime) ++ + (lib.optionals (builtins.hasAttr "pythonRuntime" info) info.pythonRuntime) + ) ) ) featuresInfo); cmakeFlags = lib.mapAttrsToList ( diff --git a/pkgs/applications/radio/gnuradio/wrapper.nix b/pkgs/applications/radio/gnuradio/wrapper.nix index 926022353e41..c38c89fc459b 100644 --- a/pkgs/applications/radio/gnuradio/wrapper.nix +++ b/pkgs/applications/radio/gnuradio/wrapper.nix @@ -41,12 +41,9 @@ let ++ (builtins.map unwrapped.python.pkgs.toPythonModule extraPackages) ++ lib.flatten (lib.mapAttrsToList ( feat: info: ( - if unwrapped.hasFeature feat then - (if builtins.hasAttr "pythonRuntime" info then info.pythonRuntime else []) - else - [] + lib.optionals ((unwrapped.hasFeature feat) && (builtins.hasAttr "pythonRuntime" info)) info.pythonRuntime ) - ) unwrapped.featuresInfo) + ) unwrapped.featuresInfo) ; pythonEnv = unwrapped.python.withPackages(ps: pythonPkgs); diff --git a/pkgs/build-support/build-setupcfg/default.nix b/pkgs/build-support/build-setupcfg/default.nix index bc6482f0a88e..5737989249af 100644 --- a/pkgs/build-support/build-setupcfg/default.nix +++ b/pkgs/build-support/build-setupcfg/default.nix @@ -6,8 +6,8 @@ # * application: Whether this package is a python library or an # application which happens to be written in python. # * doCheck: Whether to run the test suites. -pythonPackages: -{ src, info, meta ? {}, application ? false, doCheck ? true }: let +lib: pythonPackages: +{ src, info, meta ? {}, application ? false, doCheck ? true}: let build = if application then pythonPackages.buildPythonApplication else pythonPackages.buildPythonPackage; @@ -18,7 +18,8 @@ in build { nativeBuildInputs = map (p: pythonPackages.${p}) ( (info.setup_requires or []) ++ - (if doCheck then (info.tests_require or []) else [])); + (lib.optionals doCheck (info.tests_require or [])) + ); propagatedBuildInputs = map (p: pythonPackages.${p}) (info.install_requires or []); diff --git a/pkgs/build-support/dotnet/make-nuget-source/default.nix b/pkgs/build-support/dotnet/make-nuget-source/default.nix index 8dc77f3aac03..ea1c5328082d 100644 --- a/pkgs/build-support/dotnet/make-nuget-source/default.nix +++ b/pkgs/build-support/dotnet/make-nuget-source/default.nix @@ -30,9 +30,7 @@ let meta.licence = let depLicenses = lib.splitString "\n" (builtins.readFile "${nuget-source}/share/licenses"); in (lib.flatten (lib.forEach depLicenses (spdx: - if (spdx != "") - then lib.getLicenseFromSpdxId spdx - else [] + lib.optionals (spdx != "") (lib.getLicenseFromSpdxId spdx) ))); }; in nuget-source diff --git a/pkgs/development/interpreters/python/default.nix b/pkgs/development/interpreters/python/default.nix index 76dc12005f8e..08e2717d41c1 100644 --- a/pkgs/development/interpreters/python/default.nix +++ b/pkgs/development/interpreters/python/default.nix @@ -63,7 +63,7 @@ hooks = import ./hooks/default.nix; keep = lib.extends hooks pythonPackagesFun; extra = _: {}; - optionalExtensions = cond: as: if cond then as else []; + optionalExtensions = cond: as: lib.optionals cond as; pythonExtension = import ../../../top-level/python-packages.nix; python2Extension = import ../../../top-level/python2-packages.nix; extensions = lib.composeManyExtensions ([ diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index d5b02223fd6c..ee94d4aec031 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -39,7 +39,7 @@ let })); # See build-setupcfg/default.nix for documentation. - buildSetupcfg = import ../../../build-support/build-setupcfg self; + buildSetupcfg = import ../../../build-support/build-setupcfg lib self; # Check whether a derivation provides a Python module. hasPythonModule = drv: drv?pythonModule && drv.pythonModule == python; diff --git a/pkgs/development/java-modules/m2install.nix b/pkgs/development/java-modules/m2install.nix index b35880e013c8..c058590c8574 100644 --- a/pkgs/development/java-modules/m2install.nix +++ b/pkgs/development/java-modules/m2install.nix @@ -5,7 +5,7 @@ , sha512 , type ? "jar" , suffix ? "" -, sourceProvenance ? (if type == "jar" then [ lib.sourceTypes.binaryBytecode ] else []) +, sourceProvenance ? (lib.optionals (type == "jar") [ lib.sourceTypes.binaryBytecode ]) }: let diff --git a/pkgs/development/mobile/androidenv/compose-android-packages.nix b/pkgs/development/mobile/androidenv/compose-android-packages.nix index 75f393b3f9e2..d27c1bb1cdc9 100644 --- a/pkgs/development/mobile/androidenv/compose-android-packages.nix +++ b/pkgs/development/mobile/androidenv/compose-android-packages.nix @@ -186,7 +186,7 @@ rec { system-images = lib.flatten (map (apiVersion: map (type: map (abiVersion: - if lib.hasAttrByPath [apiVersion type abiVersion] system-images-packages then + lib.optionals (lib.hasAttrByPath [apiVersion type abiVersion] system-images-packages) ( deployAndroidPackage { inherit os; package = system-images-packages.${apiVersion}.${type}.${abiVersion}; @@ -197,7 +197,7 @@ rec { sed -i '/^Addon.Vendor/d' source.properties ''; } - else [] + ) ) abiVersions ) systemImageTypes ) platformVersions); @@ -217,7 +217,7 @@ rec { }; # All NDK bundles. - ndk-bundles = if includeNDK then map makeNdkBundle ndkVersions else []; + ndk-bundles = lib.optionals includeNDK (map makeNdkBundle ndkVersions); # The "default" NDK bundle. ndk-bundle = if includeNDK then lib.findFirst (x: x != null) null ndk-bundles else null; diff --git a/pkgs/development/python-modules/polars/default.nix b/pkgs/development/python-modules/polars/default.nix index f265e24fe4ef..5424152a1e82 100644 --- a/pkgs/development/python-modules/polars/default.nix +++ b/pkgs/development/python-modules/polars/default.nix @@ -42,7 +42,7 @@ buildPythonPackage { # Revisit this whenever package or Rust is upgraded RUSTC_BOOTSTRAP = 1; - propagatedBuildInputs = if pythonOlder "3.10" then [ typing-extensions ] else []; + propagatedBuildInputs = lib.optionals (pythonOlder "3.10") [ typing-extensions ]; nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ]; diff --git a/pkgs/games/xjump/default.nix b/pkgs/games/xjump/default.nix index 3c13fc1a9b78..2c56e0bba4f6 100644 --- a/pkgs/games/xjump/default.nix +++ b/pkgs/games/xjump/default.nix @@ -12,12 +12,8 @@ stdenv.mkDerivation { nativeBuildInputs = [ autoconf automake ]; buildInputs = [ libX11 libXt libXpm libXaw ]; preConfigure = "autoreconf --install"; - patches = if stdenv.buildPlatform.isDarwin then [ ./darwin.patch ] else []; - configureFlags = - if localStateDir != null then - ["--localstatedir=${localStateDir}"] - else - []; + patches = lib.optionals stdenv.buildPlatform.isDarwin [ ./darwin.patch ]; + configureFlags = lib.optionals (localStateDir != null) ["--localstatedir=${localStateDir}"]; meta = with lib; { description = "The falling tower game"; diff --git a/pkgs/stdenv/generic/check-meta.nix b/pkgs/stdenv/generic/check-meta.nix index dd7825a409e2..4b0ca649ee94 100644 --- a/pkgs/stdenv/generic/check-meta.nix +++ b/pkgs/stdenv/generic/check-meta.nix @@ -322,7 +322,7 @@ let }" else "key 'meta.${k}' is unrecognized; expected one of: \n [${lib.concatMapStringsSep ", " (x: "'${x}'") (lib.attrNames metaTypes)}]"; - checkMeta = meta: if config.checkMeta then lib.remove null (lib.mapAttrsToList checkMetaAttr meta) else []; + checkMeta = meta: lib.optionals config.checkMeta (lib.remove null (lib.mapAttrsToList checkMetaAttr meta)); checkOutputsToInstall = attrs: let expectedOutputs = attrs.meta.outputsToInstall or []; diff --git a/pkgs/stdenv/native/default.nix b/pkgs/stdenv/native/default.nix index 87862b84bc1b..bae4ff2c93b2 100644 --- a/pkgs/stdenv/native/default.nix +++ b/pkgs/stdenv/native/default.nix @@ -12,9 +12,9 @@ let else "/bin/bash"; path = - (if system == "i686-solaris" then [ "/usr/gnu" ] else []) ++ - (if system == "i686-netbsd" then [ "/usr/pkg" ] else []) ++ - (if system == "x86_64-solaris" then [ "/opt/local/gnu" ] else []) ++ + (lib.optionals (system == "i686-solaris") [ "/usr/gnu" ]) ++ + (lib.optionals (system == "i686-netbsd") [ "/usr/pkg" ]) ++ + (lib.optionals (system == "x86_64-solaris") [ "/opt/local/gnu" ]) ++ ["/" "/usr" "/usr/local"]; prehookBase = '' diff --git a/pkgs/tools/archivers/zip/default.nix b/pkgs/tools/archivers/zip/default.nix index ab91cfc64834..82329537251e 100644 --- a/pkgs/tools/archivers/zip/default.nix +++ b/pkgs/tools/archivers/zip/default.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { "INSTALL=cp" ]; - patches = if (enableNLS && !stdenv.isCygwin) then [ ./natspec-gentoo.patch.bz2 ] else []; + patches = lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ]; buildInputs = lib.optional enableNLS libnatspec ++ lib.optional stdenv.isCygwin libiconv; diff --git a/pkgs/tools/nix/info/default.nix b/pkgs/tools/nix/info/default.nix index 151a53f15258..84bd3e891622 100644 --- a/pkgs/tools/nix/info/default.nix +++ b/pkgs/tools/nix/info/default.nix @@ -9,7 +9,7 @@ stdenv.mkDerivation { path = lib.makeBinPath ([ coreutils findutils gnugrep - ] ++ (if stdenv.isDarwin then [ darwin.DarwinTools ] else [])); + ] ++ (lib.optionals stdenv.isDarwin [ darwin.DarwinTools ])); is_darwin = if stdenv.isDarwin then "yes" else "no"; sandboxtest = ./sandbox.nix; diff --git a/pkgs/tools/typesetting/tex/nix/default.nix b/pkgs/tools/typesetting/tex/nix/default.nix index fbb6fdb0fe01..e9017333c943 100644 --- a/pkgs/tools/typesetting/tex/nix/default.nix +++ b/pkgs/tools/typesetting/tex/nix/default.nix @@ -82,7 +82,8 @@ rec { findLhs2TeXIncludes = - { rootFile + { lib + , rootFile }: builtins.genericClosure { @@ -97,7 +98,7 @@ rec { { src = key; } "${pkgs.stdenv.bash}/bin/bash ${./find-lhs2tex-includes.sh}"); - in pkgs.lib.concatMap (x: if builtins.pathExists x then [{key = x;}] else []) + in pkgs.lib.concatMap (x: lib.optionals (builtins.pathExists x) [{key = x;}]) (map (x: dirOf key + ("/" + x)) deps); }; diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index f9aa50a01d71..cf9bb6e59345 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -41,7 +41,7 @@ makeScopeWithSplicing (generateSplicesForMkScope "darwin") (_: {}) (spliced: spl useAppleSDKLibs = stdenv.hostPlatform.isAarch64; selectAttrs = attrs: names: - lib.listToAttrs (lib.concatMap (n: if attrs ? "${n}" then [(lib.nameValuePair n attrs."${n}")] else []) names); + lib.listToAttrs (lib.concatMap (n: lib.optionals (attrs ? "${n}") [(lib.nameValuePair n attrs."${n}")]) names); chooseLibs = ( # There are differences in which libraries are exported. Avoid evaluation diff --git a/pkgs/top-level/release-haskell.nix b/pkgs/top-level/release-haskell.nix index ee7e64f1ffaa..8c38800b77cb 100644 --- a/pkgs/top-level/release-haskell.nix +++ b/pkgs/top-level/release-haskell.nix @@ -39,9 +39,7 @@ let attrs: if lib.isDerivation attrs then [ attrs ] - else if lib.isAttrs attrs - then accumulateDerivations (lib.attrValues attrs) - else [] + else lib.optionals (lib.isAttrs attrs) (accumulateDerivations (lib.attrValues attrs)) ) jobList; # names of all subsets of `pkgs.haskell.packages` diff --git a/pkgs/top-level/release-python.nix b/pkgs/top-level/release-python.nix index f34185722201..691f50708ace 100644 --- a/pkgs/top-level/release-python.nix +++ b/pkgs/top-level/release-python.nix @@ -24,7 +24,7 @@ let packagePython value else []); - in if res.success then res.value else [] + in lib.optionals res.success res.value ); jobs = {