summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix Buehler <account@buehler.rocks>2023-02-14 19:11:59 +0100
committerFelix Buehler <account@buehler.rocks>2023-02-14 19:11:59 +0100
commitbc3d5934d7f276a21537b40159491257ee163d94 (patch)
tree53b1d9bd9cb148a0ab34f2fd9e1d94802dde639e
parent3bee4ab8db244db328b41ae5f4fbce19b658f1be (diff)
downloadnixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar.gz
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar.bz2
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar.lz
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar.xz
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.tar.zst
nixpkgs-bc3d5934d7f276a21537b40159491257ee163d94.zip
treewide: use lib.optionals
-rw-r--r--pkgs/applications/editors/vscode/extensions/vscodeEnv.nix3
-rw-r--r--pkgs/applications/file-managers/spacefm/default.nix2
-rw-r--r--pkgs/applications/kde/kdevelop/wrapper.nix4
-rw-r--r--pkgs/applications/networking/browsers/chromium/browser.nix4
-rw-r--r--pkgs/applications/networking/browsers/firefox/wrapper.nix4
-rw-r--r--pkgs/applications/radio/gnuradio/shared.nix18
-rw-r--r--pkgs/applications/radio/gnuradio/wrapper.nix7
-rw-r--r--pkgs/build-support/build-setupcfg/default.nix7
-rw-r--r--pkgs/build-support/dotnet/make-nuget-source/default.nix4
-rw-r--r--pkgs/development/interpreters/python/default.nix2
-rw-r--r--pkgs/development/interpreters/python/python-packages-base.nix2
-rw-r--r--pkgs/development/java-modules/m2install.nix2
-rw-r--r--pkgs/development/mobile/androidenv/compose-android-packages.nix6
-rw-r--r--pkgs/development/python-modules/polars/default.nix2
-rw-r--r--pkgs/games/xjump/default.nix8
-rw-r--r--pkgs/stdenv/generic/check-meta.nix2
-rw-r--r--pkgs/stdenv/native/default.nix6
-rw-r--r--pkgs/tools/archivers/zip/default.nix2
-rw-r--r--pkgs/tools/nix/info/default.nix2
-rw-r--r--pkgs/tools/typesetting/tex/nix/default.nix5
-rw-r--r--pkgs/top-level/darwin-packages.nix2
-rw-r--r--pkgs/top-level/release-haskell.nix4
-rw-r--r--pkgs/top-level/release-python.nix2
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 7c58a4bdfb3..818cca51772 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 334228f98ea..605340cbc85 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 86d3de9eb39..c73f2bba7b5 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 2f39e82f3b2..1eea3e8962f 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 06bd49facb8..de68807d8f2 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 ff6aaf35bea..bdbc22cb787 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 926022353e4..c38c89fc459 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 bc6482f0a88..5737989249a 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 8dc77f3aac0..ea1c5328082 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 76dc12005f8..08e2717d41c 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 d5b02223fd6..ee94d4aec03 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 b35880e013c..c058590c857 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 75f393b3f9e..d27c1bb1cdc 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 f265e24fe4e..5424152a1e8 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 3c13fc1a9b7..2c56e0bba4f 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 dd7825a409e..4b0ca649ee9 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 87862b84bc1..bae4ff2c93b 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 ab91cfc6483..82329537251 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 151a53f1525..84bd3e89162 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 fbb6fdb0fe0..e9017333c94 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 f9aa50a01d7..cf9bb6e5934 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 ee7e64f1ffa..8c38800b77c 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 f3418572220..691f50708ac 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 = {