···27 # The lessopen package pulls in Perl.
28 less.lessopen = mkDefault null;
29 command-not-found.enable = mkDefault false;
030 };
3132 # This pulls in nixos-containers which depends on Perl.
···27 # The lessopen package pulls in Perl.
28 less.lessopen = mkDefault null;
29 command-not-found.enable = mkDefault false;
30+ fish.generateCompletions = mkDefault false;
31 };
3233 # This pulls in nixos-containers which depends on Perl.
+24-16
nixos/modules/programs/fish.nix
···72 '';
73 };
740000075 vendor.config.enable = lib.mkOption {
76 type = lib.types.bool;
77 default = true;
···247 '';
248 }
249250- {
251 etc."fish/generated_completions".source =
252 let
253 patchedGenerator = pkgs.stdenv.mkDerivation {
···297 ignoreCollisions = true;
298 paths = builtins.map generateCompletions config.environment.systemPackages;
299 };
300- }
301302 # include programs that bring their own completions
303 {
···318 }
319 ];
320321- 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- '';
000335336 };
337 meta.maintainers = with lib.maintainers; [ sigmasquadron ];
···72 '';
73 };
7475+ generateCompletions = lib.mkEnableOption "generating completion files from man pages" // {
76+ default = true;
77+ example = false;
78+ };
79+80 vendor.config.enable = lib.mkOption {
81 type = lib.types.bool;
82 default = true;
···252 '';
253 }
254255+ (lib.mkIf cfg.generateCompletions {
256 etc."fish/generated_completions".source =
257 let
258 patchedGenerator = pkgs.stdenv.mkDerivation {
···302 ignoreCollisions = true;
303 paths = builtins.map generateCompletions config.environment.systemPackages;
304 };
305+ })
306307 # include programs that bring their own completions
308 {
···323 }
324 ];
325326+ 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+ '';
343344 };
345 meta.maintainers = with lib.maintainers; [ sigmasquadron ];