diff --git a/doc/release-notes/rl-2605.section.md b/doc/release-notes/rl-2605.section.md index 74248d2317f6..f5c88d1eb7b5 100644 --- a/doc/release-notes/rl-2605.section.md +++ b/doc/release-notes/rl-2605.section.md @@ -109,6 +109,8 @@ - `nodePackages.browserify` has been removed, as it was unmaintained within nixpkgs. +- `command-not-found` package will be enabled by default if the source of nixpkgs contains the file `programs.sqlite`. This is the case if a nixpkgs tarball from https://channels.nixos.org is used. This usage will also make the database of `command-no-found` stateless. + - `nodePackages.sass` has been removed, as it was unmaintained within nixpkgs. - All `@tailwindcss` packages in the `nodePackages` set have been removed, as they are libraries that should instead be locked by JS projects that utilize them. 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 d1e8f91a525b..51ec0922c4f7 100644 --- a/nixos/modules/programs/command-not-found/command-not-found.nix +++ b/nixos/modules/programs/command-not-found/command-not-found.nix @@ -38,8 +38,6 @@ in Whether interactive shells should show which Nix package (if any) provides a missing command. - Requires nix-channels to be set and downloaded (sudo nix-channel --update.) - See also nix-index and nix-index-database as an alternative for flakes-based systems. Additionally, having the env var NIX_AUTO_RUN set will automatically run the matching package, and with NIX_AUTO_RUN_INTERACTIVE it will confirm the package before running. @@ -47,38 +45,48 @@ in }; dbPath = lib.mkOption { - default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite"; description = '' - Absolute path to programs.sqlite. + Absolute path to `programs.sqlite`, which contains mappings from binary names to package names. - By default this file will be provided by your channel - (nixexprs.tar.xz). + If a nixpkgs tarball from https://channels.nixos.org is used as the source of nixpkgs, this file will be provided and this option be set by default. + + To use the stateful `programs.sqlite` database, set this option to + `/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; }; }; - config = lib.mkIf cfg.enable { - programs.bash.interactiveShellInit = '' - command_not_found_handle() { - '${commandNotFound}/bin/command-not-found' "$@" - } - ''; + config = lib.mkMerge [ + { + programs.command-not-found = { + enable = lib.mkOptionDefault (builtins.pathExists cfg.dbPath); + dbPath = pkgs.path + "/programs.sqlite"; + }; + } - programs.zsh.interactiveShellInit = '' - command_not_found_handler() { - '${commandNotFound}/bin/command-not-found' "$@" - } - ''; + (lib.mkIf cfg.enable { + programs.bash.interactiveShellInit = '' + command_not_found_handle() { + '${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 - ''; + programs.zsh.interactiveShellInit = '' + command_not_found_handler() { + '${commandNotFound}/bin/command-not-found' "$@" + } + ''; - environment.systemPackages = [ commandNotFound ]; - }; + # 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 ]; + }) + ]; }