Skip to content

Commit

Permalink
modules/home-manager: patch nix-index to remove FHS outputs
Browse files Browse the repository at this point in the history
This is part of a PR over at https://github . com/nix-community/nix-index/pull/243 which makes `--top-level` a default argument. This in turn removes FHS entries by default from being matched when using `nix-locate`. This was always a pain point for me so I am glad someone knew how to fix it. Unfortunately since that PR seems a bit stalled I've in turn needed to patch directly. I've poked upstream to help move that PR along, and once it does merge I'll drop this patch.
  • Loading branch information
Frontear committed Nov 15, 2024
1 parent 8d77c1e commit 5d18690
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
17 changes: 11 additions & 6 deletions modules/home-manager/programs/nix-index/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ in {
options.my.programs.nix-index = {
enable = lib.mkDefaultEnableOption "nix-index";
package = lib.mkOption {
default = pkgs.nix-index;
defaultText = "pkgs.nix-index";
description = ''
The nix-index package to use.
'';
default = pkgs.nix-index.override (prev: {
nix-index-unwrapped = prev.nix-index-unwrapped.overrideAttrs (prevAttrs: {
patches = (prevAttrs.patches or []) ++ [
# https://github.com/nix-community/nix-index/pull/243
./skip-fhs-by-default.patch
];
});
});

type = with lib.types; package;
};
Expand All @@ -24,6 +27,8 @@ in {
my.persist.directories = [ "~/.cache/nix-index" ];

programs.command-not-found.enable = lib.mkForce false;
programs.nix-index.enable = true;
programs.nix-index = {
inherit (cfg) enable package;
};
};
}
51 changes: 51 additions & 0 deletions modules/home-manager/programs/nix-index/skip-fhs-by-default.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c09c04..25f62e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@
### Fixed
### Changed

+* `--top-level` is now the default. To use the old default, add `--all`.
+
## 0.1.8
### Added

diff --git a/command-not-found.sh b/command-not-found.sh
index 5f30bad..64457ef 100755
--- a/command-not-found.sh
+++ b/command-not-found.sh
@@ -16,7 +16,7 @@ command_not_found_handle () {

toplevel=nixpkgs # nixpkgs should always be available even in NixOS
cmd=$1
- attrs=$(@out@/bin/nix-locate --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$cmd")
+ attrs=$(@out@/bin/nix-locate --minimal --no-group --type x --type s --whole-name --at-root "/bin/$cmd")
len=$(echo -n "$attrs" | grep -c "^")

case $len in
diff --git a/src/bin/nix-locate.rs b/src/bin/nix-locate.rs
index 760d398..2c18747 100644
--- a/src/bin/nix-locate.rs
+++ b/src/bin/nix-locate.rs
@@ -187,7 +187,7 @@ fn process_args(matches: Opts) -> result::Result<Args, clap::Error> {
file_type: matches
.r#type
.unwrap_or_else(|| files::ALL_FILE_TYPES.to_vec()),
- only_toplevel: matches.top_level,
+ only_toplevel: !matches.all,
color,
minimal: matches.minimal,
};
@@ -255,9 +255,9 @@ struct Opts {
#[clap(long, name = "HASH")]
hash: Option<String>,

- /// Only print matches from packages that show up in `nix-env -qa`.
+ /// Print all matches, not only print from packages that show up in `nix-env -qa`.
#[clap(long)]
- top_level: bool,
+ all: bool,

/// Only print matches for files that have this type. If the option is given multiple times,
/// a file will be printed if it has any of the given types.

0 comments on commit 5d18690

Please sign in to comment.