3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #222080 from Stunkymonkey/nixos-optionalString

This commit is contained in:
Artturi 2023-04-20 16:07:30 +03:00 committed by GitHub
commit b83db86a9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 89 additions and 95 deletions

View file

@ -10,10 +10,7 @@ let
check = x: (lib.types.package.check x) && (attrByPath ["meta" "isIbusEngine"] false x); check = x: (lib.types.package.check x) && (attrByPath ["meta" "isIbusEngine"] false x);
}; };
impanel = impanel = optionalString (cfg.panel != null) "--panel=${cfg.panel}";
if cfg.panel != null
then "--panel=${cfg.panel}"
else "";
ibusAutostart = pkgs.writeTextFile { ibusAutostart = pkgs.writeTextFile {
name = "autostart-ibus-daemon"; name = "autostart-ibus-daemon";

View file

@ -22,8 +22,8 @@ let
(option: '' (option: ''
menuentry '${defaults.name} ${ menuentry '${defaults.name} ${
# Name appended to menuentry defaults to params if no specific name given. # Name appended to menuentry defaults to params if no specific name given.
option.name or (if option ? params then "(${option.params})" else "") option.name or (optionalString (option ? params) "(${option.params})")
}' ${if option ? class then " --class ${option.class}" else ""} { }' ${optionalString (option ? class) " --class ${option.class}"} {
linux ${defaults.image} \''${isoboot} ${defaults.params} ${ linux ${defaults.image} \''${isoboot} ${defaults.params} ${
option.params or "" option.params or ""
} }

View file

@ -11,7 +11,7 @@ let
${concatStringsSep "\n" ${concatStringsSep "\n"
(mapAttrsToList (command: action: "${command} ${action}") cfg.commands) (mapAttrsToList (command: action: "${command} ${action}") cfg.commands)
} }
${if cfg.clearDefaultCommands then "#stop" else ""} ${optionalString cfg.clearDefaultCommands "#stop"}
#line-edit #line-edit
${concatStringsSep "\n" ${concatStringsSep "\n"

View file

@ -1,7 +1,7 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
inherit (lib) mkOption mkIf types; inherit (lib) mkOption mkIf types optionalString;
cfg = config.programs.tmux; cfg = config.programs.tmux;
@ -17,17 +17,17 @@ let
set -g base-index ${toString cfg.baseIndex} set -g base-index ${toString cfg.baseIndex}
setw -g pane-base-index ${toString cfg.baseIndex} setw -g pane-base-index ${toString cfg.baseIndex}
${if cfg.newSession then "new-session" else ""} ${optionalString cfg.newSession "new-session"}
${if cfg.reverseSplit then '' ${optionalString cfg.reverseSplit ''
bind v split-window -h bind v split-window -h
bind s split-window -v bind s split-window -v
'' else ""} ''}
set -g status-keys ${cfg.keyMode} set -g status-keys ${cfg.keyMode}
set -g mode-keys ${cfg.keyMode} set -g mode-keys ${cfg.keyMode}
${if cfg.keyMode == "vi" && cfg.customPaneNavigationAndResize then '' ${optionalString (cfg.keyMode == "vi" && cfg.customPaneNavigationAndResize) ''
bind h select-pane -L bind h select-pane -L
bind j select-pane -D bind j select-pane -D
bind k select-pane -U bind k select-pane -U
@ -37,15 +37,15 @@ let
bind -r J resize-pane -D ${toString cfg.resizeAmount} bind -r J resize-pane -D ${toString cfg.resizeAmount}
bind -r K resize-pane -U ${toString cfg.resizeAmount} bind -r K resize-pane -U ${toString cfg.resizeAmount}
bind -r L resize-pane -R ${toString cfg.resizeAmount} bind -r L resize-pane -R ${toString cfg.resizeAmount}
'' else ""} ''}
${if (cfg.shortcut != defaultShortcut) then '' ${optionalString (cfg.shortcut != defaultShortcut) ''
# rebind main key: C-${cfg.shortcut} # rebind main key: C-${cfg.shortcut}
unbind C-${defaultShortcut} unbind C-${defaultShortcut}
set -g prefix C-${cfg.shortcut} set -g prefix C-${cfg.shortcut}
bind ${cfg.shortcut} send-prefix bind ${cfg.shortcut} send-prefix
bind C-${cfg.shortcut} last-window bind C-${cfg.shortcut} last-window
'' else ""} ''}
setw -g aggressive-resize ${boolToStr cfg.aggressiveResize} setw -g aggressive-resize ${boolToStr cfg.aggressiveResize}
setw -g clock-mode-style ${if cfg.clock24 then "24" else "12"} setw -g clock-mode-style ${if cfg.clock24 then "24" else "12"}

View file

@ -781,11 +781,11 @@ in {
# FIXME Most of these custom warnings and filters for security.acme.certs.* are required # FIXME Most of these custom warnings and filters for security.acme.certs.* are required
# because using mkRemovedOptionModule/mkChangedOptionModule with attrsets isn't possible. # because using mkRemovedOptionModule/mkChangedOptionModule with attrsets isn't possible.
warnings = filter (w: w != "") (mapAttrsToList (cert: data: if data.extraDomains != "_mkMergedOptionModule" then '' warnings = filter (w: w != "") (mapAttrsToList (cert: data: optionalString (data.extraDomains != "_mkMergedOptionModule") ''
The option definition `security.acme.certs.${cert}.extraDomains` has changed The option definition `security.acme.certs.${cert}.extraDomains` has changed
to `security.acme.certs.${cert}.extraDomainNames` and is now a list of strings. to `security.acme.certs.${cert}.extraDomainNames` and is now a list of strings.
Setting a custom webroot for extra domains is not possible, instead use separate certs. Setting a custom webroot for extra domains is not possible, instead use separate certs.
'' else "") cfg.certs); '') cfg.certs);
assertions = let assertions = let
certs = attrValues cfg.certs; certs = attrValues cfg.certs;

View file

@ -275,9 +275,9 @@ in {
warnings = warnings =
# https://github.com/badaix/snapcast/blob/98ac8b2fb7305084376607b59173ce4097c620d8/server/streamreader/stream_manager.cpp#L85 # https://github.com/badaix/snapcast/blob/98ac8b2fb7305084376607b59173ce4097c620d8/server/streamreader/stream_manager.cpp#L85
filter (w: w != "") (mapAttrsToList (k: v: if v.type == "spotify" then '' filter (w: w != "") (mapAttrsToList (k: v: optionalString (v.type == "spotify") ''
services.snapserver.streams.${k}.type = "spotify" is deprecated, use services.snapserver.streams.${k}.type = "librespot" instead. services.snapserver.streams.${k}.type = "spotify" is deprecated, use services.snapserver.streams.${k}.type = "librespot" instead.
'' else "") cfg.streams); '') cfg.streams);
systemd.services.snapserver = { systemd.services.snapserver = {
after = [ "network.target" ]; after = [ "network.target" ];

View file

@ -20,7 +20,7 @@ let
''; '';
backupDatabaseScript = db: '' backupDatabaseScript = db: ''
dest="${cfg.location}/${db}.gz" dest="${cfg.location}/${db}.gz"
if ${mariadb}/bin/mysqldump ${if cfg.singleTransaction then "--single-transaction" else ""} ${db} | ${gzip}/bin/gzip -c > $dest.tmp; then if ${mariadb}/bin/mysqldump ${optionalString cfg.singleTransaction "--single-transaction"} ${db} | ${gzip}/bin/gzip -c > $dest.tmp; then
mv $dest.tmp $dest mv $dest.tmp $dest
echo "Backed up to $dest" echo "Backed up to $dest"
else else

View file

@ -300,7 +300,7 @@ in
filesFromTmpFile = "/run/restic-backups-${name}/includes"; filesFromTmpFile = "/run/restic-backups-${name}/includes";
backupPaths = backupPaths =
if (backup.dynamicFilesFrom == null) if (backup.dynamicFilesFrom == null)
then if (backup.paths != null) then concatStringsSep " " backup.paths else "" then optionalString (backup.paths != null) (concatStringsSep " " backup.paths)
else "--files-from ${filesFromTmpFile}"; else "--files-from ${filesFromTmpFile}";
pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [ pruneCmd = optionals (builtins.length backup.pruneOpts > 0) [
(resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts)) (resticCmd + " forget --prune " + (concatStringsSep " " backup.pruneOpts))

View file

@ -196,9 +196,9 @@ in
--gcmode ${cfg.gcmode} \ --gcmode ${cfg.gcmode} \
--port ${toString cfg.port} \ --port ${toString cfg.port} \
--maxpeers ${toString cfg.maxpeers} \ --maxpeers ${toString cfg.maxpeers} \
${if cfg.http.enable then ''--http --http.addr ${cfg.http.address} --http.port ${toString cfg.http.port}'' else ""} \ ${optionalString cfg.http.enable ''--http --http.addr ${cfg.http.address} --http.port ${toString cfg.http.port}''} \
${optionalString (cfg.http.apis != null) ''--http.api ${lib.concatStringsSep "," cfg.http.apis}''} \ ${optionalString (cfg.http.apis != null) ''--http.api ${lib.concatStringsSep "," cfg.http.apis}''} \
${if cfg.websocket.enable then ''--ws --ws.addr ${cfg.websocket.address} --ws.port ${toString cfg.websocket.port}'' else ""} \ ${optionalString cfg.websocket.enable ''--ws --ws.addr ${cfg.websocket.address} --ws.port ${toString cfg.websocket.port}''} \
${optionalString (cfg.websocket.apis != null) ''--ws.api ${lib.concatStringsSep "," cfg.websocket.apis}''} \ ${optionalString (cfg.websocket.apis != null) ''--ws.api ${lib.concatStringsSep "," cfg.websocket.apis}''} \
${optionalString cfg.metrics.enable ''--metrics --metrics.addr ${cfg.metrics.address} --metrics.port ${toString cfg.metrics.port}''} \ ${optionalString cfg.metrics.enable ''--metrics --metrics.addr ${cfg.metrics.address} --metrics.port ${toString cfg.metrics.port}''} \
--authrpc.addr ${cfg.authrpc.address} --authrpc.port ${toString cfg.authrpc.port} --authrpc.vhosts ${lib.concatStringsSep "," cfg.authrpc.vhosts} \ --authrpc.addr ${cfg.authrpc.address} --authrpc.port ${toString cfg.authrpc.port} --authrpc.vhosts ${lib.concatStringsSep "," cfg.authrpc.vhosts} \

View file

@ -242,7 +242,7 @@ in {
jobdir="${jenkinsCfg.home}/$jenkinsjobname" jobdir="${jenkinsCfg.home}/$jenkinsjobname"
rm -rf "$jobdir" rm -rf "$jobdir"
done done
'' + (if cfg.accessUser != "" then reloadScript else ""); '' + (optionalString (cfg.accessUser != "") reloadScript);
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = jenkinsCfg.user; User = jenkinsCfg.user;

View file

@ -4,7 +4,7 @@ with lib;
let let
cfg = config.services.minetest-server; cfg = config.services.minetest-server;
flag = val: name: if val != null then "--${name} ${toString val} " else ""; flag = val: name: optionalString (val != null) "--${name} ${toString val} ";
flags = [ flags = [
(flag cfg.gameId "gameid") (flag cfg.gameId "gameid")
(flag cfg.world "world") (flag cfg.world "world")

View file

@ -83,9 +83,8 @@ let
}; };
mailOption = mailOption =
if foldr (n: a: a || (n.mail or false) != false) false (attrValues cfg.settings) optionalString (foldr (n: a: a || (n.mail or false) != false) false (attrValues cfg.settings))
then "--mail=${pkgs.mailutils}/bin/mail" "--mail=${pkgs.mailutils}/bin/mail";
else "";
in in
{ {
imports = [ imports = [

View file

@ -7,7 +7,7 @@ let
cfg = config.services.syslogd; cfg = config.services.syslogd;
syslogConf = pkgs.writeText "syslog.conf" '' syslogConf = pkgs.writeText "syslog.conf" ''
${if (cfg.tty != "") then "kern.warning;*.err;authpriv.none /dev/${cfg.tty}" else ""} ${optionalString (cfg.tty != "") "kern.warning;*.err;authpriv.none /dev/${cfg.tty}"}
${cfg.defaultConfig} ${cfg.defaultConfig}
${cfg.extraConfig} ${cfg.extraConfig}
''; '';

View file

@ -234,7 +234,7 @@ let
headerChecks = concatStringsSep "\n" (map (x: "${x.pattern} ${x.action}") cfg.headerChecks) + cfg.extraHeaderChecks; headerChecks = concatStringsSep "\n" (map (x: "${x.pattern} ${x.action}") cfg.headerChecks) + cfg.extraHeaderChecks;
aliases = let separator = if cfg.aliasMapType == "hash" then ":" else ""; in aliases = let separator = optionalString (cfg.aliasMapType == "hash") ":"; in
optionalString (cfg.postmasterAlias != "") '' optionalString (cfg.postmasterAlias != "") ''
postmaster${separator} ${cfg.postmasterAlias} postmaster${separator} ${cfg.postmasterAlias}
'' ''

View file

@ -10,7 +10,7 @@ let
Connection = ${cfg.device.connection} Connection = ${cfg.device.connection}
SynchronizeTime = ${if cfg.device.synchronizeTime then "yes" else "no"} SynchronizeTime = ${if cfg.device.synchronizeTime then "yes" else "no"}
LogFormat = ${cfg.log.format} LogFormat = ${cfg.log.format}
${if (cfg.device.pin != null) then "PIN = ${cfg.device.pin}" else ""} ${optionalString (cfg.device.pin != null) "PIN = ${cfg.device.pin}"}
${cfg.extraConfig.gammu} ${cfg.extraConfig.gammu}
@ -33,10 +33,10 @@ let
${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") ( ${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") (
with cfg.backend; '' with cfg.backend; ''
Driver = ${sql.driver} Driver = ${sql.driver}
${if (sql.database!= null) then "Database = ${sql.database}" else ""} ${optionalString (sql.database!= null) "Database = ${sql.database}"}
${if (sql.host != null) then "Host = ${sql.host}" else ""} ${optionalString (sql.host != null) "Host = ${sql.host}"}
${if (sql.user != null) then "User = ${sql.user}" else ""} ${optionalString (sql.user != null) "User = ${sql.user}"}
${if (sql.password != null) then "Password = ${sql.password}" else ""} ${optionalString (sql.password != null) "Password = ${sql.password}"}
'')} '')}
${cfg.extraConfig.smsd} ${cfg.extraConfig.smsd}

View file

@ -1215,7 +1215,7 @@ in {
enableDelete = true; # This must be true, otherwise GitLab won't manage it correctly enableDelete = true; # This must be true, otherwise GitLab won't manage it correctly
extraConfig = { extraConfig = {
auth.token = { auth.token = {
realm = "http${if cfg.https == true then "s" else ""}://${cfg.host}/jwt/auth"; realm = "http${optionalString (cfg.https == true) "s"}://${cfg.host}/jwt/auth";
service = cfg.registry.serviceName; service = cfg.registry.serviceName;
issuer = cfg.registry.issuer; issuer = cfg.registry.issuer;
rootcertbundle = cfg.registry.certFile; rootcertbundle = cfg.registry.certFile;

View file

@ -3,7 +3,7 @@ with lib;
let let
cfg = config.services.mbpfan; cfg = config.services.mbpfan;
verbose = if cfg.verbose then "v" else ""; verbose = optionalString cfg.verbose "v";
settingsFormat = pkgs.formats.ini {}; settingsFormat = pkgs.formats.ini {};
settingsFile = settingsFormat.generate "mbpfan.ini" cfg.settings; settingsFile = settingsFormat.generate "mbpfan.ini" cfg.settings;

View file

@ -283,13 +283,13 @@ in
services.redmine.settings = { services.redmine.settings = {
production = { production = {
scm_subversion_command = if cfg.components.subversion then "${pkgs.subversion}/bin/svn" else ""; scm_subversion_command = optionalString cfg.components.subversion "${pkgs.subversion}/bin/svn";
scm_mercurial_command = if cfg.components.mercurial then "${pkgs.mercurial}/bin/hg" else ""; scm_mercurial_command = optionalString cfg.components.mercurial "${pkgs.mercurial}/bin/hg";
scm_git_command = if cfg.components.git then "${pkgs.git}/bin/git" else ""; scm_git_command = optionalString cfg.components.git "${pkgs.git}/bin/git";
scm_cvs_command = if cfg.components.cvs then "${pkgs.cvs}/bin/cvs" else ""; scm_cvs_command = optionalString cfg.components.cvs "${pkgs.cvs}/bin/cvs";
scm_bazaar_command = if cfg.components.breezy then "${pkgs.breezy}/bin/bzr" else ""; scm_bazaar_command = optionalString cfg.components.breezy "${pkgs.breezy}/bin/bzr";
imagemagick_convert_command = if cfg.components.imagemagick then "${pkgs.imagemagick}/bin/convert" else ""; imagemagick_convert_command = optionalString cfg.components.imagemagick "${pkgs.imagemagick}/bin/convert";
gs_command = if cfg.components.ghostscript then "${pkgs.ghostscript}/bin/gs" else ""; gs_command = optionalString cfg.components.ghostscript "${pkgs.ghostscript}/bin/gs";
minimagick_font_path = "${cfg.components.minimagick_font_path}"; minimagick_font_path = "${cfg.components.minimagick_font_path}";
}; };
}; };

View file

@ -20,7 +20,7 @@ let
${optionalString (cfg.hostsAllowReg != []) "hosts_allow_reg = ${concatStringsSep "," cfg.hostsAllowReg}"} ${optionalString (cfg.hostsAllowReg != []) "hosts_allow_reg = ${concatStringsSep "," cfg.hostsAllowReg}"}
${optionalString (cfg.hostsAllowSip != []) "hosts_allow_sip = ${concatStringsSep "," cfg.hostsAllowSip}"} ${optionalString (cfg.hostsAllowSip != []) "hosts_allow_sip = ${concatStringsSep "," cfg.hostsAllowSip}"}
${optionalString (cfg.hostsDenySip != []) "hosts_deny_sip = ${concatStringsSep "," cfg.hostsDenySip}"} ${optionalString (cfg.hostsDenySip != []) "hosts_deny_sip = ${concatStringsSep "," cfg.hostsDenySip}"}
${if (cfg.passwordFile != "") then "proxy_auth_pwfile = ${cfg.passwordFile}" else ""} ${optionalString (cfg.passwordFile != "") "proxy_auth_pwfile = ${cfg.passwordFile}"}
${cfg.extraConfig} ${cfg.extraConfig}
''; '';

View file

@ -58,10 +58,10 @@ in
}; };
}; };
serviceOpts = let serviceOpts = let
collectSettingsArgs = if (cfg.collectdBinary.enable) then '' collectSettingsArgs = optionalString (cfg.collectdBinary.enable) ''
--collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \ --collectd.listen-address ${cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \
--collectd.security-level ${cfg.collectdBinary.securityLevel} \ --collectd.security-level ${cfg.collectdBinary.securityLevel} \
'' else ""; '';
in { in {
serviceConfig = { serviceConfig = {
ExecStart = '' ExecStart = ''

View file

@ -1,13 +1,13 @@
{ config, lib, ...}: { config, lib, ...}:
let let
inherit (lib) concatStringsSep mkOption types; inherit (lib) concatStringsSep mkOption types optionalString;
in { in {
mkCellServDB = cellName: db: '' mkCellServDB = cellName: db: ''
>${cellName} >${cellName}
'' + (concatStringsSep "\n" (map (dbm: if (dbm.ip != "" && dbm.dnsname != "") then dbm.ip + " #" + dbm.dnsname else "") '' + (concatStringsSep "\n" (map (dbm: optionalString (dbm.ip != "" && dbm.dnsname != "") "${dbm.ip} #${dbm.dnsname}")
db)) db))
+ "\n"; + "\n";

View file

@ -17,7 +17,7 @@ let
ttl ${toString proxy.ttl} ttl ${toString proxy.ttl}
${render proxy.rules (ruleNetworkName: rule: '' ${render proxy.rules (ruleNetworkName: rule: ''
rule ${prefer rule.network ruleNetworkName} { rule ${prefer rule.network ruleNetworkName} {
${rule.method}${if rule.method == "iface" then " ${rule.interface}" else ""} ${rule.method}${optionalString (rule.method == "iface") " ${rule.interface}"}
}'')} }'')}
}'')} }'')}
''); '');

View file

@ -86,7 +86,7 @@ in
redis.createInstance = mkOption { redis.createInstance = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = if versionAtLeast config.system.stateVersion "22.05" then "ntopng" else ""; default = optionalString (versionAtLeast config.system.stateVersion "22.05") "ntopng";
description = lib.mdDoc '' description = lib.mdDoc ''
Local Redis instance name. Set to `null` to disable Local Redis instance name. Set to `null` to disable
local Redis instance. Defaults to `""` for local Redis instance. Defaults to `""` for

View file

@ -169,11 +169,11 @@ in
else (concatStrings (map (i: "--interface=\"${i}\"") else (concatStrings (map (i: "--interface=\"${i}\"")
interfaces))} \ interfaces))} \
-h "${hostKey}" \ -h "${hostKey}" \
${if !syslog then "--no-syslog" else ""} \ ${optionalString (!syslog) "--no-syslog" } \
${if passwordAuthentication then "--password" else "--no-password" } \ ${if passwordAuthentication then "--password" else "--no-password" } \
${if publicKeyAuthentication then "--publickey" else "--no-publickey" } \ ${if publicKeyAuthentication then "--publickey" else "--no-publickey" } \
${if rootLogin then "--root-login" else "--no-root-login" } \ ${if rootLogin then "--root-login" else "--no-root-login" } \
${if loginShell != null then "--login-shell=\"${loginShell}\"" else "" } \ ${optionalString (loginShell != null) "--login-shell=\"${loginShell}\"" } \
${if srpKeyExchange then "--srp-keyexchange" else "--no-srp-keyexchange" } \ ${if srpKeyExchange then "--srp-keyexchange" else "--no-srp-keyexchange" } \
${if !tcpForwarding then "--no-tcpip-forward" else "--tcpip-forward"} \ ${if !tcpForwarding then "--no-tcpip-forward" else "--tcpip-forward"} \
${if x11Forwarding then "--x11-forward" else "--no-x11-forward" } \ ${if x11Forwarding then "--x11-forward" else "--no-x11-forward" } \

View file

@ -474,10 +474,10 @@ in
mkdir -m 0755 -p "$(dirname '${k.path}')" mkdir -m 0755 -p "$(dirname '${k.path}')"
ssh-keygen \ ssh-keygen \
-t "${k.type}" \ -t "${k.type}" \
${if k ? bits then "-b ${toString k.bits}" else ""} \ ${optionalString (k ? bits) "-b ${toString k.bits}"} \
${if k ? rounds then "-a ${toString k.rounds}" else ""} \ ${optionalString (k ? rounds) "-a ${toString k.rounds}"} \
${if k ? comment then "-C '${k.comment}'" else ""} \ ${optionalString (k ? comment) "-C '${k.comment}'"} \
${if k ? openSSHFormat && k.openSSHFormat then "-o" else ""} \ ${optionalString (k ? openSSHFormat && k.openSSHFormat) "-o"} \
-f "${k.path}" \ -f "${k.path}" \
-N "" -N ""
fi fi
@ -550,7 +550,7 @@ in
'') cfg.ports} '') cfg.ports}
${concatMapStrings ({ port, addr, ... }: '' ${concatMapStrings ({ port, addr, ... }: ''
ListenAddress ${addr}${if port != null then ":" + toString port else ""} ListenAddress ${addr}${optionalString (port != null) (":" + toString port)}
'') cfg.listenAddresses} '') cfg.listenAddresses}
${optionalString cfgc.setXAuthLocation '' ${optionalString cfgc.setXAuthLocation ''

View file

@ -4,7 +4,7 @@ let
inherit (builtins) toFile; inherit (builtins) toFile;
inherit (lib) concatMapStringsSep concatStringsSep mapAttrsToList inherit (lib) concatMapStringsSep concatStringsSep mapAttrsToList
mkIf mkEnableOption mkOption types literalExpression; mkIf mkEnableOption mkOption types literalExpression optionalString;
cfg = config.services.strongswan; cfg = config.services.strongswan;
@ -34,8 +34,8 @@ let
strongswanConf = {setup, connections, ca, secretsFile, managePlugins, enabledPlugins}: toFile "strongswan.conf" '' strongswanConf = {setup, connections, ca, secretsFile, managePlugins, enabledPlugins}: toFile "strongswan.conf" ''
charon { charon {
${if managePlugins then "load_modular = no" else ""} ${optionalString managePlugins "load_modular = no"}
${if managePlugins then ("load = " + (concatStringsSep " " enabledPlugins)) else ""} ${optionalString managePlugins ("load = " + (concatStringsSep " " enabledPlugins))}
plugins { plugins {
stroke { stroke {
secrets_file = ${secretsFile} secrets_file = ${secretsFile}

View file

@ -154,8 +154,8 @@ in
environment.systemPackages = [ pkgs.stunnel ]; environment.systemPackages = [ pkgs.stunnel ];
environment.etc."stunnel.cfg".text = '' environment.etc."stunnel.cfg".text = ''
${ if cfg.user != null then "setuid = ${cfg.user}" else "" } ${ optionalString (cfg.user != null) "setuid = ${cfg.user}" }
${ if cfg.group != null then "setgid = ${cfg.group}" else "" } ${ optionalString (cfg.group != null) "setgid = ${cfg.group}" }
debug = ${cfg.logLevel} debug = ${cfg.logLevel}

View file

@ -27,7 +27,7 @@ let
${optionalString srv.unlisted "type = UNLISTED"} ${optionalString srv.unlisted "type = UNLISTED"}
${optionalString (srv.flags != "") "flags = ${srv.flags}"} ${optionalString (srv.flags != "") "flags = ${srv.flags}"}
socket_type = ${if srv.protocol == "udp" then "dgram" else "stream"} socket_type = ${if srv.protocol == "udp" then "dgram" else "stream"}
${if srv.port != 0 then "port = ${toString srv.port}" else ""} ${optionalString (srv.port != 0) "port = ${toString srv.port}"}
wait = ${if srv.protocol == "udp" then "yes" else "no"} wait = ${if srv.protocol == "udp" then "yes" else "no"}
user = ${srv.user} user = ${srv.user}
server = ${srv.server} server = ${srv.server}

View file

@ -72,15 +72,14 @@ let
} // (getProviderOptions cfg cfg.provider) // cfg.extraConfig; } // (getProviderOptions cfg cfg.provider) // cfg.extraConfig;
mapConfig = key: attr: mapConfig = key: attr:
if attr != null && attr != [] then ( optionalString (attr != null && attr != []) (
if isDerivation attr then mapConfig key (toString attr) else if isDerivation attr then mapConfig key (toString attr) else
if (builtins.typeOf attr) == "set" then concatStringsSep " " if (builtins.typeOf attr) == "set" then concatStringsSep " "
(mapAttrsToList (name: value: mapConfig (key + "-" + name) value) attr) else (mapAttrsToList (name: value: mapConfig (key + "-" + name) value) attr) else
if (builtins.typeOf attr) == "list" then concatMapStringsSep " " (mapConfig key) attr else if (builtins.typeOf attr) == "list" then concatMapStringsSep " " (mapConfig key) attr else
if (builtins.typeOf attr) == "bool" then "--${key}=${boolToString attr}" else if (builtins.typeOf attr) == "bool" then "--${key}=${boolToString attr}" else
if (builtins.typeOf attr) == "string" then "--${key}='${attr}'" else if (builtins.typeOf attr) == "string" then "--${key}='${attr}'" else
"--${key}=${toString attr}") "--${key}=${toString attr}");
else "";
configString = concatStringsSep " " (mapAttrsToList mapConfig allConfig); configString = concatStringsSep " " (mapAttrsToList mapConfig allConfig);
in in

View file

@ -72,7 +72,7 @@ in {
EnvironmentFile = cfg.credentialsFile; EnvironmentFile = cfg.credentialsFile;
ExecStart = '' ExecStart = ''
${cfg.package}/bin/cachix ${lib.optionalString cfg.verbose "--verbose"} ${lib.optionalString (cfg.host != null) "--host ${cfg.host}"} \ ${cfg.package}/bin/cachix ${lib.optionalString cfg.verbose "--verbose"} ${lib.optionalString (cfg.host != null) "--host ${cfg.host}"} \
deploy agent ${cfg.name} ${if cfg.profile != null then cfg.profile else ""} deploy agent ${cfg.name} ${optionalString (cfg.profile != null) cfg.profile}
''; '';
}; };
}; };

View file

@ -1025,8 +1025,8 @@ in
services.postfix = lib.mkIf cfg.mail.incoming.enable { services.postfix = lib.mkIf cfg.mail.incoming.enable {
enable = true; enable = true;
sslCert = if cfg.sslCertificate != null then cfg.sslCertificate else ""; sslCert = lib.optionalString (cfg.sslCertificate != null) cfg.sslCertificate;
sslKey = if cfg.sslCertificateKey != null then cfg.sslCertificateKey else ""; sslKey = lib.optionalString (cfg.sslCertificateKey != null) cfg.sslCertificateKey;
origin = cfg.hostname; origin = cfg.hostname;
relayDomains = [ cfg.hostname ]; relayDomains = [ cfg.hostname ];

View file

@ -54,7 +54,7 @@ in {
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${builtins.toString cfg.preforkProcesses} ${ ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${builtins.toString cfg.preforkProcesses} ${
if (cfg.socketType != "unix") then "-s ${cfg.socketType}:${cfg.socketAddress}" else "" optionalString (cfg.socketType != "unix") "-s ${cfg.socketType}:${cfg.socketAddress}"
}"; }";
} // (if cfg.user != null && cfg.group != null then { } // (if cfg.user != null && cfg.group != null then {
User = cfg.user; User = cfg.user;

View file

@ -64,7 +64,7 @@ let
]; ];
maybeModuleString = moduleName: maybeModuleString = moduleName:
if elem moduleName cfg.enableModules then ''"${moduleName}"'' else ""; optionalString (elem moduleName cfg.enableModules) ''"${moduleName}"'';
modulesIncludeString = concatStringsSep ",\n" modulesIncludeString = concatStringsSep ",\n"
(filter (x: x != "") (map maybeModuleString allKnownModules)); (filter (x: x != "") (map maybeModuleString allKnownModules));
@ -106,15 +106,15 @@ let
static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" ) index-file.names = ( "index.html" )
${if cfg.mod_userdir then '' ${optionalString cfg.mod_userdir ''
userdir.path = "public_html" userdir.path = "public_html"
'' else ""} ''}
${if cfg.mod_status then '' ${optionalString cfg.mod_status ''
status.status-url = "/server-status" status.status-url = "/server-status"
status.statistics-url = "/server-statistics" status.statistics-url = "/server-statistics"
status.config-url = "/server-config" status.config-url = "/server-config"
'' else ""} ''}
${cfg.extraConfig} ${cfg.extraConfig}
''; '';

View file

@ -318,7 +318,7 @@ let
listenString = { addr, port, ssl, extraParameters ? [], ... }: listenString = { addr, port, ssl, extraParameters ? [], ... }:
# UDP listener for QUIC transport protocol. # UDP listener for QUIC transport protocol.
(if ssl && vhost.quic then " (optionalString (ssl && vhost.quic) "
listen ${addr}:${toString port} quic " listen ${addr}:${toString port} quic "
+ optionalString vhost.default "default_server " + optionalString vhost.default "default_server "
+ optionalString vhost.reuseport "reuseport " + optionalString vhost.reuseport "reuseport "
@ -326,7 +326,7 @@ let
let inCompatibleParameters = [ "ssl" "proxy_protocol" "http2" ]; let inCompatibleParameters = [ "ssl" "proxy_protocol" "http2" ];
isCompatibleParameter = param: !(any (p: p == param) inCompatibleParameters); isCompatibleParameter = param: !(any (p: p == param) inCompatibleParameters);
in filter isCompatibleParameter extraParameters)) in filter isCompatibleParameter extraParameters))
+ ";" else "") + ";")
+ " + "
listen ${addr}:${toString port} " listen ${addr}:${toString port} "

View file

@ -234,11 +234,11 @@ in
ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i` ln -sfn ${tomcat}/conf/$i ${cfg.baseDir}/conf/`basename $i`
done done
${if cfg.extraConfigFiles != [] then '' ${optionalString (cfg.extraConfigFiles != []) ''
for i in ${toString cfg.extraConfigFiles}; do for i in ${toString cfg.extraConfigFiles}; do
ln -sfn $i ${cfg.baseDir}/conf/`basename $i` ln -sfn $i ${cfg.baseDir}/conf/`basename $i`
done done
'' else ""} ''}
# Create a modified catalina.properties file # Create a modified catalina.properties file
# Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries # Change all references from CATALINA_HOME to CATALINA_BASE and add support for shared libraries
@ -345,7 +345,7 @@ in
# Symlink all the given web applications files or paths into the webapps/ directory # Symlink all the given web applications files or paths into the webapps/ directory
# of this virtual host # of this virtual host
for i in "${if virtualHost ? webapps then toString virtualHost.webapps else ""}"; do for i in "${optionalString (virtualHost ? webapps) (toString virtualHost.webapps)}"; do
if [ -f $i ]; then if [ -f $i ]; then
# If the given web application is a file, symlink it into the webapps/ directory # If the given web application is a file, symlink it into the webapps/ directory
ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i` ln -sfn $i ${cfg.baseDir}/virtualhosts/${virtualHost.name}/webapps/`basename $i`

View file

@ -33,7 +33,7 @@ let
then realGrub.override { efiSupport = cfg.efiSupport; } then realGrub.override { efiSupport = cfg.efiSupport; }
else null; else null;
f = x: if x == null then "" else "" + x; f = x: optionalString (x != null) ("" + x);
grubConfig = args: grubConfig = args:
let let
@ -52,7 +52,7 @@ let
fullName = lib.getName realGrub; fullName = lib.getName realGrub;
fullVersion = lib.getVersion realGrub; fullVersion = lib.getVersion realGrub;
grubEfi = f grubEfi; grubEfi = f grubEfi;
grubTargetEfi = if cfg.efiSupport && (cfg.version == 2) then f (grubEfi.grubTarget or "") else ""; grubTargetEfi = optionalString (cfg.efiSupport && (cfg.version == 2)) (f (grubEfi.grubTarget or ""));
bootPath = args.path; bootPath = args.path;
storePath = config.boot.loader.grub.storePath; storePath = config.boot.loader.grub.storePath;
bootloaderId = if args.efiBootloaderId == null then "${config.system.nixos.distroName}${efiSysMountPoint'}" else args.efiBootloaderId; bootloaderId = if args.efiBootloaderId == null then "${config.system.nixos.distroName}${efiSysMountPoint'}" else args.efiBootloaderId;

View file

@ -20,7 +20,7 @@ let
nix = config.nix.package.out; nix = config.nix.package.out;
timeout = if config.boot.loader.timeout != null then config.boot.loader.timeout else ""; timeout = optionalString (config.boot.loader.timeout != null) config.boot.loader.timeout;
editor = if cfg.editor then "True" else "False"; editor = if cfg.editor then "True" else "False";
@ -32,9 +32,9 @@ let
inherit (config.system.nixos) distroName; inherit (config.system.nixos) distroName;
memtest86 = if cfg.memtest86.enable then pkgs.memtest86-efi else ""; memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86-efi;
netbootxyz = if cfg.netbootxyz.enable then pkgs.netbootxyz-efi else ""; netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi;
copyExtraFiles = pkgs.writeShellScript "copy-extra-files" '' copyExtraFiles = pkgs.writeShellScript "copy-extra-files" ''
empty_file=$(${pkgs.coreutils}/bin/mktemp) empty_file=$(${pkgs.coreutils}/bin/mktemp)

View file

@ -1024,13 +1024,12 @@ in
copy_bin_and_libs ${pkgs.gnupg}/libexec/scdaemon copy_bin_and_libs ${pkgs.gnupg}/libexec/scdaemon
${concatMapStringsSep "\n" (x: ${concatMapStringsSep "\n" (x:
if x.gpgCard != null then optionalString (x.gpgCard != null)
'' ''
mkdir -p $out/secrets/gpg-keys/${x.device} mkdir -p $out/secrets/gpg-keys/${x.device}
cp -a ${x.gpgCard.encryptedPass} $out/secrets/gpg-keys/${x.device}/cryptkey.gpg cp -a ${x.gpgCard.encryptedPass} $out/secrets/gpg-keys/${x.device}/cryptkey.gpg
cp -a ${x.gpgCard.publicKey} $out/secrets/gpg-keys/${x.device}/pubkey.asc cp -a ${x.gpgCard.publicKey} $out/secrets/gpg-keys/${x.device}/pubkey.asc
'' ''
else ""
) (attrValues luks.devices) ) (attrValues luks.devices)
} }
''} ''}

View file

@ -319,7 +319,7 @@ in
message = let message = let
fs = head (filter notAutoResizable fileSystems); fs = head (filter notAutoResizable fileSystems);
in in
"Mountpoint '${fs.mountPoint}': 'autoResize = true' is not supported for 'fsType = \"${fs.fsType}\"':${if fs.fsType == "auto" then " fsType has to be explicitly set and" else ""} only the ext filesystems and f2fs support it."; "Mountpoint '${fs.mountPoint}': 'autoResize = true' is not supported for 'fsType = \"${fs.fsType}\"':${optionalString (fs.fsType == "auto") " fsType has to be explicitly set and"} only the ext filesystems and f2fs support it.";
} }
]; ];

View file

@ -170,11 +170,11 @@ let
--setenv HOST_PORT="$HOST_PORT" \ --setenv HOST_PORT="$HOST_PORT" \
--setenv PATH="$PATH" \ --setenv PATH="$PATH" \
${optionalString cfg.ephemeral "--ephemeral"} \ ${optionalString cfg.ephemeral "--ephemeral"} \
${if cfg.additionalCapabilities != null && cfg.additionalCapabilities != [] then ${optionalString (cfg.additionalCapabilities != null && cfg.additionalCapabilities != [])
''--capability="${concatStringsSep "," cfg.additionalCapabilities}"'' else "" ''--capability="${concatStringsSep "," cfg.additionalCapabilities}"''
} \ } \
${if cfg.tmpfs != null && cfg.tmpfs != [] then ${optionalString (cfg.tmpfs != null && cfg.tmpfs != [])
''--tmpfs=${concatStringsSep " --tmpfs=" cfg.tmpfs}'' else "" ''--tmpfs=${concatStringsSep " --tmpfs=" cfg.tmpfs}''
} \ } \
${containerInit cfg} "''${SYSTEM_PATH:-/nix/var/nix/profiles/system}/init" ${containerInit cfg} "''${SYSTEM_PATH:-/nix/var/nix/profiles/system}/init"
''; '';

View file

@ -214,11 +214,11 @@ let
mkdir $out mkdir $out
diskImage=$out/disk.img diskImage=$out/disk.img
${qemu}/bin/qemu-img create -f qcow2 $diskImage "120M" ${qemu}/bin/qemu-img create -f qcow2 $diskImage "120M"
${if cfg.useEFIBoot then '' ${lib.optionalString cfg.useEFIBoot ''
efiVars=$out/efi-vars.fd efiVars=$out/efi-vars.fd
cp ${cfg.efi.variables} $efiVars cp ${cfg.efi.variables} $efiVars
chmod 0644 $efiVars chmod 0644 $efiVars
'' else ""} ''}
''; '';
buildInputs = [ pkgs.util-linux ]; buildInputs = [ pkgs.util-linux ];
QEMU_OPTS = "-nographic -serial stdio -monitor none" QEMU_OPTS = "-nographic -serial stdio -monitor none"