From f99d745319e6a3fc840d5785f7afb1fc9774df3d Mon Sep 17 00:00:00 2001 From: d-r-a-b <107967151+d-r-a-b@users.noreply.github.com> Date: Wed, 6 May 2026 10:36:41 -0400 Subject: [PATCH 1/3] nixos/command-not-found: don't require lib.mkForce to set dbPath --- nixos/modules/programs/command-not-found/command-not-found.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e6ea41778172..03117e573cf1 100644 --- a/nixos/modules/programs/command-not-found/command-not-found.nix +++ b/nixos/modules/programs/command-not-found/command-not-found.nix @@ -62,7 +62,7 @@ in { programs.command-not-found = { enable = lib.mkDefault (builtins.pathExists cfg.dbPath); - dbPath = pkgs.path + "/programs.sqlite"; + dbPath = lib.mkDefault (pkgs.path + "/programs.sqlite"); }; } From 626fddace8895a528d5354fb6f35b7753603292e 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:39:42 -0400 Subject: [PATCH 2/3] nixos/command-not-found: set `dbPath` default with module system options --- .../programs/command-not-found/command-not-found.nix | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 03117e573cf1..366879d4088f 100644 --- a/nixos/modules/programs/command-not-found/command-not-found.nix +++ b/nixos/modules/programs/command-not-found/command-not-found.nix @@ -45,6 +45,11 @@ in }; dbPath = lib.mkOption { + type = lib.types.path; + default = pkgs.path + "/programs.sqlite"; + defaultText = lib.literalExpression '' + pkgs.path + "/programs.sqlite" + ''; description = '' Absolute path to `programs.sqlite`, which contains mappings from binary names to package names. @@ -54,7 +59,6 @@ in `/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite`. If you do so, you can update it with `sudo nix-channels --update`. ''; - type = lib.types.path; }; }; @@ -62,7 +66,6 @@ in { programs.command-not-found = { enable = lib.mkDefault (builtins.pathExists cfg.dbPath); - dbPath = lib.mkDefault (pkgs.path + "/programs.sqlite"); }; } 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 3/3] 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 ]; + }; }