From 213f12982d7562e0e73f7bbbb80328dfde2bc50e Mon Sep 17 00:00:00 2001 From: d-r-a-b <107967151+d-r-a-b@users.noreply.github.com> Date: Tue, 19 May 2026 10:46:41 -0400 Subject: [PATCH] nixos/command-not-found: set `enable` default with module system --- .../command-not-found/command-not-found.nix | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/nixos/modules/programs/command-not-found/command-not-found.nix b/nixos/modules/programs/command-not-found/command-not-found.nix index 366879d4088f..120feacc61b9 100644 --- a/nixos/modules/programs/command-not-found/command-not-found.nix +++ b/nixos/modules/programs/command-not-found/command-not-found.nix @@ -33,7 +33,10 @@ in enable = lib.mkOption { type = lib.types.bool; - default = false; + default = builtins.pathExists config.programs.command-not-found.dbPath; + defaultText = lib.literalExpression '' + builtins.pathExists config.programs.command-not-found.dbPath + ''; description = '' Whether interactive shells should show which Nix package (if any) provides a missing command. @@ -62,34 +65,26 @@ in }; }; - config = lib.mkMerge [ - { - programs.command-not-found = { - enable = lib.mkDefault (builtins.pathExists cfg.dbPath); - }; - } + config = lib.mkIf cfg.enable { + programs.bash.interactiveShellInit = '' + command_not_found_handle() { + '${commandNotFound}/bin/command-not-found' "$@" + } + ''; - (lib.mkIf cfg.enable { - programs.bash.interactiveShellInit = '' - command_not_found_handle() { - '${commandNotFound}/bin/command-not-found' "$@" - } - ''; + programs.zsh.interactiveShellInit = '' + command_not_found_handler() { + '${commandNotFound}/bin/command-not-found' "$@" + } + ''; - programs.zsh.interactiveShellInit = '' - command_not_found_handler() { - '${commandNotFound}/bin/command-not-found' "$@" - } - ''; + # NOTE: Fish by itself checks for nixos command-not-found, let's instead makes it explicit. + programs.fish.interactiveShellInit = '' + function fish_command_not_found + "${commandNotFound}/bin/command-not-found" $argv + end + ''; - # NOTE: Fish by itself checks for nixos command-not-found, let's instead makes it explicit. - programs.fish.interactiveShellInit = '' - function fish_command_not_found - "${commandNotFound}/bin/command-not-found" $argv - end - ''; - - environment.systemPackages = [ commandNotFound ]; - }) - ]; + environment.systemPackages = [ commandNotFound ]; + }; }