1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-09 18:41:06 +01:00

treewide: remove formatting excludes

This removes the last three formatting excludes so that the entire
project is formatted by nixfmt. This is the first step towards moving
to the RFC style format.
This commit is contained in:
Robert Helgesson 2024-12-13 13:20:31 +01:00
parent 3066cc58f5
commit a17d730ab5
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
4 changed files with 540 additions and 574 deletions

View file

@ -6,21 +6,21 @@ let
cfg = config.programs.zsh;
relToDotDir = file: (optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
relToDotDir = file:
(optionalString (cfg.dotDir != null) (cfg.dotDir + "/")) + file;
pluginsDir = if cfg.dotDir != null then
relToDotDir "plugins" else ".zsh/plugins";
pluginsDir =
if cfg.dotDir != null then relToDotDir "plugins" else ".zsh/plugins";
envVarsStr = config.lib.zsh.exportAll cfg.sessionVariables;
localVarsStr = config.lib.zsh.defineAll cfg.localVariables;
aliasesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: "alias -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") cfg.shellAliases
);
aliasesStr = concatStringsSep "\n" (mapAttrsToList
(k: v: "alias -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}")
cfg.shellAliases);
dirHashesStr = concatStringsSep "\n" (
mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes
);
dirHashesStr = concatStringsSep "\n"
(mapAttrsToList (k: v: ''hash -d ${k}="${v}"'') cfg.dirHashes);
zdotdir = "$HOME/" + lib.escapeShellArg cfg.dotDir;
@ -64,20 +64,22 @@ let
path = mkOption {
type = types.str;
default = if versionAtLeast stateVersion "20.03"
then "$HOME/.zsh_history"
else relToDotDir ".zsh_history";
default = if versionAtLeast stateVersion "20.03" then
"$HOME/.zsh_history"
else
relToDotDir ".zsh_history";
defaultText = literalExpression ''
"$HOME/.zsh_history" if state version 20.03,
"$ZDOTDIR/.zsh_history" otherwise
'';
example = literalExpression ''"''${config.xdg.dataHome}/zsh/zsh_history"'';
example =
literalExpression ''"''${config.xdg.dataHome}/zsh/zsh_history"'';
description = "History file location";
};
ignorePatterns = mkOption {
type = types.listOf types.str;
default = [];
default = [ ];
example = literalExpression ''[ "rm *" "pkill *" ]'';
description = ''
Do not enter command lines into the history list
@ -170,7 +172,7 @@ let
package = mkPackageOption pkgs "oh-my-zsh" { };
plugins = mkOption {
default = [];
default = [ ];
example = [ "git" "sudo" ];
type = types.listOf types.str;
description = ''
@ -215,7 +217,7 @@ let
options = {
enable = mkEnableOption "history substring search";
searchUpKey = mkOption {
type = with types; either (listOf str) str ;
type = with types; either (listOf str) str;
default = [ "^[[A" ];
description = ''
The key codes to be used when searching up.
@ -224,7 +226,7 @@ let
'';
};
searchDownKey = mkOption {
type = with types; either (listOf str) str ;
type = with types; either (listOf str) str;
default = [ "^[[B" ];
description = ''
The key codes to be used when searching down.
@ -253,7 +255,7 @@ let
patterns = mkOption {
type = types.attrsOf types.str;
default = {};
default = { };
example = { "rm -rf *" = "fg=white,bold,bg=red"; };
description = ''
Custom syntax highlighting for user-defined patterns.
@ -263,7 +265,7 @@ let
styles = mkOption {
type = types.attrsOf types.str;
default = {};
default = { };
example = { comment = "fg=black,bold"; };
description = ''
Custom styles for syntax highlighting.
@ -273,13 +275,25 @@ let
};
};
in
{
in {
imports = [
(mkRenamedOptionModule [ "programs" "zsh" "enableAutosuggestions" ] [ "programs" "zsh" "autosuggestion" "enable" ])
(mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [ "programs" "zsh" "syntaxHighlighting" "enable" ])
(mkRenamedOptionModule [ "programs" "zsh" "zproof" ] [ "programs" "zsh" "zprof" ])
(mkRenamedOptionModule [ "programs" "zsh" "enableAutosuggestions" ] [
"programs"
"zsh"
"autosuggestion"
"enable"
])
(mkRenamedOptionModule [ "programs" "zsh" "enableSyntaxHighlighting" ] [
"programs"
"zsh"
"syntaxHighlighting"
"enable"
])
(mkRenamedOptionModule [ "programs" "zsh" "zproof" ] [
"programs"
"zsh"
"zprof"
])
];
options = {
@ -297,7 +311,7 @@ in
};
cdpath = mkOption {
default = [];
default = [ ];
description = ''
List of paths to autocomplete calls to {command}`cd`.
'';
@ -316,7 +330,7 @@ in
};
shellAliases = mkOption {
default = {};
default = { };
example = literalExpression ''
{
ll = "ls -l";
@ -331,7 +345,7 @@ in
};
shellGlobalAliases = mkOption {
default = {};
default = { };
example = literalExpression ''
{
UUID = "$(uuidgen | tr -d \\n)";
@ -346,7 +360,7 @@ in
};
dirHashes = mkOption {
default = {};
default = { };
example = literalExpression ''
{
docs = "$HOME/Documents";
@ -374,7 +388,8 @@ in
completionInit = mkOption {
default = "autoload -U compinit && compinit";
description = "Initialization commands to run when completion is enabled.";
description =
"Initialization commands to run when completion is enabled.";
type = types.lines;
};
@ -387,13 +402,13 @@ in
syntaxHighlighting = mkOption {
type = syntaxHighlightingModule;
default = {};
default = { };
description = "Options related to zsh-syntax-highlighting.";
};
historySubstringSearch = mkOption {
type = historySubstringSearchModule;
default = {};
default = { };
description = "Options related to zsh-history-substring-search.";
};
@ -415,7 +430,8 @@ in
};
strategy = mkOption {
type = types.listOf (types.enum [ "history" "completion" "match_prev_cmd" ]);
type = types.listOf
(types.enum [ "history" "completion" "match_prev_cmd" ]);
default = [ "history" ];
description = ''
`ZSH_AUTOSUGGEST_STRATEGY` is an array that specifies how suggestions should be generated.
@ -436,7 +452,7 @@ in
history = mkOption {
type = historyModule;
default = {};
default = { };
description = "Options related to commands history configuration.";
};
@ -448,7 +464,7 @@ in
};
sessionVariables = mkOption {
default = {};
default = { };
type = types.attrs;
example = { MAILCHECK = 30; };
description = "Environment variables that will be set for zsh session.";
@ -457,7 +473,8 @@ in
initExtraBeforeCompInit = mkOption {
default = "";
type = types.lines;
description = "Extra commands that should be added to {file}`.zshrc` before compinit.";
description =
"Extra commands that should be added to {file}`.zshrc` before compinit.";
};
initExtra = mkOption {
@ -481,7 +498,8 @@ in
profileExtra = mkOption {
default = "";
type = types.lines;
description = "Extra commands that should be added to {file}`.zprofile`.";
description =
"Extra commands that should be added to {file}`.zprofile`.";
};
loginExtra = mkOption {
@ -493,12 +511,13 @@ in
logoutExtra = mkOption {
default = "";
type = types.lines;
description = "Extra commands that should be added to {file}`.zlogout`.";
description =
"Extra commands that should be added to {file}`.zlogout`.";
};
plugins = mkOption {
type = types.listOf pluginModule;
default = [];
default = [ ];
example = literalExpression ''
[
{
@ -528,14 +547,14 @@ in
oh-my-zsh = mkOption {
type = ohMyZshModule;
default = {};
default = { };
description = "Options to configure oh-my-zsh.";
};
localVariables = mkOption {
type = types.attrs;
default = {};
example = { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=["dir" "vcs"]; };
default = { };
example = { POWERLEVEL9K_LEFT_PROMPT_ELEMENTS = [ "dir" "vcs" ]; };
description = ''
Extra local variables defined at the top of {file}`.zshrc`.
'';
@ -609,16 +628,16 @@ in
cfg.initExtraFirst
"typeset -U path cdpath fpath manpath"
(optionalString (cfg.cdpath != []) ''
(optionalString (cfg.cdpath != [ ]) ''
cdpath+=(${concatStringsSep " " cfg.cdpath})
'')
''
for profile in ''${(z)NIX_PROFILES}; do
fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions)
done
for profile in ''${(z)NIX_PROFILES}; do
fpath+=($profile/share/zsh/site-functions $profile/share/zsh/$ZSH_VERSION/functions $profile/share/zsh/vendor-completions)
done
HELPDIR="${cfg.package}/share/zsh/$ZSH_VERSION/help"
HELPDIR="${cfg.package}/share/zsh/$ZSH_VERSION/help"
''
(optionalString (cfg.defaultKeymap != null) ''
@ -635,120 +654,136 @@ in
'') cfg.plugins))
''
# Oh-My-Zsh/Prezto calls compinit during initialization,
# calling it twice causes slight start up slowdown
# as all $fpath entries will be traversed again.
${optionalString (cfg.enableCompletion && !cfg.oh-my-zsh.enable && !cfg.prezto.enable)
cfg.completionInit
}''
# Oh-My-Zsh/Prezto calls compinit during initialization,
# calling it twice causes slight start up slowdown
# as all $fpath entries will be traversed again.
${optionalString
(cfg.enableCompletion && !cfg.oh-my-zsh.enable && !cfg.prezto.enable)
cfg.completionInit}''
(optionalString cfg.autosuggestion.enable ''
source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh
${optionalString (cfg.autosuggestion.strategy != []) ''
ZSH_AUTOSUGGEST_STRATEGY=(${concatStringsSep " " cfg.autosuggestion.strategy})
''
}
'')
(optionalString (cfg.autosuggestion.enable && cfg.autosuggestion.highlight != null) ''
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.autosuggestion.highlight}"
${optionalString (cfg.autosuggestion.strategy != [ ]) ''
ZSH_AUTOSUGGEST_STRATEGY=(${
concatStringsSep " " cfg.autosuggestion.strategy
})
''}
'')
(optionalString
(cfg.autosuggestion.enable && cfg.autosuggestion.highlight != null) ''
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="${cfg.autosuggestion.highlight}"
'')
(optionalString cfg.oh-my-zsh.enable ''
# oh-my-zsh extra settings for plugins
${cfg.oh-my-zsh.extraConfig}
# oh-my-zsh configuration generated by NixOS
${optionalString (cfg.oh-my-zsh.plugins != [])
"plugins=(${concatStringsSep " " cfg.oh-my-zsh.plugins})"
}
${optionalString (cfg.oh-my-zsh.custom != "")
"ZSH_CUSTOM=\"${cfg.oh-my-zsh.custom}\""
}
${optionalString (cfg.oh-my-zsh.theme != "")
"ZSH_THEME=\"${cfg.oh-my-zsh.theme}\""
}
source $ZSH/oh-my-zsh.sh
# oh-my-zsh extra settings for plugins
${cfg.oh-my-zsh.extraConfig}
# oh-my-zsh configuration generated by NixOS
${optionalString (cfg.oh-my-zsh.plugins != [ ])
"plugins=(${concatStringsSep " " cfg.oh-my-zsh.plugins})"}
${optionalString (cfg.oh-my-zsh.custom != "")
''ZSH_CUSTOM="${cfg.oh-my-zsh.custom}"''}
${optionalString (cfg.oh-my-zsh.theme != "")
''ZSH_THEME="${cfg.oh-my-zsh.theme}"''}
source $ZSH/oh-my-zsh.sh
'')
''
${optionalString cfg.prezto.enable
(builtins.readFile "${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zshrc")}
${optionalString cfg.prezto.enable (builtins.readFile
"${pkgs.zsh-prezto}/share/zsh-prezto/runcoms/zshrc")}
${concatStrings (map (plugin: ''
if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then
source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"
fi
'') cfg.plugins)}
${concatStrings (map (plugin: ''
if [[ -f "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}" ]]; then
source "$HOME/${pluginsDir}/${plugin.name}/${plugin.file}"
fi
'') cfg.plugins)}
# History options should be set in .zshrc and after oh-my-zsh sourcing.
# See https://github.com/nix-community/home-manager/issues/177.
HISTSIZE="${toString cfg.history.size}"
SAVEHIST="${toString cfg.history.save}"
${optionalString (cfg.history.ignorePatterns != []) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
${if versionAtLeast config.home.stateVersion "20.03"
then ''HISTFILE="${cfg.history.path}"''
else ''HISTFILE="$HOME/${cfg.history.path}"''}
mkdir -p "$(dirname "$HISTFILE")"
# History options should be set in .zshrc and after oh-my-zsh sourcing.
# See https://github.com/nix-community/home-manager/issues/177.
HISTSIZE="${toString cfg.history.size}"
SAVEHIST="${toString cfg.history.save}"
${optionalString (cfg.history.ignorePatterns != [ ])
"HISTORY_IGNORE=${
lib.escapeShellArg
"(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"
}"}
${if versionAtLeast config.home.stateVersion "20.03" then
''HISTFILE="${cfg.history.path}"''
else
''HISTFILE="$HOME/${cfg.history.path}"''}
mkdir -p "$(dirname "$HISTFILE")"
setopt HIST_FCNTL_LOCK
${if cfg.history.append then "setopt" else "unsetopt"} APPEND_HISTORY
${if cfg.history.ignoreDups then "setopt" else "unsetopt"} HIST_IGNORE_DUPS
${if cfg.history.ignoreAllDups then "setopt" else "unsetopt"} HIST_IGNORE_ALL_DUPS
${if cfg.history.ignoreSpace then "setopt" else "unsetopt"} HIST_IGNORE_SPACE
${if cfg.history.expireDuplicatesFirst then "setopt" else "unsetopt"} HIST_EXPIRE_DUPS_FIRST
${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY
${if cfg.history.extended then "setopt" else "unsetopt"} EXTENDED_HISTORY
${if cfg.autocd != null then "${if cfg.autocd then "setopt" else "unsetopt"} autocd" else ""}
setopt HIST_FCNTL_LOCK
${if cfg.history.append then "setopt" else "unsetopt"} APPEND_HISTORY
${
if cfg.history.ignoreDups then "setopt" else "unsetopt"
} HIST_IGNORE_DUPS
${
if cfg.history.ignoreAllDups then "setopt" else "unsetopt"
} HIST_IGNORE_ALL_DUPS
${
if cfg.history.ignoreSpace then "setopt" else "unsetopt"
} HIST_IGNORE_SPACE
${
if cfg.history.expireDuplicatesFirst then "setopt" else "unsetopt"
} HIST_EXPIRE_DUPS_FIRST
${if cfg.history.share then "setopt" else "unsetopt"} SHARE_HISTORY
${
if cfg.history.extended then "setopt" else "unsetopt"
} EXTENDED_HISTORY
${if cfg.autocd != null then
"${if cfg.autocd then "setopt" else "unsetopt"} autocd"
else
""}
${cfg.initExtra}
${cfg.initExtra}
# Aliases
${aliasesStr}
# Aliases
${aliasesStr}
''
]
++ (mapAttrsToList (k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}") cfg.shellGlobalAliases)
++ [ (''
# Named Directory Hashes
${dirHashesStr}
'')
] ++ (mapAttrsToList
(k: v: "alias -g -- ${lib.escapeShellArg k}=${lib.escapeShellArg v}")
cfg.shellGlobalAliases) ++ [
(''
# Named Directory Hashes
${dirHashesStr}
'')
(optionalString cfg.syntaxHighlighting.enable
# Load zsh-syntax-highlighting after all custom widgets have been created
# https://github.com/zsh-users/zsh-syntax-highlighting#faq
''
source ${cfg.syntaxHighlighting.package}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(${lib.concatStringsSep " " (map lib.escapeShellArg cfg.syntaxHighlighting.highlighters)})
${lib.concatStringsSep "\n" (
lib.mapAttrsToList
(name: value: "ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})")
cfg.syntaxHighlighting.styles
)}
${lib.concatStringsSep "\n" (
lib.mapAttrsToList
(name: value: "ZSH_HIGHLIGHT_PATTERNS+=(${lib.escapeShellArg name} ${lib.escapeShellArg value})")
cfg.syntaxHighlighting.patterns
)}
'')
(optionalString cfg.syntaxHighlighting.enable
# Load zsh-syntax-highlighting after all custom widgets have been created
# https://github.com/zsh-users/zsh-syntax-highlighting#faq
''
source ${cfg.syntaxHighlighting.package}/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(${
lib.concatStringsSep " "
(map lib.escapeShellArg cfg.syntaxHighlighting.highlighters)
})
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
"ZSH_HIGHLIGHT_STYLES+=(${lib.escapeShellArg name} ${
lib.escapeShellArg value
})") cfg.syntaxHighlighting.styles)}
${lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value:
"ZSH_HIGHLIGHT_PATTERNS+=(${lib.escapeShellArg name} ${
lib.escapeShellArg value
})") cfg.syntaxHighlighting.patterns)}
'')
(optionalString (cfg.historySubstringSearch.enable or false)
(optionalString (cfg.historySubstringSearch.enable or false)
# Load zsh-history-substring-search after zsh-syntax-highlighting
# https://github.com/zsh-users/zsh-history-substring-search#usage
''
source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
${lib.concatMapStringsSep "\n"
(upKey: "bindkey \"${upKey}\" history-substring-search-up")
(lib.toList cfg.historySubstringSearch.searchUpKey)
}
${lib.concatMapStringsSep "\n"
(downKey: "bindkey \"${downKey}\" history-substring-search-down")
(lib.toList cfg.historySubstringSearch.searchDownKey)
}
'')
''
source ${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh
${lib.concatMapStringsSep "\n"
(upKey: ''bindkey "${upKey}" history-substring-search-up'')
(lib.toList cfg.historySubstringSearch.searchUpKey)}
${lib.concatMapStringsSep "\n"
(downKey: ''bindkey "${downKey}" history-substring-search-down'')
(lib.toList cfg.historySubstringSearch.searchDownKey)}
'')
(optionalString cfg.zprof.enable
''
zprof
'')
]);
(optionalString cfg.zprof.enable ''
zprof
'')
]);
}
(mkIf cfg.oh-my-zsh.enable {
@ -757,15 +792,14 @@ in
home.file."${config.xdg.cacheHome}/oh-my-zsh/.keep".text = "";
})
(mkIf (cfg.plugins != []) {
(mkIf (cfg.plugins != [ ]) {
# Many plugins require compinit to be called
# but allow the user to opt out.
programs.zsh.enableCompletion = mkDefault true;
home.file =
foldl' (a: b: a // b) {}
home.file = foldl' (a: b: a // b) { }
(map (plugin: { "${pluginsDir}/${plugin.name}".source = plugin.src; })
cfg.plugins);
cfg.plugins);
})
]);
}