nixos/fish: allow disabling completion generation (#418328)

authored by Aleksana and committed by GitHub 662f1d70 b18bbc99

+25 -16
+1
nixos/modules/profiles/minimal.nix
··· 27 27 # The lessopen package pulls in Perl. 28 28 less.lessopen = mkDefault null; 29 29 command-not-found.enable = mkDefault false; 30 + fish.generateCompletions = mkDefault false; 30 31 }; 31 32 32 33 # This pulls in nixos-containers which depends on Perl.
+24 -16
nixos/modules/programs/fish.nix
··· 72 72 ''; 73 73 }; 74 74 75 + generateCompletions = lib.mkEnableOption "generating completion files from man pages" // { 76 + default = true; 77 + example = false; 78 + }; 79 + 75 80 vendor.config.enable = lib.mkOption { 76 81 type = lib.types.bool; 77 82 default = true; ··· 247 252 ''; 248 253 } 249 254 250 - { 255 + (lib.mkIf cfg.generateCompletions { 251 256 etc."fish/generated_completions".source = 252 257 let 253 258 patchedGenerator = pkgs.stdenv.mkDerivation { ··· 297 302 ignoreCollisions = true; 298 303 paths = builtins.map generateCompletions config.environment.systemPackages; 299 304 }; 300 - } 305 + }) 301 306 302 307 # include programs that bring their own completions 303 308 { ··· 318 323 } 319 324 ]; 320 325 321 - programs.fish.interactiveShellInit = '' 322 - # add completions generated by NixOS to $fish_complete_path 323 - begin 324 - # 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", 325 - # splits by null byte, and then removes all empty lines produced by using 'string' 326 - set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".") 327 - set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".") 328 - set fish_complete_path $prev "/etc/fish/generated_completions" $post 329 - end 330 - # prevent fish from generating completions on first run 331 - if not test -d $__fish_user_data_dir/generated_completions 332 - ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions 333 - end 334 - ''; 326 + programs.fish.interactiveShellInit = 327 + lib.optionalString cfg.generateCompletions '' 328 + # add completions generated by NixOS to $fish_complete_path 329 + begin 330 + # 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", 331 + # splits by null byte, and then removes all empty lines produced by using 'string' 332 + set -l prev (string join0 $fish_complete_path | string match --regex "^.*?(?=\x00[^\x00]*generated_completions.*)" | string split0 | string match -er ".") 333 + set -l post (string join0 $fish_complete_path | string match --regex "[^\x00]*generated_completions.*" | string split0 | string match -er ".") 334 + set fish_complete_path $prev "/etc/fish/generated_completions" $post 335 + end 336 + '' 337 + + '' 338 + # prevent fish from generating completions on first run 339 + if not test -d $__fish_user_data_dir/generated_completions 340 + ${pkgs.coreutils}/bin/mkdir $__fish_user_data_dir/generated_completions 341 + end 342 + ''; 335 343 336 344 }; 337 345 meta.maintainers = with lib.maintainers; [ sigmasquadron ];