From c9fd4820d5e33422d2a9311898e098ba492dbd34 Mon Sep 17 00:00:00 2001 From: isabel Date: Mon, 30 Sep 2024 16:30:50 +0100 Subject: [PATCH] programs/bash: move to completion.* a port of https://github.com/NixOS/nixpkgs/pull/291552 for darwin --- modules/examples/hydra.nix | 2 +- modules/examples/lnl.nix | 2 +- modules/nix/default.nix | 2 +- modules/programs/bash/default.nix | 30 +++++++++++++++++++----------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/modules/examples/hydra.nix b/modules/examples/hydra.nix index 15808d92..31604985 100644 --- a/modules/examples/hydra.nix +++ b/modules/examples/hydra.nix @@ -12,7 +12,7 @@ in { # Create /etc/bashrc that loads the nix-darwin environment. programs.bash.enable = true; - programs.bash.enableCompletion = false; + programs.bash.completion.enable = false; # Recreate /run/current-system symlink after boot. services.activate-system.enable = true; diff --git a/modules/examples/lnl.nix b/modules/examples/lnl.nix index 96954d22..010dff5a 100644 --- a/modules/examples/lnl.nix +++ b/modules/examples/lnl.nix @@ -199,7 +199,7 @@ # Dotfiles. # programs.vim.package = mkForce pkgs.lnl.vim; - programs.bash.enableCompletion = true; + programs.bash.completion.enable = true; programs.zsh.enable = true; programs.zsh.enableBashCompletion = true; diff --git a/modules/nix/default.nix b/modules/nix/default.nix index b91521a7..6bce1e35 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -686,7 +686,7 @@ in nixPackage pkgs.nix-info ] - ++ optional (config.programs.bash.enableCompletion) pkgs.nix-bash-completions; + ++ optional (config.programs.bash.completion.enable) pkgs.nix-bash-completions; environment.etc."nix/nix.conf".source = nixConf; diff --git a/modules/programs/bash/default.nix b/modules/programs/bash/default.nix index 3abb3e84..2518c9c5 100644 --- a/modules/programs/bash/default.nix +++ b/modules/programs/bash/default.nix @@ -7,6 +7,10 @@ let in { + imports = [ + (mkRenamedOptionModule [ "programs" "bash" "enableCompletion" ] [ "programs" "bash" "completion" "enable" ]) + ]; + options = { programs.bash.enable = mkOption { @@ -21,14 +25,18 @@ in type = types.lines; }; - programs.bash.enableCompletion = mkOption { - type = types.bool; - default = false; - description = '' - Enable bash completion for all interactive bash shells. + programs.bash.completion = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Enable bash completion for all interactive bash shells. - NOTE. This doesn't work with bash 3.2, which is the default on macOS. - ''; + NOTE: This doesn't work with bash 3.2, which is installed by default on macOS by Apple. + ''; + }; + + package = mkPackageOption pkgs "bash-completion" { }; }; }; @@ -38,9 +46,9 @@ in environment.systemPackages = [ # Include bash package pkgs.bashInteractive - ] ++ optional cfg.enableCompletion pkgs.bash-completion; + ] ++ optional cfg.completion.enable cfg.completion.package; - environment.pathsToLink = + environment.pathsToLink = optionals cfg.completion.enable [ "/etc/bash_completion.d" "/share/bash-completion/completions" ]; @@ -70,9 +78,9 @@ in ${config.environment.interactiveShellInit} ${cfg.interactiveShellInit} - ${optionalString cfg.enableCompletion '' + ${optionalString cfg.completion.enable '' if [ "$TERM" != "dumb" ]; then - source "${pkgs.bash-completion}/etc/profile.d/bash_completion.sh" + source "${cfg.completion.package}/etc/profile.d/bash_completion.sh" nullglobStatus=$(shopt -p nullglob) shopt -s nullglob