- 
          
- 
        Couldn't load subscription status. 
- Fork 46
treewide: disable programs.nix-index.enable option by default #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treewide: disable programs.nix-index.enable option by default #132
Conversation
| Should we maybe start by printing a warning if the option is set to true by this module, to give people the chance to update their configs? | 
| 
 What about doing the opposite? If  | 
| 
 But that warning would be hard to avoid in case you actually conditionally enable the module. I think it should be possible to not have any warnings to avoid warning fatigue. | 
Fixes: 5f154bf ("nixos-module: disable programs.command-not-found by default") Link: nix-community#132
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    4b18f07    to
    fd1dc42      
    Compare
  
    | 
 This should be resolved by commit  For reference, I am using this PR as follows: commit ebbf6a3cb5255e8717ee00650e382de7971765e1
Author: NAHO <90870942+trueNAHO@users.noreply.github.com>
Date:   2024-12-12 15:40:47 +0100
    nix-index: init
    
    Initialize the nix-index module with pre-generated databases and comma
    [1] support by leveraging the nix-index-database [3] wrapper of
    nix-index [2].
    
    This changes the behaviour of the fish_command_not_found function.
    
    [1]: https://github.com/nix-community/comma
    [2]: https://github.com/nix-community/nix-index
    [3]: https://github.com/nix-community/nix-index-database
diff --git a/flake.lock b/flake.lock
index 9df4f840..41d49c60 100644
--- a/flake.lock
+++ b/flake.lock
@@ -355,6 +355,27 @@
         "type": "github"
       }
     },
+    "nix-index-database_2": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ]
+      },
+      "locked": {
+        "lastModified": 1734097052,
+        "narHash": "sha256-FKXpL6/RWwKo3B5AxqUeYOddxXuvuzMAAP6ffg253no=",
+        "owner": "trueNAHO",
+        "repo": "nix-index-database",
+        "rev": "fd1dc4242b789bd6e22309c73a97c4119819eae7",
+        "type": "github"
+      },
+      "original": {
+        "owner": "trueNAHO",
+        "ref": "treewide-disable-programs-nix-index-enable-option-by-default",
+        "repo": "nix-index-database",
+        "type": "github"
+      }
+    },
     "nixpkgs": {
       "locked": {
         "lastModified": 1733392399,
@@ -470,6 +491,7 @@
         "home-manager": "home-manager",
         "logo": "logo",
         "nix-alien": "nix-alien",
+        "nix-index-database": "nix-index-database_2",
         "nixpkgs": "nixpkgs_3",
         "nixvim": "nixvim",
         "os": "os",
diff --git a/flake.nix b/flake.nix
index 9c751904..969d25d0 100644
--- a/flake.nix
+++ b/flake.nix
@@ -84,6 +84,14 @@
       url = "github:thiagokokada/nix-alien";
     };
 
+    # TODO: Replace this fork with upstream once [1] is merged.
+    #
+    # [1]: https://github.com/nix-community/nix-index-database/pull/132
+    nix-index-database = {
+      inputs.nixpkgs.follows = "nixpkgs";
+      url = "github:trueNAHO/nix-index-database/treewide-disable-programs-nix-index-enable-option-by-default";
+    };
+
     nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
 
     nixvim = {
diff --git a/home_configurations/private/full/default.nix b/home_configurations/private/full/default.nix
index 12c27f01..9b799cda 100644
--- a/home_configurations/private/full/default.nix
+++ b/home_configurations/private/full/default.nix
@@ -192,6 +192,7 @@ lib.dotfiles.homeManagerConfiguration.homeManagerConfiguration
             full = true;
           };
 
+          nix-index.enable = true;
           nix-your-shell.enable = true;
           password-store.enable = true;
           qutebrowser.enable = true;
diff --git a/home_configurations/private/full/imports.nix b/home_configurations/private/full/imports.nix
index 9ac923bd..2e34e554 100644
--- a/home_configurations/private/full/imports.nix
+++ b/home_configurations/private/full/imports.nix
@@ -159,6 +159,7 @@
     ../../../modules/inputs/home-manager/programs/lazygit
     ../../../modules/inputs/home-manager/programs/man
     ../../../modules/inputs/home-manager/programs/mpv
+    ../../../modules/inputs/home-manager/programs/nix-index
     ../../../modules/inputs/home-manager/programs/nix-your-shell
     ../../../modules/inputs/home-manager/programs/password-store
     ../../../modules/inputs/home-manager/programs/qutebrowser
diff --git a/modules/inputs/home-manager/programs/fish/default.nix b/modules/inputs/home-manager/programs/fish/default.nix
index da99254f..aebe8df3 100644
--- a/modules/inputs/home-manager/programs/fish/default.nix
+++ b/modules/inputs/home-manager/programs/fish/default.nix
@@ -90,15 +90,6 @@
                 description = "Output parent directory multiple times";
               };
 
-              fish_command_not_found = {
-                body =
-                  validateFunctionArguments
-                  "fish_command_not_found"
-                  "nix run nixpkgs#$argv[1] -- $argv[2..]";
-
-                description = "What to do when a command wasn't found";
-              };
-
               fish_mode_prompt = fishModePrompt "";
 
               fish_greeting = {
diff --git a/modules/inputs/home-manager/programs/nix-index/default.nix b/modules/inputs/home-manager/programs/nix-index/default.nix
new file mode 100644
index 00000000..da9f05f3
--- /dev/null
+++ b/modules/inputs/home-manager/programs/nix-index/default.nix
@@ -0,0 +1,28 @@
+{
+  config,
+  inputs,
+  lib,
+  ...
+}: {
+  imports = [inputs.nix-index-database.hmModules.nix-index];
+
+  options.dotfiles.inputs.home-manager.programs.nix-index.enable =
+    lib.dotfiles.mkEnableOption;
+
+  config = lib.mkMerge [
+    {
+      programs.nix-index.acknowledgeBreakingChange = true;
+    }
+
+    (
+      lib.mkIf
+      config.dotfiles.inputs.home-manager.programs.nix-index.enable
+      {
+        programs = {
+          nix-index-database.comma.enable = true;
+          nix-index.enable = true;
+        };
+      }
+    )
+  ];
+} | 
fd1dc42    to
    928ab2e      
    Compare
  
    | Changelogv2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
| @r-vdp can you have a look again? | 
| I'll try to have a look at it tomorrow. I would prefer to move the second commit to another PR, because it's not related to the functional change here and I don't feel like arguing about stylistic changes. I don't love the idea of the extra option to acknowledge the change, I'd like to avoid it if possible, but if there's no better way, then we leave it. | 
| 
 The commits are included in this patchset to avoid merge conflicts with the commits, while the commit is included in this patchset for simplicity reasons. 
 The following end-user module triggers the warning when  {
  config,
  inputs,
  lib,
  ...
}: {
  imports = [inputs.nix-index-database.hmModules.nix-index];
  options.nix-index.enable = lib.mkEnableOption "nix-index";
  config = lib.mkIf config.nix-index.enable {
    programs = {
      nix-index-database.comma.enable = true;
      nix-index.enable = true;
    };
  };
}In that case, end-users have to use the following potentially undesired workaround: 11,15c11,13
<   config = lib.mkIf config.nix-index.enable {
<     programs = {
<       nix-index-database.comma.enable = true;
<       nix-index.enable = true;
<     };
---
>   config.programs = {
>     nix-index-database.comma.enable = config.nix-index.enable;
>     nix-index.enable = config.nix-index.enable;If we provide an explicit breaking change option, end-users get a proper warning once this option is deprecated: {
  config,
  inputs,
  lib,
  ...
}: {
  imports = [inputs.nix-index-database.hmModules.nix-index];
  options.nix-index.enable = lib.mkEnableOption "nix-index";
  config = lib.mkMerge [
    {
      # This will trigger a proper warning once this upstream option is
      # deprecated with lib.mkRemovedOptionModule.
      programs.nix-index.acknowledgeBreakingChange = true;
    }
    (
      lib.mkIf config.nix-index.enable {
        programs = {
          nix-index-database.comma.enable = true;
          nix-index.enable = true;
        };
      }
    )
  ];
}Otherwise, end-users have to use the workaround and will never be notified when the workaround is no longer necessary. | 
Fixes: 5f154bf ("nixos-module: disable programs.command-not-found by default") Link: nix-community#132
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    928ab2e    to
    8f6bf3e      
    Compare
  
    | Changelogv3: 8f6bf3e
 v2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
| Friendly ping: @r-vdp | 
Fixes: 5f154bf ("nixos-module: disable programs.command-not-found by default") Link: nix-community#132
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    Fixes: 5f154bf ("nixos-module: disable programs.command-not-found by default") Link: nix-community#132
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    e35a2c2    to
    33b2e62      
    Compare
  
    | Changelogv5: 33b2e62
 v4: e35a2c2
 v3: 8f6bf3e
 v2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
33b2e62    to
    2072ea4      
    Compare
  
    Fixes: 5f154bf ("nixos-module: disable programs.command-not-found by default") Link: nix-community#132
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    | Changelogv6: 2072ea4
 v5: 33b2e62
 v4: e35a2c2
 v3: 8f6bf3e
 v2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
| I agree with the idea behind this PR, but I don't necessarily agree with all of the other changes that you made that have nothing to do with this enable option. I gave you the same feedback before. So, as before, I'd suggest that you remove those changes from this PR. | 
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    2072ea4    to
    786aecf      
    Compare
  
    | Changelogv8: 395c618
 v7: 786aecf
 v6: 2072ea4
 v5: 33b2e62
 v4: e35a2c2
 v3: 8f6bf3e
 v2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
| 
 Yes. My bad for not entirely understanding that part at first. I moved all commits except for "treewide: disable programs.nix-index.enable option by default" and "shared: add programs.nix-index.acknowledgeBreakingChange option" into seperate PRs in v7. | 
Disable the programs.nix-index.enable option by default to align with
Nix conventions and streamline configuration sharing.
This avoids needing to remember to disable this module across all
configurations and avoids highly discouraged conditional imports that
often lead to infinite recursions [1].
BREAKING CHANGE: The programs.nix-index.enable option is disabled by
default, meaning that this module has no effect unless the following is
declared:
    programs.nix-index.enable = true;
[1]: https://discourse.nixos.org/t/conditional-module-imports/34863/2
Link: nix-community#132
    786aecf    to
    395c618      
    Compare
  
            
          
                nix/shared.nix
              
                Outdated
          
        
      | nix-index-database.comma.enable = lib.mkEnableOption "wrapping comma with nix-index-database and put it in the PATH"; | ||
|  | ||
| # TODO: Remove this option after the release of nixos-25.11. | ||
| nix-index.acknowledgeBreakingChange = lib.mkOption { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not providing a default at all is indeed better, it will print a clear error that most nix users will easily understand.
Including this option is also a future maintenance issue, we need to decide when to remove it (which will be again a breaking change for people who decided to set it), and it also doesn't make it clear which breaking change you're acknowledging, in case we introduce a new one before we remove this option.
So, I'd remove this option and just not provide a default for the enable option for now.
395c618    to
    fcd8050      
    Compare
  
    | Changelogv9: fcd8050
 v8: 395c618
 v7: 786aecf
 v6: 2072ea4
 v5: 33b2e62
 v4: e35a2c2
 v3: 8f6bf3e
 v2: 928ab2e
 v1: fd1dc42
 v0: 4b18f07 | 
| Thanks! | 
This patchset does some cleanup and disables the
programs.nix-index.enableoption by default for the following reason:The
programs.nix-index.enableoption was first introduced in commit 75e347f ("Allow command-not-found integration with home-manager.") and set totrue:nix-index-database/home-manager-module.nix
Line 6 in 75e347f
To this day,
programs.nix-index.enableis still set totrue:nix-index-database/nix/shared.nix
Line 6 in f1e477a