treewide: use optionalString instead of 'then ""'

This commit is contained in:
Felix Buehler 2023-06-24 20:19:19 +02:00
parent e9e3f2e736
commit f3719756b5
53 changed files with 101 additions and 116 deletions

View file

@ -33,7 +33,7 @@ let
} }
trap on_exit EXIT trap on_exit EXIT
archiveName="${if cfg.archiveBaseName == null then "" else cfg.archiveBaseName + "-"}$(date ${cfg.dateFormat})" archiveName="${optionalString (cfg.archiveBaseName != null) (cfg.archiveBaseName + "-")}$(date ${cfg.dateFormat})"
archiveSuffix="${optionalString cfg.appendFailedSuffix ".failed"}" archiveSuffix="${optionalString cfg.appendFailedSuffix ".failed"}"
${cfg.preHook} ${cfg.preHook}
'' + optionalString cfg.doInit '' '' + optionalString cfg.doInit ''

View file

@ -210,9 +210,7 @@ in {
preStart = preStart =
let replacePlugins = let replacePlugins =
if cfg.plugins == null optionalString (cfg.plugins != null) (
then ""
else
let pluginCmds = lib.attrsets.mapAttrsToList let pluginCmds = lib.attrsets.mapAttrsToList
(n: v: "cp ${v} ${cfg.home}/plugins/${n}.jpi") (n: v: "cp ${v} ${cfg.home}/plugins/${n}.jpi")
cfg.plugins; cfg.plugins;
@ -220,7 +218,7 @@ in {
rm -r ${cfg.home}/plugins || true rm -r ${cfg.home}/plugins || true
mkdir -p ${cfg.home}/plugins mkdir -p ${cfg.home}/plugins
${lib.strings.concatStringsSep "\n" pluginCmds} ${lib.strings.concatStringsSep "\n" pluginCmds}
''; '');
in '' in ''
rm -rf ${cfg.home}/war rm -rf ${cfg.home}/war
${replacePlugins} ${replacePlugins}

View file

@ -11,7 +11,7 @@ let
mapAttrsToList (n: v: ''"${n}": "${(concatStringsSep "," (map convType v))}"'') mapAttrsToList (n: v: ''"${n}": "${(concatStringsSep "," (map convType v))}"'')
(foldAttrs (n: a: [n] ++ a) [] cfg.hardware); (foldAttrs (n: a: [n] ++ a) [] cfg.hardware);
mergedConfig = with builtins; mergedConfig = with builtins;
mapAttrsToList (n: v: ''"${n}": ${if isBool v then "" else ''"''}${convType v}${if isBool v then "" else ''"''}'') mapAttrsToList (n: v: ''"${n}": ${if isBool v then (convType v) else ''"${convType v}"''}'')
cfg.config; cfg.config;
cgminerConfig = pkgs.writeText "cgminer.conf" '' cgminerConfig = pkgs.writeText "cgminer.conf" ''

View file

@ -8,13 +8,13 @@ let
settingsFormat = pkgs.formats.ini { settingsFormat = pkgs.formats.ini {
listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {}); listToValue = concatMapStringsSep "," (generators.mkValueStringDefault {});
mkKeyValue = k: v: mkKeyValue = k: v:
if v == null then "" optionalString (v != null)
else generators.mkKeyValueDefault { (generators.mkKeyValueDefault {
mkValueString = v: mkValueString = v:
if v == true then "yes" if v == true then "yes"
else if v == false then "no" else if v == false then "no"
else generators.mkValueStringDefault {} v; else generators.mkValueStringDefault {} v;
} "=" k v; } "=" k v);
}; };
configIniOfService = srv: settingsFormat.generate "sourcehut-${srv}-config.ini" configIniOfService = srv: settingsFormat.generate "sourcehut-${srv}-config.ini"
# Each service needs access to only a subset of sections (and secrets). # Each service needs access to only a subset of sections (and secrets).

View file

@ -104,12 +104,12 @@ in
LoadCredential = "configFile:${computedConfigFile}"; LoadCredential = "configFile:${computedConfigFile}";
ExecStart = '' ExecStart = ''
${cfg.package}/bin/pve_exporter \ ${cfg.package}/bin/pve_exporter \
--${if cfg.collectors.status == true then "" else "no-"}collector.status \ --${optionalString (!cfg.collectors.status) "no-"}collector.status \
--${if cfg.collectors.version == true then "" else "no-"}collector.version \ --${optionalString (!cfg.collectors.version) "no-"}collector.version \
--${if cfg.collectors.node == true then "" else "no-"}collector.node \ --${optionalString (!cfg.collectors.node) "no-"}collector.node \
--${if cfg.collectors.cluster == true then "" else "no-"}collector.cluster \ --${optionalString (!cfg.collectors.cluster) "no-"}collector.cluster \
--${if cfg.collectors.resources == true then "" else "no-"}collector.resources \ --${optionalString (!cfg.collectors.resources) "no-"}collector.resources \
--${if cfg.collectors.config == true then "" else "no-"}collector.config \ --${optionalString (!cfg.collectors.config) "no-"}collector.config \
%d/configFile \ %d/configFile \
${toString cfg.port} ${cfg.listenAddress} ${toString cfg.port} ${cfg.listenAddress}
''; '';

View file

@ -8,8 +8,7 @@ let
settingsFile = pkgs.writeText "biboumi.cfg" ( settingsFile = pkgs.writeText "biboumi.cfg" (
generators.toKeyValue { generators.toKeyValue {
mkKeyValue = k: v: mkKeyValue = k: v:
if v == null then "" lib.optionalString (v != null) (generators.mkKeyValueDefault {} "=" k v);
else generators.mkKeyValueDefault {} "=" k v;
} cfg.settings); } cfg.settings);
need_CAP_NET_BIND_SERVICE = cfg.settings.identd_port != 0 && cfg.settings.identd_port < 1024; need_CAP_NET_BIND_SERVICE = cfg.settings.identd_port != 0 && cfg.settings.identd_port < 1024;
in in

View file

@ -239,7 +239,7 @@ in
after = [ "network-online.target" ]; after = [ "network-online.target" ];
bindsTo = [ "network-online.target" ]; bindsTo = [ "network-online.target" ];
preStart = if cfg.confFile != null then "" else '' preStart = optionalString (cfg.confFile == null) ''
[ -e /etc/cjdns.keys ] && source /etc/cjdns.keys [ -e /etc/cjdns.keys ] && source /etc/cjdns.keys
if [ -z "$CJDNS_PRIVATE_KEY" ]; then if [ -z "$CJDNS_PRIVATE_KEY" ]; then

View file

@ -14,8 +14,8 @@ let
nonchars = filter (x : !(elem x.value chars)) nonchars = filter (x : !(elem x.value chars))
(imap0 (i: v: {ind = i; value = v;}) (stringToCharacters str)); (imap0 (i: v: {ind = i; value = v;}) (stringToCharacters str));
in in
if length nonchars == 0 then "" lib.optionalString (length nonchars != 0)
else substring (head nonchars).ind (add 1 (sub (last nonchars).ind (head nonchars).ind)) str; (substring (head nonchars).ind (add 1 (sub (last nonchars).ind (head nonchars).ind)) str);
indent = str: concatStrings (concatMap (s: [" " (trim [" " "\t"] s) "\n"]) (splitString "\n" str)); indent = str: concatStrings (concatMap (s: [" " (trim [" " "\t"] s) "\n"]) (splitString "\n" str));
configText = indent (toString cfg.configSetup); configText = indent (toString cfg.configSetup);
connectionText = concatStrings (mapAttrsToList (n: v: connectionText = concatStrings (mapAttrsToList (n: v:

View file

@ -19,8 +19,8 @@ let
welcometext="${cfg.welcometext}" welcometext="${cfg.welcometext}"
port=${toString cfg.port} port=${toString cfg.port}
${if cfg.hostName == "" then "" else "host="+cfg.hostName} ${optionalString (cfg.hostName != "") "host=${cfg.hostName}"}
${if cfg.password == "" then "" else "serverpassword="+cfg.password} ${optionalString (cfg.password != "") "serverpassword=${cfg.password}"}
bandwidth=${toString cfg.bandwidth} bandwidth=${toString cfg.bandwidth}
users=${toString cfg.users} users=${toString cfg.users}
@ -32,17 +32,17 @@ let
bonjour=${boolToString cfg.bonjour} bonjour=${boolToString cfg.bonjour}
sendversion=${boolToString cfg.sendVersion} sendversion=${boolToString cfg.sendVersion}
${if cfg.registerName == "" then "" else "registerName="+cfg.registerName} ${optionalString (cfg.registerName != "") "registerName=${cfg.registerName}"}
${if cfg.registerPassword == "" then "" else "registerPassword="+cfg.registerPassword} ${optionalString (cfg.registerPassword == "") "registerPassword=${cfg.registerPassword}"}
${if cfg.registerUrl == "" then "" else "registerUrl="+cfg.registerUrl} ${optionalString (cfg.registerUrl != "") "registerUrl=${cfg.registerUrl}"}
${if cfg.registerHostname == "" then "" else "registerHostname="+cfg.registerHostname} ${optionalString (cfg.registerHostname != "") "registerHostname=${cfg.registerHostname}"}
certrequired=${boolToString cfg.clientCertRequired} certrequired=${boolToString cfg.clientCertRequired}
${if cfg.sslCert == "" then "" else "sslCert="+cfg.sslCert} ${optionalString (cfg.sslCert != "") "sslCert=${cfg.sslCert}"}
${if cfg.sslKey == "" then "" else "sslKey="+cfg.sslKey} ${optionalString (cfg.sslKey != "") "sslKey=${cfg.sslKey}"}
${if cfg.sslCa == "" then "" else "sslCA="+cfg.sslCa} ${optionalString (cfg.sslCa != "") "sslCA=${cfg.sslCa}"}
${lib.optionalString (cfg.dbus != null) "dbus=${cfg.dbus}"} ${optionalString (cfg.dbus != null) "dbus=${cfg.dbus}"}
${cfg.extraConfig} ${cfg.extraConfig}
''; '';

View file

@ -137,8 +137,8 @@ let
''; '';
yesOrNo = b: if b then "yes" else "no"; yesOrNo = b: if b then "yes" else "no";
maybeString = prefix: x: if x == null then "" else ''${prefix} "${x}"''; maybeString = prefix: x: optionalString (x != null) ''${prefix} "${x}"'';
maybeToString = prefix: x: if x == null then "" else ''${prefix} ${toString x}''; maybeToString = prefix: x: optionalString (x != null) ''${prefix} ${toString x}'';
forEach = pre: l: concatMapStrings (x: pre + x + "\n") l; forEach = pre: l: concatMapStrings (x: pre + x + "\n") l;

View file

@ -165,9 +165,7 @@ in
${lsh}/sbin/lshd --daemonic \ ${lsh}/sbin/lshd --daemonic \
--password-helper="${lsh}/sbin/lsh-pam-checkpw" \ --password-helper="${lsh}/sbin/lsh-pam-checkpw" \
-p ${toString portNumber} \ -p ${toString portNumber} \
${if interfaces == [] then "" ${optionalString (interfaces != []) (concatStrings (map (i: "--interface=\"${i}\"") interfaces))} \
else (concatStrings (map (i: "--interface=\"${i}\"")
interfaces))} \
-h "${hostKey}" \ -h "${hostKey}" \
${optionalString (!syslog) "--no-syslog" } \ ${optionalString (!syslog) "--no-syslog" } \
${if passwordAuthentication then "--password" else "--no-password" } \ ${if passwordAuthentication then "--password" else "--no-password" } \

View file

@ -6,7 +6,7 @@ let
cfg = config.services.fcron; cfg = config.services.fcron;
queuelen = if cfg.queuelen == null then "" else "-q ${toString cfg.queuelen}"; queuelen = optionalString (cfg.queuelen != null) "-q ${toString cfg.queuelen}";
# Duplicate code, also found in cron.nix. Needs deduplication. # Duplicate code, also found in cron.nix. Needs deduplication.
systemCronJobs = systemCronJobs =

View file

@ -62,7 +62,7 @@ let
port = cfg.database.port; port = cfg.database.port;
# Blank for unix sockets, see # Blank for unix sockets, see
# https://github.com/will/crystal-pg/blob/1548bb255210/src/pq/conninfo.cr#L100-L108 # https://github.com/will/crystal-pg/blob/1548bb255210/src/pq/conninfo.cr#L100-L108
host = if cfg.database.host == null then "" else cfg.database.host; host = lib.optionalString (cfg.database.host != null) cfg.database.host;
# Not needed because peer authentication is enabled # Not needed because peer authentication is enabled
password = lib.mkIf (cfg.database.host == null) ""; password = lib.mkIf (cfg.database.host == null) "";
}; };

View file

@ -16,7 +16,7 @@ let
DB_HOSTNAME=${cfg.database.host} DB_HOSTNAME=${cfg.database.host}
DB_USERNAME=${cfg.database.user} DB_USERNAME=${cfg.database.user}
# NOTE: file_get_contents adds newline at the end of returned string # NOTE: file_get_contents adds newline at the end of returned string
DB_PASSWORD=${if cfg.database.passwordFile == null then "" else "trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")"} DB_PASSWORD=${optionalString (cfg.database.passwordFile != null) "trim(file_get_contents('${cfg.database.passwordFile}'), \"\\r\\n\")"}
DB_DATABASE=${cfg.database.name} DB_DATABASE=${cfg.database.name}
DB_PORT=${toString cfg.database.port} DB_PORT=${toString cfg.database.port}
SESS_EXPIRATION=864000 SESS_EXPIRATION=864000

View file

@ -350,7 +350,7 @@ in {
}; };
redis = { redis = {
hostname = "${toString cfg.redis.host}"; hostname = "${toString cfg.redis.host}";
port = (if cfg.redis.port == null then "" else cfg.redis.port); port = (lib.optionalString (cfg.redis.port != null) cfg.redis.port);
}; };
storage = { storage = {
tmp = lib.mkDefault "/var/lib/peertube/storage/tmp/"; tmp = lib.mkDefault "/var/lib/peertube/storage/tmp/";

View file

@ -4,7 +4,7 @@ with lib;
let let
cfg = config.services.lighttpd.cgit; cfg = config.services.lighttpd.cgit;
pathPrefix = if stringLength cfg.subdir == 0 then "" else "/" + cfg.subdir; pathPrefix = optionalString (stringLength cfg.subdir != 0) ("/" + cfg.subdir);
configFile = pkgs.writeText "cgitrc" configFile = pkgs.writeText "cgitrc"
'' ''
# default paths to static assets # default paths to static assets

View file

@ -100,7 +100,7 @@ let
}; };
}; };
optionalKV = k: v: if v == null then "" else "${k} = ${builtins.toString v}"; optionalKV = k: v: optionalString (v != null) "${k} = ${builtins.toString v}";
renderPhocOutput = name: output: let renderPhocOutput = name: output: let
modelines = if builtins.isList output.modeline modelines = if builtins.isList output.modeline

View file

@ -70,11 +70,10 @@ let
let let
val = if item.freeform != null then item.freeform else item.tristate; val = if item.freeform != null then item.freeform else item.tristate;
in in
if val == null optionalString (val != null)
then "" (if (item.optional)
else if (item.optional)
then "${key}? ${mkValue val}\n" then "${key}? ${mkValue val}\n"
else "${key} ${mkValue val}\n"; else "${key} ${mkValue val}\n");
mkConf = cfg: concatStrings (mapAttrsToList mkConfigLine cfg); mkConf = cfg: concatStrings (mapAttrsToList mkConfigLine cfg);
in mkConf exprs; in mkConf exprs;

View file

@ -65,8 +65,8 @@ let
[ coreutils gnused gnugrep findutils diffutils btrfs-progs util-linux mdadm ] [ coreutils gnused gnugrep findutils diffutils btrfs-progs util-linux mdadm ]
++ optional cfg.efiSupport efibootmgr ++ optional cfg.efiSupport efibootmgr
++ optionals cfg.useOSProber [ busybox os-prober ]); ++ optionals cfg.useOSProber [ busybox os-prober ]);
font = if cfg.font == null then "" font = lib.optionalString (cfg.font != null) (
else (if lib.last (lib.splitString "." cfg.font) == "pf2" if lib.last (lib.splitString "." cfg.font) == "pf2"
then cfg.font then cfg.font
else "${convertedFont}"); else "${convertedFont}");
}); });

View file

@ -42,7 +42,7 @@ let
writeTmpfiles = { rules, user ? null }: writeTmpfiles = { rules, user ? null }:
let let
suffix = if user == null then "" else "-${user}"; suffix = optionalString (user != null) "-${user}";
in in
pkgs.writeTextFile { pkgs.writeTextFile {
name = "nixos-user-tmpfiles.d${suffix}"; name = "nixos-user-tmpfiles.d${suffix}";

View file

@ -47,10 +47,10 @@ stdenv.mkDerivation {
postInstall = "wrapProgram $out/Applications/TeXmacs-${version}/Contents/MacOS/TeXmacs --suffix PATH : " + postInstall = "wrapProgram $out/Applications/TeXmacs-${version}/Contents/MacOS/TeXmacs --suffix PATH : " +
"${ghostscript}/bin:" + "${ghostscript}/bin:" +
(if aspell == null then "" else "${aspell}/bin:") + (lib.optionalString (aspell != null) "${aspell}/bin:") +
(if tex == null then "" else "${tex}/bin:") + (lib.optionalString (tex != null) "${tex}/bin:") +
(if netpbm == null then "" else "${lib.getBin netpbm}/bin:") + (lib.optionalString (netpbm != null) "${lib.getBin netpbm}/bin:") +
(if imagemagick == null then "" else "${imagemagick}/bin:"); (lib.optionalString (imagemagick != null) "${imagemagick}/bin:");
enableParallelBuilding = true; enableParallelBuilding = true;

View file

@ -22,7 +22,7 @@ let
armv7l-linux = "0m1v24gg2dy79hgrz37gysgrazg8vkr1gkp52j6m6y76vi0l8249"; armv7l-linux = "0m1v24gg2dy79hgrz37gysgrazg8vkr1gkp52j6m6y76vi0l8249";
}.${system} or throwSystem; }.${system} or throwSystem;
sourceRoot = if stdenv.isDarwin then "" else "."; sourceRoot = lib.optionalString (!stdenv.isDarwin) ".";
in in
callPackage ./generic.nix rec { callPackage ./generic.nix rec {
inherit sourceRoot commandLineArgs useVSCodeRipgrep; inherit sourceRoot commandLineArgs useVSCodeRipgrep;

View file

@ -134,9 +134,7 @@ let
}; };
}; };
suffix = if (channel == "stable" || channel == "ungoogled-chromium") suffix = lib.optionalString (channel != "stable" && channel != "ungoogled-chromium") ("-" + channel);
then ""
else "-" + channel;
sandboxExecutableName = chromium.browser.passthru.sandboxExecutableName; sandboxExecutableName = chromium.browser.passthru.sandboxExecutableName;

View file

@ -46,13 +46,9 @@ let
then baseName then baseName
else baseName + "-" + channel; else baseName + "-" + channel;
iconSuffix = if channel == "stable" iconSuffix = lib.optionalString (channel != "stable") "_${channel}";
then ""
else "_${channel}";
desktopSuffix = if channel == "stable" desktopSuffix = lib.optionalString (channel != "stable") "-${channel}";
then ""
else "-${channel}";
in in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {

View file

@ -395,7 +395,7 @@ in
dontWrapQtApps = true; dontWrapQtApps = true;
configureFlags = [ configureFlags = [
(if withHelp then "" else "--without-help") (lib.optionalString (!withHelp) "--without-help")
"--with-boost=${getDev boost}" "--with-boost=${getDev boost}"
"--with-boost-libdir=${getLib boost}/lib" "--with-boost-libdir=${getLib boost}/lib"
"--with-beanshell-jar=${bsh}" "--with-beanshell-jar=${bsh}"

View file

@ -2,8 +2,7 @@
let let
load_num = load_num =
if num == null then "" else lib.optionalString (num != null) ''
''
-I ${num}/lib/ocaml/${ocaml.version}/site-lib/num \ -I ${num}/lib/ocaml/${ocaml.version}/site-lib/num \
-I ${num}/lib/ocaml/${ocaml.version}/site-lib/top-num \ -I ${num}/lib/ocaml/${ocaml.version}/site-lib/top-num \
-I ${num}/lib/ocaml/${ocaml.version}/site-lib/stublibs \ -I ${num}/lib/ocaml/${ocaml.version}/site-lib/stublibs \

View file

@ -19,7 +19,7 @@ let
runAllTests = files == null; runAllTests = files == null;
testArgs = if runAllTests then "--all" else testFileList; testArgs = if runAllTests then "--all" else testFileList;
patienceSpecifier = lib.optionalString longTests "--long"; patienceSpecifier = lib.optionalString longTests "--long";
timeSpecifier = if timeLimit == null then "" else "--short ${toString timeLimit}"; timeSpecifier = lib.optionalString (timeLimit != null) "--short ${toString timeLimit}";
relpathToArg = relpath: lib.escapeShellArg "${src}/${relpath}"; # paths need to be absolute relpathToArg = relpath: lib.escapeShellArg "${src}/${relpath}"; # paths need to be absolute
testFileList = lib.concatStringsSep " " (map relpathToArg files); testFileList = lib.concatStringsSep " " (map relpathToArg files);
in in

View file

@ -38,7 +38,7 @@ let
# #
# See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295 # See https://github.com/NixOS/nixpkgs/pull/198311#issuecomment-1326894295
myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: { myCargoSetupHook = rustPlatform.cargoSetupHook.overrideAttrs (old: {
cargoConfig = if stdenv.isDarwin then "" else old.cargoConfig; cargoConfig = lib.optionalString (!stdenv.isDarwin) old.cargoConfig;
}); });
src = fetchFromGitHub { src = fetchFromGitHub {

View file

@ -28,7 +28,7 @@ let
export DBUS_SESSION_BUS_ADDRESS export DBUS_SESSION_BUS_ADDRESS
exec ${sway}/bin/sway "$@" exec ${sway}/bin/sway "$@"
else else
exec ${if !dbusSupport then "" else "${dbus}/bin/dbus-run-session"} ${sway}/bin/sway "$@" exec ${lib.optionalString dbusSupport "${dbus}/bin/dbus-run-session"} ${sway}/bin/sway "$@"
fi fi
''; '';
in symlinkJoin { in symlinkJoin {

View file

@ -59,12 +59,12 @@ let
bintoolsVersion = lib.getVersion bintools; bintoolsVersion = lib.getVersion bintools;
bintoolsName = lib.removePrefix targetPrefix (lib.getName bintools); bintoolsName = lib.removePrefix targetPrefix (lib.getName bintools);
libc_bin = if libc == null then "" else getBin libc; libc_bin = lib.optionalString (libc != null) (getBin libc);
libc_dev = if libc == null then "" else getDev libc; libc_dev = lib.optionalString (libc != null) (getDev libc);
libc_lib = if libc == null then "" else getLib libc; libc_lib = lib.optionalString (libc != null) (getLib libc);
bintools_bin = if nativeTools then "" else getBin bintools; bintools_bin = lib.optionalString (!nativeTools) (getBin bintools);
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils. # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
coreutils_bin = if nativeTools then "" else getBin coreutils; coreutils_bin = lib.optionalString (!nativeTools) (getBin coreutils);
# See description in cc-wrapper. # See description in cc-wrapper.
suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config; suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
@ -103,7 +103,7 @@ in
stdenv.mkDerivation { stdenv.mkDerivation {
pname = targetPrefix pname = targetPrefix
+ (if name != "" then name else "${bintoolsName}-wrapper"); + (if name != "" then name else "${bintoolsName}-wrapper");
version = if bintools == null then "" else bintoolsVersion; version = lib.optionalString (bintools != null) bintoolsVersion;
preferLocalBuild = true; preferLocalBuild = true;
@ -265,7 +265,7 @@ stdenv.mkDerivation {
# install the wrapper, you get tools like objdump (same for any # install the wrapper, you get tools like objdump (same for any
# binaries of libc). # binaries of libc).
+ optionalString (!nativeTools) '' + optionalString (!nativeTools) ''
printWords ${bintools_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages printWords ${bintools_bin} ${lib.optionalString (libc != null) libc_bin} > $out/nix-support/propagated-user-env-packages
'' ''
## ##
@ -381,7 +381,7 @@ stdenv.mkDerivation {
# for substitution in utils.bash # for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params"; expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or ""; shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep; gnugrep_bin = lib.optionalString (!nativeTools) gnugrep;
wrapperName = "BINTOOLS_WRAPPER"; wrapperName = "BINTOOLS_WRAPPER";
inherit dynamicLinker targetPrefix suffixSalt coreutils_bin; inherit dynamicLinker targetPrefix suffixSalt coreutils_bin;
inherit bintools_bin libc_bin libc_dev libc_lib; inherit bintools_bin libc_bin libc_dev libc_lib;

View file

@ -75,14 +75,14 @@ let
ccVersion = lib.getVersion cc; ccVersion = lib.getVersion cc;
ccName = lib.removePrefix targetPrefix (lib.getName cc); ccName = lib.removePrefix targetPrefix (lib.getName cc);
libc_bin = if libc == null then "" else getBin libc; libc_bin = optionalString (libc != null) (getBin libc);
libc_dev = if libc == null then "" else getDev libc; libc_dev = optionalString (libc != null) (getDev libc);
libc_lib = if libc == null then "" else getLib libc; libc_lib = optionalString (libc != null) (getLib libc);
cc_solib = getLib cc cc_solib = getLib cc
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"; + optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils. # The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
coreutils_bin = if nativeTools then "" else getBin coreutils; coreutils_bin = optionalString (!nativeTools) (getBin coreutils);
# The "suffix salt" is a arbitrary string added in the end of env vars # The "suffix salt" is a arbitrary string added in the end of env vars
# defined by cc-wrapper's hooks so that multiple cc-wrappers can be used # defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
@ -164,7 +164,7 @@ assert nativePrefix == bintools.nativePrefix;
stdenv.mkDerivation { stdenv.mkDerivation {
pname = targetPrefix pname = targetPrefix
+ (if name != "" then name else "${ccName}-wrapper"); + (if name != "" then name else "${ccName}-wrapper");
version = if cc == null then "" else ccVersion; version = optionalString (cc != null) ccVersion;
preferLocalBuild = true; preferLocalBuild = true;
@ -600,10 +600,10 @@ stdenv.mkDerivation {
# for substitution in utils.bash # for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params"; expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or ""; shell = getBin shell + shell.shellPath or "";
gnugrep_bin = if nativeTools then "" else gnugrep; gnugrep_bin = optionalString (!nativeTools) gnugrep;
# stdenv.cc.cc should not be null and we have nothing better for now. # stdenv.cc.cc should not be null and we have nothing better for now.
# if the native impure bootstrap is gotten rid of this can become `inherit cc;` again. # if the native impure bootstrap is gotten rid of this can become `inherit cc;` again.
cc = if nativeTools then "" else cc; cc = optionalString (!nativeTools) cc;
wrapperName = "CC_WRAPPER"; wrapperName = "CC_WRAPPER";
inherit suffixSalt coreutils_bin bintools; inherit suffixSalt coreutils_bin bintools;
inherit libc_bin libc_dev libc_lib; inherit libc_bin libc_dev libc_lib;

View file

@ -594,7 +594,7 @@ rec {
nativeBuildInputs = [ jshon pigz jq moreutils ]; nativeBuildInputs = [ jshon pigz jq moreutils ];
# Image name must be lowercase # Image name must be lowercase
imageName = lib.toLower name; imageName = lib.toLower name;
imageTag = if tag == null then "" else tag; imageTag = lib.optionalString (tag != null) tag;
inherit fromImage baseJson; inherit fromImage baseJson;
layerClosure = writeReferencesToFile layer; layerClosure = writeReferencesToFile layer;
passthru.buildArgs = args; passthru.buildArgs = args;

View file

@ -24,7 +24,7 @@ let
position = "${position.file}:${toString position.line}"; position = "${position.file}:${toString position.line}";
}; };
passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "forceFetchGit" "private" "githubBase" "varPrefix" ]; passthruAttrs = removeAttrs args [ "owner" "repo" "rev" "fetchSubmodules" "forceFetchGit" "private" "githubBase" "varPrefix" ];
varBase = "NIX${if varPrefix == null then "" else "_${varPrefix}"}_GITHUB_PRIVATE_"; varBase = "NIX${lib.optionalString (varPrefix != null) "_${varPrefix}"}_GITHUB_PRIVATE_";
useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone || forceFetchGit || (sparseCheckout != []); useFetchGit = fetchSubmodules || (leaveDotGit == true) || deepClone || forceFetchGit || (sparseCheckout != []);
# We prefer fetchzip in cases we don't need submodules as the hash # We prefer fetchzip in cases we don't need submodules as the hash
# is more stable in that case. # is more stable in that case.

View file

@ -72,7 +72,7 @@ in
${if makeUInitrd then "uInitrdCompression" else null} = uInitrdCompression; ${if makeUInitrd then "uInitrdCompression" else null} = uInitrdCompression;
passAsFile = ["contents"]; passAsFile = ["contents"];
contents = lib.concatMapStringsSep "\n" ({ object, symlink, ... }: "${object}\n${if symlink == null then "" else symlink}") contents + "\n"; contents = lib.concatMapStringsSep "\n" ({ object, symlink, ... }: "${object}\n${lib.optionalString (symlink != null) symlink}") contents + "\n";
nativeBuildInputs = [makeInitrdNGTool cpio] ++ lib.optional makeUInitrd ubootTools ++ lib.optional strip binutils; nativeBuildInputs = [makeInitrdNGTool cpio] ++ lib.optional makeUInitrd ubootTools ++ lib.optional strip binutils;

View file

@ -66,7 +66,7 @@ in rec {
handleSlashPrefix = l: handleSlashPrefix = l:
let let
split = (match "^(/?)(.*)" l); split = (match "^(/?)(.*)" l);
findSlash = l: if (match ".+/.+" l) != null then "" else l; findSlash = l: lib.optionalString ((match ".+/.+" l) == null) l;
hasSlash = mapAroundCharclass findSlash l != l; hasSlash = mapAroundCharclass findSlash l != l;
in in
(if (elemAt split 0) == "/" || hasSlash (if (elemAt split 0) == "/" || hasSlash

View file

@ -21,7 +21,7 @@
, verbose , verbose
, workspace_member }: , workspace_member }:
let version_ = lib.splitString "-" crateVersion; let version_ = lib.splitString "-" crateVersion;
versionPre = if lib.tail version_ == [] then "" else lib.elemAt version_ 1; versionPre = lib.optionalString (lib.tail version_ != []) (lib.elemAt version_ 1);
version = lib.splitVersion (lib.head version_); version = lib.splitVersion (lib.head version_);
rustcOpts = lib.foldl' (opts: opt: opts + " " + opt) rustcOpts = lib.foldl' (opts: opt: opts + " " + opt)
(if release then "-C opt-level=3" else "-C debuginfo=2") (if release then "-C opt-level=3" else "-C debuginfo=2")

View file

@ -468,7 +468,7 @@ rec {
echo "installing RPMs..." echo "installing RPMs..."
PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \ PATH=/usr/bin:/bin:/usr/sbin:/sbin $chroot /mnt \
rpm -iv --nosignature ${if runScripts then "" else "--noscripts"} $rpms rpm -iv --nosignature ${lib.optionalString (!runScripts) "--noscripts"} $rpms
echo "running post-install script..." echo "running post-install script..."
eval "$postInstall" eval "$postInstall"

View file

@ -3,7 +3,7 @@
let let
common = { pname, sha256, suffix ? "" }: let common = { pname, sha256, suffix ? "" }: let
legacySuffix = if suffix == "-nons" then "" else "-ns"; legacySuffix = lib.optionalString (suffix != "-nons") "-ns";
self = stdenv.mkDerivation rec { self = stdenv.mkDerivation rec {
inherit pname; inherit pname;
version = "1.79.2"; version = "1.79.2";

View file

@ -7,10 +7,7 @@ let
dynamic-linker = stdenv.cc.bintools.dynamicLinker; dynamic-linker = stdenv.cc.bintools.dynamicLinker;
patchelf = libPath : patchelf = libPath :
if stdenv.isDarwin lib.optionalString (!stdenv.isDarwin) ''
then ""
else
''
chmod u+w $PURS chmod u+w $PURS
patchelf --interpreter ${dynamic-linker} --set-rpath ${libPath} $PURS patchelf --interpreter ${dynamic-linker} --set-rpath ${libPath} $PURS
chmod u-w $PURS chmod u-w $PURS

View file

@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
postBuild = '' postBuild = ''
$CXX -shared -o ${libname} \ $CXX -shared -o ${libname} \
${if stdenv.cc.isClang then "" else "-Wl,-soname,${libname}"} \ ${lib.optionalString (!stdenv.cc.isClang) "-Wl,-soname,${libname}"} \
ipasirglucoseglue.o libipasirglucose4.a ipasirglucoseglue.o libipasirglucose4.a
''; '';

View file

@ -118,7 +118,7 @@ let
optionalLocation = let optionalLocation = let
pos = builtins.unsafeGetAttrPos (if attrs ? "pname" then "pname" else "name") attrs; pos = builtins.unsafeGetAttrPos (if attrs ? "pname" then "pname" else "name") attrs;
in if pos == null then "" else " at ${pos.file}:${toString pos.line}:${toString pos.column}"; in lib.optionalString (pos != null) " at ${pos.file}:${toString pos.line}:${toString pos.column}";
leftPadName = name: against: let leftPadName = name: against: let
len = lib.max (lib.stringLength name) (lib.stringLength against); len = lib.max (lib.stringLength name) (lib.stringLength against);

View file

@ -42,7 +42,7 @@ let
if [ -f "$prg" ]; then if [ -f "$prg" ]; then
rm -f "$out/bin/$prg" rm -f "$out/bin/$prg"
if [ -x "$prg" ]; then if [ -x "$prg" ]; then
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${lib.concatStringsSep " " makeWrapperArgs} makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${lib.optionalString (!permitUserSite) ''--set PYTHONNOUSERSITE "true"''} ${lib.concatStringsSep " " makeWrapperArgs}
fi fi
fi fi
done done

View file

@ -330,7 +330,7 @@ assert buildPostproc -> buildAvutil;
assert buildSwscale -> buildAvutil; assert buildSwscale -> buildAvutil;
stdenv.mkDerivation (finalAttrs: { stdenv.mkDerivation (finalAttrs: {
pname = "ffmpeg" + (if ffmpegVariant == "small" then "" else "-${ffmpegVariant}"); pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}");
inherit version; inherit version;
src = fetchgit { src = fetchgit {

View file

@ -39,7 +39,7 @@ let
"stitching" "stitching"
"video" "video"
] ++ lib.optionals (!stdenv.isAarch64 && enableGStreamer) [ "gapi" ]; ] ++ lib.optionals (!stdenv.isAarch64 && enableGStreamer) [ "gapi" ];
testRunner = if stdenv.isDarwin then "" else "${lib.getExe xvfb-run} -a "; testRunner = lib.optionalString (!stdenv.isDarwin) "${lib.getExe xvfb-run} -a ";
testsPreparation = '' testsPreparation = ''
touch $out touch $out
# several tests want a write access, so we have to copy files # several tests want a write access, so we have to copy files

View file

@ -173,9 +173,9 @@ stdenv.mkDerivation rec {
"-make" "libs" "-make" "tools" "-make" "translations" "-make" "libs" "-make" "tools" "-make" "translations"
"-no-phonon" "-no-webkit" "-no-multimedia" "-audio-backend" "-no-phonon" "-no-webkit" "-no-multimedia" "-audio-backend"
]) ++ [ ]) ++ [
"-${if demos then "" else "no"}make" "demos" "-${lib.optionalString (!demos) "no"}make" "demos"
"-${if examples then "" else "no"}make" "examples" "-${lib.optionalString (!examples) "no"}make" "examples"
"-${if docs then "" else "no"}make" "docs" "-${lib.optionalString (!docs) "no"}make" "docs"
] ++ lib.optional developerBuild "-developer-build" ] ++ lib.optional developerBuild "-developer-build"
++ lib.optionals stdenv.hostPlatform.isDarwin [ platformFlag "unsupported/macx-clang-libc++" ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ platformFlag "unsupported/macx-clang-libc++" ]
++ lib.optionals stdenv.hostPlatform.isWindows [ platformFlag "win32-g++-4.6" ]; ++ lib.optionals stdenv.hostPlatform.isWindows [ platformFlag "win32-g++-4.6" ];

View file

@ -158,8 +158,7 @@ stdenv.mkDerivation ({
installPhase = '' installPhase = ''
${if target == "android" then '' ${if target == "android" then ''
${if release then "" ${lib.optionalString (!release) ''
else ''
cp "$(ls build/android/bin/*.apk | grep -v '\-unsigned.apk')" $out cp "$(ls build/android/bin/*.apk | grep -v '\-unsigned.apk')" $out
''} ''}

View file

@ -23,7 +23,7 @@ buildPythonPackage rec {
azure-nspkg azure-nspkg
] ++ lib.optionals (!isPy3k) [ setuptools ]; # need for namespace lookup ] ++ lib.optionals (!isPy3k) [ setuptools ]; # need for namespace lookup
postInstall = if isPy3k then "" else '' postInstall = lib.optionalString (!isPy3k) ''
echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/__init__.py echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/__init__.py
''; '';

View file

@ -26,7 +26,7 @@ buildPythonPackage rec {
msrestazure msrestazure
]; ];
postInstall = if isPy3k then "" else '' postInstall = pkgs.lib.optionalString (!isPy3k) ''
echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/mgmt/__init__.py echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/mgmt/__init__.py
echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/__init__.py echo "__import__('pkg_resources').declare_namespace(__name__)" >> "$out/lib/${python.libPrefix}"/site-packages/azure/__init__.py
''; '';

View file

@ -53,7 +53,7 @@ in buildPythonPackage {
disabled = pythonAtLeast "3.11"; disabled = pythonAtLeast "3.11";
src = let src = let
pyVerNoDot = lib.strings.stringAsChars (x: if x == "." then "" else x) python.pythonVersion; pyVerNoDot = lib.strings.stringAsChars (x: lib.optionalString (x != ".") x) python.pythonVersion;
platform = if stdenv.isDarwin then "mac" else "linux"; platform = if stdenv.isDarwin then "mac" else "linux";
unit = if cudaSupport then "gpu" else "cpu"; unit = if cudaSupport then "gpu" else "cpu";
key = "${platform}_py_${pyVerNoDot}_${unit}"; key = "${platform}_py_${pyVerNoDot}_${unit}";

View file

@ -70,11 +70,12 @@ let
assert gemFiles.gemdir != null; "cp -a ${gemFiles.gemdir}/* $out/") #*/ assert gemFiles.gemdir != null; "cp -a ${gemFiles.gemdir}/* $out/") #*/
); );
maybeCopyAll = pkgname: if pkgname == null then "" else maybeCopyAll = pkgname: lib.optionalString (pkgname != null) (
let let
mainGem = gems.${pkgname} or (throw "bundlerEnv: gem ${pkgname} not found"); mainGem = gems.${pkgname} or (throw "bundlerEnv: gem ${pkgname} not found");
in in
copyIfBundledByPath mainGem; copyIfBundledByPath mainGem
);
# We have to normalize the Gemfile.lock, otherwise bundler tries to be # We have to normalize the Gemfile.lock, otherwise bundler tries to be
# helpful by doing so at run time, causing executables to immediately bail # helpful by doing so at run time, causing executables to immediately bail

View file

@ -224,7 +224,7 @@ stdenv.mkDerivation ((builtins.removeAttrs attrs ["source"]) // {
pushd $out/${ruby.gemPath} pushd $out/${ruby.gemPath}
find doc/ -iname created.rid -delete -print find doc/ -iname created.rid -delete -print
find gems/*/ext/ extensions/ \( -iname Makefile -o -iname mkmf.log -o -iname gem_make.out \) -delete -print find gems/*/ext/ extensions/ \( -iname Makefile -o -iname mkmf.log -o -iname gem_make.out \) -delete -print
${if keepGemCache then "" else "rm -fvr cache"} ${lib.optionalString (!keepGemCache) "rm -fvr cache"}
popd popd
# write out metadata and binstubs # write out metadata and binstubs

View file

@ -26,7 +26,7 @@ let
configureFlagsArray=( CFLAGS="-O2 -fno-strict-aliasing" configureFlagsArray=( CFLAGS="-O2 -fno-strict-aliasing"
CXXFLAGS="-O2 -fno-strict-aliasing" CXXFLAGS="-O2 -fno-strict-aliasing"
--mandir=$out/share/man --mandir=$out/share/man
${if sysconfDir == "" then "" else "--sysconfdir=${sysconfDir}"} ${lib.optionalString (sysconfDir != "") "--sysconfdir=${sysconfDir}"}
${lib.optionalString static "LDFLAGS=-static"} ${lib.optionalString static "LDFLAGS=-static"}
${lib.withFeature (static == true || popt == null) "included-popt"} ${lib.withFeature (static == true || popt == null) "included-popt"}
${lib.withFeature (avahi != null) "avahi"} ${lib.withFeature (avahi != null) "avahi"}

View file

@ -397,10 +397,11 @@ stdenv.mkDerivation ({
meta = { meta = {
description = description =
"The Linux kernel" + "The Linux kernel" +
(if kernelPatches == [] then "" else (lib.optionalString (kernelPatches != []) (
" (with patches: " " (with patches: "
+ lib.concatStringsSep ", " (map (x: x.name) kernelPatches) + lib.concatStringsSep ", " (map (x: x.name) kernelPatches)
+ ")"); + ")"
));
license = lib.licenses.gpl2Only; license = lib.licenses.gpl2Only;
homepage = "https://www.kernel.org/"; homepage = "https://www.kernel.org/";
maintainers = lib.teams.linux-kernel.members ++ [ maintainers = lib.teams.linux-kernel.members ++ [