treewide: use lib.optional instead of 'then []'

This commit is contained in:
Felix Buehler 2023-06-10 20:16:12 +02:00 committed by Emery Hemingway
parent b63179691f
commit bec27fabee
13 changed files with 15 additions and 20 deletions

View file

@ -31,7 +31,7 @@ evalConfigArgs@
, prefix ? [] , prefix ? []
, lib ? import ../../lib , lib ? import ../../lib
, extraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH"; , extraModules ? let e = builtins.getEnv "NIXOS_EXTRA_MODULE_PATH";
in if e == "" then [] else [(import e)] in lib.optional (e != "") (import e)
}: }:
let pkgs_ = pkgs; let pkgs_ = pkgs;

View file

@ -39,9 +39,7 @@ with lib;
# !!! Hack - attributes expected by other modules. # !!! Hack - attributes expected by other modules.
environment.systemPackages = [ pkgs.grub2_efi ] environment.systemPackages = [ pkgs.grub2_efi ]
++ (if pkgs.stdenv.hostPlatform.system == "aarch64-linux" ++ (lib.optionals (pkgs.stdenv.hostPlatform.system != "aarch64-linux") [pkgs.grub2 pkgs.syslinux]);
then []
else [ pkgs.grub2 pkgs.syslinux ]);
fileSystems."/" = mkImageMediaOverride fileSystems."/" = mkImageMediaOverride
{ fsType = "tmpfs"; { fsType = "tmpfs";

View file

@ -351,7 +351,7 @@ in {
CacheDirectory = dirs cacheDirs; CacheDirectory = dirs cacheDirs;
RuntimeDirectory = dirName; RuntimeDirectory = dirName;
ReadWriteDirectories = lib.mkIf useCustomDir [ cfg.storageDir ]; ReadWriteDirectories = lib.mkIf useCustomDir [ cfg.storageDir ];
StateDirectory = dirs (if useCustomDir then [] else libDirs); StateDirectory = dirs (lib.optional (!useCustomDir) libDirs);
LogsDirectory = dirName; LogsDirectory = dirName;
PrivateTmp = true; PrivateTmp = true;
ProtectSystem = "strict"; ProtectSystem = "strict";

View file

@ -130,9 +130,9 @@ in {
This defaults to the singleton list [ca] when the {option}`ca` option is defined. This defaults to the singleton list [ca] when the {option}`ca` option is defined.
''; '';
default = if cfg.elasticsearch.ca == null then [] else [ca]; default = lib.optional (cfg.elasticsearch.ca != null) ca;
defaultText = literalExpression '' defaultText = literalExpression ''
if config.${opt.elasticsearch.ca} == null then [ ] else [ ca ] lib.optional (config.${opt.elasticsearch.ca} != null) ca
''; '';
type = types.listOf types.path; type = types.listOf types.path;
}; };

View file

@ -17,7 +17,7 @@ let
# If the new path is a prefix to some existing path, we need to filter it out # If the new path is a prefix to some existing path, we need to filter it out
filteredPaths = lib.filter (p: !lib.hasPrefix (builtins.toString newPath) (builtins.toString p)) merged; filteredPaths = lib.filter (p: !lib.hasPrefix (builtins.toString newPath) (builtins.toString p)) merged;
# If a prefix of the new path is already in the list, do not add it # If a prefix of the new path is already in the list, do not add it
filteredNew = if hasPrefixInList filteredPaths newPath then [] else [ newPath ]; filteredNew = lib.optional (!hasPrefixInList filteredPaths newPath) newPath;
in filteredPaths ++ filteredNew) []; in filteredPaths ++ filteredNew) [];
defaultServiceConfig = { defaultServiceConfig = {

View file

@ -263,8 +263,8 @@ in
serviceConfig.RemainAfterExit = true; serviceConfig.RemainAfterExit = true;
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
requires = if cfg.database.host == null then [] else [ "postgresql.service" ]; requires = lib.optional (cfg.database.host != null) "postgresql.service";
after = [ "network.target" ] ++ (if cfg.database.host == null then [] else [ "postgresql.service" ]); after = [ "network.target" ] ++ (lib.optional (cfg.database.host != null) "postgresql.service");
script = '' script = ''
rm -rf "${runDir}" rm -rf "${runDir}"

View file

@ -63,7 +63,7 @@
matched = builtins.match "[ \t]+(${reHost})(.*)" str; matched = builtins.match "[ \t]+(${reHost})(.*)" str;
continue = lib.singleton (lib.head matched) continue = lib.singleton (lib.head matched)
++ matchAliases (lib.last matched); ++ matchAliases (lib.last matched);
in if matched == null then [] else continue; in lib.optional (matched != null) continue;
matchLine = str: let matchLine = str: let
result = builtins.match "[ \t]*(${reIp})[ \t]+(${reHost})(.*)" str; result = builtins.match "[ \t]*(${reIp})[ \t]+(${reHost})(.*)" str;

View file

@ -45,7 +45,7 @@ in rec {
escs = "\\*?"; escs = "\\*?";
splitString = splitString =
let recurse = str : [(substring 0 1 str)] ++ let recurse = str : [(substring 0 1 str)] ++
(if str == "" then [] else (recurse (substring 1 (stringLength(str)) str) )); (lib.optionals (str != "") (recurse (substring 1 (stringLength(str)) str) ));
in str : recurse str; in str : recurse str;
chars = s: filter (c: c != "" && !isList c) (splitString s); chars = s: filter (c: c != "" && !isList c) (splitString s);
escape = s: map (c: "\\" + c) (chars s); escape = s: map (c: "\\" + c) (chars s);

View file

@ -40,8 +40,7 @@ let
mathcomp_ = package: let mathcomp_ = package: let
classical-deps = [ mathcomp.algebra mathcomp-finmap ]; classical-deps = [ mathcomp.algebra mathcomp-finmap ];
analysis-deps = [ mathcomp.field mathcomp-bigenough ]; analysis-deps = [ mathcomp.field mathcomp-bigenough ];
intra-deps = if package == "single" then [] intra-deps = lib.optionals (package != "single") (map mathcomp_ (head (splitList (lib.pred.equal package) packages)));
else map mathcomp_ (head (splitList (lib.pred.equal package) packages));
pkgpath = if package == "single" then "." pkgpath = if package == "single" then "."
else if package == "analysis" then "theories" else "${package}"; else if package == "analysis" then "theories" else "${package}";
pname = if package == "single" then "mathcomp-analysis-single" pname = if package == "single" then "mathcomp-analysis-single"

View file

@ -55,8 +55,7 @@ let
packages = [ "ssreflect" "fingroup" "algebra" "solvable" "field" "character" "all" ]; packages = [ "ssreflect" "fingroup" "algebra" "solvable" "field" "character" "all" ];
mathcomp_ = package: let mathcomp_ = package: let
mathcomp-deps = if package == "single" then [] mathcomp-deps = lib.optionals (package != "single") (map mathcomp_ (head (splitList (lib.pred.equal package) packages)));
else map mathcomp_ (head (splitList (lib.pred.equal package) packages));
pkgpath = if package == "single" then "mathcomp" else "mathcomp/${package}"; pkgpath = if package == "single" then "mathcomp" else "mathcomp/${package}";
pname = if package == "single" then "mathcomp" else "mathcomp-${package}"; pname = if package == "single" then "mathcomp" else "mathcomp-${package}";
pkgallMake = '' pkgallMake = ''

View file

@ -33,8 +33,7 @@ let
template-coq = metacoq_ "template-coq"; template-coq = metacoq_ "template-coq";
metacoq_ = package: let metacoq_ = package: let
metacoq-deps = if package == "single" then [] metacoq-deps = lib.optionals (package != "single") (map metacoq_ (head (splitList (lib.pred.equal package) packages)));
else map metacoq_ (head (splitList (lib.pred.equal package) packages));
pkgpath = if package == "single" then "./" else "./${package}"; pkgpath = if package == "single" then "./" else "./${package}";
pname = if package == "all" then "metacoq" else "metacoq-${package}"; pname = if package == "all" then "metacoq" else "metacoq-${package}";
pkgallMake = '' pkgallMake = ''

View file

@ -33,7 +33,7 @@ mkProtobufDerivation = buildProtobuf: stdenv: stdenv.mkDerivation {
nativeBuildInputs = [ autoreconfHook buildPackages.which buildPackages.stdenv.cc buildProtobuf ]; nativeBuildInputs = [ autoreconfHook buildPackages.which buildPackages.stdenv.cc buildProtobuf ];
buildInputs = [ zlib ]; buildInputs = [ zlib ];
configureFlags = if buildProtobuf == null then [] else [ "--with-protoc=${buildProtobuf}/bin/protoc" ]; configureFlags = lib.optional (buildProtobuf != null) "--with-protoc=${buildProtobuf}/bin/protoc";
enableParallelBuilding = true; enableParallelBuilding = true;

View file

@ -65,7 +65,7 @@ stdenv.mkDerivation rec {
# to bootstrap tools: # to bootstrap tools:
# https://github.com/NixOS/nixpkgs/pull/175719 # https://github.com/NixOS/nixpkgs/pull/175719
# We pick zlib.dev as a simple canary package with pkg-config input. # We pick zlib.dev as a simple canary package with pkg-config input.
disallowedReferences = if withDebug then [] else [ zlib.dev ]; disallowedReferences = lib.optional (!withDebug) zlib.dev;
donStrip = withDebug; donStrip = withDebug;
env.NIX_CFLAGS_COMPILE = lib.optionalString withDebug "-O1 -ggdb -DNETDATA_INTERNAL_CHECKS=1"; env.NIX_CFLAGS_COMPILE = lib.optionalString withDebug "-O1 -ggdb -DNETDATA_INTERNAL_CHECKS=1";