Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/lib/booleans.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ lib }: {
# Converts a boolean to a yes/no string. This is used in lots of
# configuration formats.
yesNo = value: if value then "yes" else "no";
}
1 change: 1 addition & 0 deletions modules/lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rec {

assertions = import ./assertions.nix { inherit lib; };

booleans = import ./booleans.nix { inherit lib; };
gvariant = import ./gvariant.nix { inherit lib; };
maintainers = import ./maintainers.nix;
strings = import ./strings.nix { inherit lib; };
Expand Down
9 changes: 4 additions & 5 deletions modules/programs/irssi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let

cfg = config.programs.irssi;

boolStr = b: if b then "yes" else "no";
quoteStr = s: escape [ ''"'' ] s;

# Comma followed by newline.
Expand All @@ -33,9 +32,9 @@ let
chatnet = "${k}";
address = "${v.server.address}";
port = "${toString v.server.port}";
use_ssl = "${boolStr v.server.ssl.enable}";
ssl_verify = "${boolStr v.server.ssl.verify}";
autoconnect = "${boolStr v.server.autoConnect}";
use_ssl = "${lib.hm.booleans.yesNo v.server.ssl.enable}";
ssl_verify = "${lib.hm.booleans.yesNo v.server.ssl.verify}";
autoconnect = "${lib.hm.booleans.yesNo v.server.autoConnect}";
${
lib.optionalString (v.server.ssl.certificateFile != null) ''
ssl_cert = "${v.server.ssl.certificateFile}";
Expand All @@ -50,7 +49,7 @@ let
{
chatnet = "${k}";
name = "${c}";
autojoin = "${boolStr cv.autoJoin}";
autojoin = "${lib.hm.booleans.yesNo cv.autoJoin}";
}
'')))));

Expand Down
6 changes: 2 additions & 4 deletions modules/programs/kitty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ let
toKittyConfig = generators.toKeyValue {
mkKeyValue = key: value:
let
value' = if isBool value then
(if value then "yes" else "no")
else
toString value;
value' =
(if isBool value then lib.hm.booleans.yesNo else toString) value;
in "${key} ${value'}";
};

Expand Down
2 changes: 1 addition & 1 deletion modules/programs/mbsync.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let
if isList v then
concatMapStringsSep " " (genValue n) v
else if isBool v then
(if v then "yes" else "no")
lib.hm.booleans.yesNo v
else if isInt v then
toString v
else if isString v && hasSpace v then
Expand Down
4 changes: 1 addition & 3 deletions modules/programs/mpv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ let
rec {
int = toString option;
float = int;

bool = if option then "yes" else "no";

bool = lib.hm.booleans.yesNo option;
string = option;
}.${typeOf option};

Expand Down
2 changes: 1 addition & 1 deletion modules/programs/ncmpcpp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let
renderValue = option:
{
int = toString option;
bool = if option then "yes" else "no";
bool = lib.hm.booleans.yesNo option;
string = option;
}.${builtins.typeOf option};

Expand Down
9 changes: 5 additions & 4 deletions modules/programs/neomutt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ let
};
};

yesno = x: if x then "yes" else "no";
setOption = n: v: if v == null then "unset ${n}" else "set ${n}=${v}";
escape = replaceStrings [ "%" ] [ "%25" ];

Expand Down Expand Up @@ -167,7 +166,7 @@ let
sidebarSection = ''
# Sidebar
set sidebar_visible = yes
set sidebar_short_path = ${yesno cfg.sidebar.shortPath}
set sidebar_short_path = ${lib.hm.booleans.yesNo cfg.sidebar.shortPath}
set sidebar_width = ${toString cfg.sidebar.width}
set sidebar_format = '${cfg.sidebar.format}'
'';
Expand Down Expand Up @@ -204,8 +203,10 @@ let

# GPG section
set crypt_use_gpgme = yes
set crypt_autosign = ${yesno (gpg.signByDefault or false)}
set crypt_opportunistic_encrypt = ${yesno (gpg.encryptByDefault or false)}
set crypt_autosign = ${lib.hm.booleans.yesNo (gpg.signByDefault or false)}
set crypt_opportunistic_encrypt = ${
lib.hm.booleans.yesNo (gpg.encryptByDefault or false)
}
set pgp_use_gpg_agent = yes
set mbox_type = ${if maildir != null then "Maildir" else "mbox"}
set sort = "${cfg.sort}"
Expand Down
2 changes: 1 addition & 1 deletion modules/programs/newsboat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let
max-items ${toString cfg.maxItems}
browser ${cfg.browser}
reload-threads ${toString cfg.reloadThreads}
auto-reload ${if cfg.autoReload then "yes" else "no"}
auto-reload ${lib.hm.booleans.yesNo cfg.autoReload}
${optionalString (cfg.reloadTime != null)
(toString "reload-time ${toString cfg.reloadTime}")}
prepopulate-query-feeds yes
Expand Down
6 changes: 2 additions & 4 deletions modules/programs/offlineimap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ let
toIni = generators.toINI {
mkKeyValue = key: value:
let
value' = if isBool value then
(if value then "yes" else "no")
else
toString value;
value' =
(if isBool value then lib.hm.booleans.yesNo else toString) value;
in "${key} = ${value'}";
};

Expand Down
12 changes: 5 additions & 7 deletions modules/programs/ssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ let
then " ${entry.address}"
else " [${entry.address}]:${toString entry.port}";

yn = flag: if flag then "yes" else "no";

unwords = builtins.concatStringsSep " ";

bindOptions = {
Expand Down Expand Up @@ -284,7 +282,7 @@ let
matchBlockStr = cf: concatStringsSep "\n" (
["Host ${cf.host}"]
++ optional (cf.port != null) " Port ${toString cf.port}"
++ optional (cf.forwardAgent != null) " ForwardAgent ${yn cf.forwardAgent}"
++ optional (cf.forwardAgent != null) " ForwardAgent ${lib.hm.booleans.yesNo cf.forwardAgent}"
++ optional cf.forwardX11 " ForwardX11 yes"
++ optional cf.forwardX11Trusted " ForwardX11Trusted yes"
++ optional cf.identitiesOnly " IdentitiesOnly yes"
Expand All @@ -296,7 +294,7 @@ let
" ServerAliveInterval ${toString cf.serverAliveInterval}"
++ optional (cf.serverAliveCountMax != 3)
" ServerAliveCountMax ${toString cf.serverAliveCountMax}"
++ optional (cf.compression != null) " Compression ${yn cf.compression}"
++ optional (cf.compression != null) " Compression ${lib.hm.booleans.yesNo cf.compression}"
++ optional (!cf.checkHostIP) " CheckHostIP no"
++ optional (cf.proxyCommand != null) " ProxyCommand ${cf.proxyCommand}"
++ optional (cf.proxyJump != null) " ProxyJump ${cf.proxyJump}"
Expand Down Expand Up @@ -498,11 +496,11 @@ in
)}

Host *
ForwardAgent ${yn cfg.forwardAgent}
Compression ${yn cfg.compression}
ForwardAgent ${lib.hm.booleans.yesNo cfg.forwardAgent}
Compression ${lib.hm.booleans.yesNo cfg.compression}
ServerAliveInterval ${toString cfg.serverAliveInterval}
ServerAliveCountMax ${toString cfg.serverAliveCountMax}
HashKnownHosts ${yn cfg.hashKnownHosts}
HashKnownHosts ${lib.hm.booleans.yesNo cfg.hashKnownHosts}
UserKnownHostsFile ${cfg.userKnownHostsFile}
ControlMaster ${cfg.controlMaster}
ControlPath ${cfg.controlPath}
Expand Down
28 changes: 14 additions & 14 deletions modules/programs/zsh/prezto.nix
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ in {
# Generated by Nix
${optionalString (cfg.caseSensitive != null) ''
zstyle ':prezto:*:*' case-sensitive '${
if cfg.caseSensitive then "yes" else "no"
lib.hm.booleans.yesNo cfg.caseSensitive
}'
''}
${optionalString (cfg.color != null) ''
zstyle ':prezto:*:*' color '${if cfg.color then "yes" else "no"}'
zstyle ':prezto:*:*' color '${lib.hm.booleans.yesNo cfg.color}'
''}
${optionalString (cfg.pmoduleDirs != [ ]) ''
zstyle ':prezto:load' pmodule-dirs ${
Expand Down Expand Up @@ -410,12 +410,12 @@ in {
''}
${optionalString (cfg.editor.dotExpansion != null) ''
zstyle ':prezto:module:editor' dot-expansion '${
if cfg.editor.dotExpansion then "yes" else "no"
lib.hm.booleans.yesNo cfg.editor.dotExpansion
}'
''}
${optionalString (cfg.editor.promptContext != null) ''
zstyle ':prezto:module:editor' ps-context '${
if cfg.editor.promptContext then "yes" else "no"
lib.hm.booleans.yesNo cfg.editor.promptContext
}'
''}
${optionalString (cfg.git.submoduleIgnore != null) ''
Expand Down Expand Up @@ -447,27 +447,27 @@ in {
''}
${optionalString (cfg.python.virtualenvAutoSwitch != null) ''
zstyle ':prezto:module:python:virtualenv' auto-switch '${
if cfg.python.virtualenvAutoSwitch then "yes" else "no"
lib.hm.booleans.yesNo cfg.python.virtualenvAutoSwitch
}'
''}
${optionalString (cfg.python.virtualenvInitialize != null) ''
zstyle ':prezto:module:python:virtualenv' initialize '${
if cfg.python.virtualenvInitialize then "yes" else "no"
lib.hm.booleans.yesNo cfg.python.virtualenvInitialize
}'
''}
${optionalString (cfg.ruby.chrubyAutoSwitch != null) ''
zstyle ':prezto:module:ruby:chruby' auto-switch '${
if cfg.ruby.chrubyAutoSwitch then "yes" else "no"
lib.hm.booleans.yesNo cfg.ruby.chrubyAutoSwitch
}'
''}
${optionalString (cfg.screen.autoStartLocal != null) ''
zstyle ':prezto:module:screen:auto-start' local '${
if cfg.screen.autoStartLocal then "yes" else "no"
lib.hm.booleans.yesNo cfg.screen.autoStartLocal
}'
''}
${optionalString (cfg.screen.autoStartRemote != null) ''
zstyle ':prezto:module:screen:auto-start' remote '${
if cfg.screen.autoStartRemote then "yes" else "no"
lib.hm.booleans.yesNo cfg.screen.autoStartRemote
}'
''}
${optionalString (cfg.ssh.identities != [ ]) ''
Expand Down Expand Up @@ -502,7 +502,7 @@ in {
''}
${optionalString (cfg.terminal.autoTitle != null) ''
zstyle ':prezto:module:terminal' auto-title '${
if cfg.terminal.autoTitle then "yes" else "no"
lib.hm.booleans.yesNo cfg.terminal.autoTitle
}'
''}
${optionalString (cfg.terminal.windowTitleFormat != null) ''
Expand All @@ -516,25 +516,25 @@ in {
''}
${optionalString (cfg.tmux.autoStartLocal != null) ''
zstyle ':prezto:module:tmux:auto-start' local '${
if cfg.tmux.autoStartLocal then "yes" else "no"
lib.hm.booleans.yesNo cfg.tmux.autoStartLocal
}'
''}
${optionalString (cfg.tmux.autoStartRemote != null) ''
zstyle ':prezto:module:tmux:auto-start' remote '${
if cfg.tmux.autoStartRemote then "yes" else "no"
lib.hm.booleans.yesNo cfg.tmux.autoStartRemote
}'
''}
${optionalString (cfg.tmux.itermIntegration != null) ''
zstyle ':prezto:module:tmux:iterm' integrate '${
if cfg.tmux.itermIntegration then "yes" else "no"
lib.hm.booleans.yesNo cfg.tmux.itermIntegration
}'
''}
${optionalString (cfg.tmux.defaultSessionName != null) ''
zstyle ':prezto:module:tmux:session' name '${cfg.tmux.defaultSessionName}'
''}
${optionalString (cfg.utility.safeOps != null) ''
zstyle ':prezto:module:utility' safe-ops '${
if cfg.utility.safeOps then "yes" else "no"
lib.hm.booleans.yesNo cfg.utility.safeOps
}'
''}
${cfg.extraConfig}
Expand Down
2 changes: 1 addition & 1 deletion modules/services/dunst.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let
mkKeyValue = key: value:
let
value' = if isBool value then
(if value then "yes" else "no")
(lib.hm.booleans.yesNo value)
else if isString value then
''"${value}"''
else
Expand Down
6 changes: 3 additions & 3 deletions modules/services/window-managers/i3-sway/i3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ let
"floating_modifier ${floating.modifier}"
(windowBorderString window floating)
"hide_edge_borders ${window.hideEdgeBorders}"
"force_focus_wrapping ${if focus.forceWrapping then "yes" else "no"}"
"focus_follows_mouse ${if focus.followMouse then "yes" else "no"}"
"force_focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}"
"focus_follows_mouse ${lib.hm.booleans.yesNo focus.followMouse}"
"focus_on_window_activation ${focus.newWindow}"
"mouse_warping ${if focus.mouseWarping then "output" else "none"}"
"workspace_layout ${workspaceLayout}"
"workspace_auto_back_and_forth ${
if workspaceAutoBackAndForth then "yes" else "no"
lib.hm.booleans.yesNo workspaceAutoBackAndForth
}"
"client.focused ${colorSetStr colors.focused}"
"client.focused_inactive ${colorSetStr colors.focusedInactive}"
Expand Down
4 changes: 2 additions & 2 deletions modules/services/window-managers/i3-sway/lib/functions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ rec {
"status_command ${statusCommand}")
"${moduleName}bar_command ${command}"
(optionalString (workspaceButtons != null)
"workspace_buttons ${if workspaceButtons then "yes" else "no"}")
"workspace_buttons ${lib.hm.booleans.yesNo workspaceButtons}")
(optionalString (workspaceNumbers != null)
"strip_workspace_numbers ${
if !workspaceNumbers then "yes" else "no"
lib.hm.booleans.yesNo (!workspaceNumbers)
}")
(optionalString (trayOutput != null) "tray_output ${trayOutput}")
(optionals colorsNotNull (indent
Expand Down
5 changes: 1 addition & 4 deletions modules/services/window-managers/i3-sway/lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,7 @@ in {
default = if isSway then "yes" else true;
description = "Whether focus should follow the mouse.";
apply = val:
if (isSway && isBool val) then
(if val then "yes" else "no")
else
val;
if (isSway && isBool val) then (lib.hm.booleans.yesNo val) else val;
};

forceWrapping = mkOption {
Expand Down
4 changes: 2 additions & 2 deletions modules/services/window-managers/i3-sway/sway.nix
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ let
"floating_modifier ${floating.modifier}"
(windowBorderString window floating)
"hide_edge_borders ${window.hideEdgeBorders}"
"focus_wrapping ${if focus.forceWrapping then "yes" else "no"}"
"focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}"
"focus_follows_mouse ${focus.followMouse}"
"focus_on_window_activation ${focus.newWindow}"
"mouse_warping ${if focus.mouseWarping then "output" else "none"}"
"workspace_layout ${workspaceLayout}"
"workspace_auto_back_and_forth ${
if workspaceAutoBackAndForth then "yes" else "no"
lib.hm.booleans.yesNo workspaceAutoBackAndForth
}"
"client.focused ${colorSetStr colors.focused}"
"client.focused_inactive ${colorSetStr colors.focusedInactive}"
Expand Down