diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index b4431aba8797..38700fa387b4 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -72,6 +72,11 @@ in ''; }; + generateCompletions = lib.mkEnableOption "generating completion files from man pages" // { + default = true; + example = false; + }; + vendor.config.enable = lib.mkOption { type = lib.types.bool; default = true; @@ -247,7 +252,7 @@ in ''; } - { + (lib.mkIf cfg.generateCompletions { etc."fish/generated_completions".source = let patchedGenerator = pkgs.stdenv.mkDerivation { @@ -297,7 +302,7 @@ in ignoreCollisions = true; paths = builtins.map generateCompletions config.environment.systemPackages; }; - } + }) # include programs that bring their own completions { @@ -318,20 +323,23 @@ in } ]; - programs.fish.interactiveShellInit = '' - # add completions generated by NixOS to $fish_complete_path - begin - # joins with null byte to accommodate all characters in paths, then respectively gets all paths before (exclusive) / after (inclusive) the first one including "generated_completions", - # splits by null byte, and then removes all empty lines produced by using 'string' - set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".") - set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".") - set fish_complete_path $prev "/etc/fish/generated_completions" $post - end - # prevent fish from generating completions on first run - if not test -d $__fish_user_data_dir/generated_completions - ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions - end - ''; + programs.fish.interactiveShellInit = + lib.optionalString cfg.generateCompletions '' + # add completions generated by NixOS to $fish_complete_path + begin + # joins with null byte to accommodate all characters in paths, then respectively gets all paths before (exclusive) / after (inclusive) the first one including "generated_completions", + # splits by null byte, and then removes all empty lines produced by using 'string' + set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".") + set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".") + set fish_complete_path $prev "/etc/fish/generated_completions" $post + end + '' + + '' + # prevent fish from generating completions on first run + if not test -d $__fish_user_data_dir/generated_completions + ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions + end + ''; }; meta.maintainers = with lib.maintainers; [ sigmasquadron ];